From a6e319ceda80e709a13f6abf429d4d85062986b4 Mon Sep 17 00:00:00 2001 From: Giulio rebuffo Date: Fri, 4 Oct 2024 23:29:09 +0200 Subject: [PATCH] Caplin: Add flag to listen to entire network traffic (#12226) --- cl/clparams/config.go | 1 + cl/sentinel/config.go | 5 +++-- cl/sentinel/service/start.go | 7 +++++-- cmd/caplin/caplin1/run.go | 17 +++++++++-------- cmd/utils/flags.go | 7 +++++++ turbo/cli/default_flags.go | 1 + 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/cl/clparams/config.go b/cl/clparams/config.go index 2466bc0919c..8b6625a8a96 100644 --- a/cl/clparams/config.go +++ b/cl/clparams/config.go @@ -64,6 +64,7 @@ type CaplinConfig struct { CaplinDiscoveryTCPPort uint64 SentinelAddr string SentinelPort uint64 + SubscribeAllTopics bool // Erigon Sync LoopBlockLimit uint64 // Beacon API router configuration diff --git a/cl/sentinel/config.go b/cl/sentinel/config.go index 728e7a1eb94..0728f31ae55 100644 --- a/cl/sentinel/config.go +++ b/cl/sentinel/config.go @@ -48,8 +48,9 @@ type SentinelConfig struct { TmpDir string LocalDiscovery bool - EnableBlocks bool - ActiveIndicies uint64 + EnableBlocks bool + SubscribeAllTopics bool // Capture all topics + ActiveIndicies uint64 } func convertToCryptoPrivkey(privkey *ecdsa.PrivateKey) (crypto.PrivKey, error) { diff --git a/cl/sentinel/service/start.go b/cl/sentinel/service/start.go index b61a097c8f6..d333da4ed74 100644 --- a/cl/sentinel/service/start.go +++ b/cl/sentinel/service/start.go @@ -59,7 +59,10 @@ func generateSubnetsTopics(template string, maxIds int) []sentinel.GossipTopic { return topics } -func getExpirationForTopic(topic string) time.Time { +func getExpirationForTopic(topic string, subscribeAll bool) time.Time { + if subscribeAll { + return time.Unix(0, math.MaxInt64) + } if strings.Contains(topic, "beacon_attestation") || (strings.Contains(topic, "sync_committee_") && !strings.Contains(topic, gossip.TopicNameSyncCommitteeContributionAndProof)) { return time.Unix(0, 0) @@ -129,7 +132,7 @@ func createSentinel( } // now lets separately connect to the gossip topics. this joins the room - _, err := sent.SubscribeGossip(v, getExpirationForTopic(v.Name)) // Listen forever. + _, err := sent.SubscribeGossip(v, getExpirationForTopic(v.Name, cfg.SubscribeAllTopics)) // Listen forever. if err != nil { logger.Error("[Sentinel] failed to start sentinel", "err", err) } diff --git a/cmd/caplin/caplin1/run.go b/cmd/caplin/caplin1/run.go index 8dd6b806a43..522f9cf2e0b 100644 --- a/cmd/caplin/caplin1/run.go +++ b/cmd/caplin/caplin1/run.go @@ -275,14 +275,15 @@ func RunCaplinService(ctx context.Context, engine execution_client.ExecutionEngi activeIndicies := state.GetActiveValidatorsIndices(state.Slot() / beaconConfig.SlotsPerEpoch) sentinel, err := service.StartSentinelService(&sentinel.SentinelConfig{ - IpAddr: config.CaplinDiscoveryAddr, - Port: int(config.CaplinDiscoveryPort), - TCPPort: uint(config.CaplinDiscoveryTCPPort), - NetworkConfig: networkConfig, - BeaconConfig: beaconConfig, - TmpDir: dirs.Tmp, - EnableBlocks: true, - ActiveIndicies: uint64(len(activeIndicies)), + IpAddr: config.CaplinDiscoveryAddr, + Port: int(config.CaplinDiscoveryPort), + TCPPort: uint(config.CaplinDiscoveryTCPPort), + SubscribeAllTopics: config.SubscribeAllTopics, + NetworkConfig: networkConfig, + BeaconConfig: beaconConfig, + TmpDir: dirs.Tmp, + EnableBlocks: true, + ActiveIndicies: uint64(len(activeIndicies)), }, rcsn, blobStorage, indexDB, &service.ServerConfig{ Network: "tcp", Addr: fmt.Sprintf("%s:%d", config.SentinelAddr, config.SentinelPort), diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 2e675efad1a..57eaeb76051 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -851,6 +851,11 @@ var ( Usage: "checkpoint sync endpoint", Value: cli.NewStringSlice(), } + CaplinSubscribeAllTopicsFlag = cli.BoolFlag{ + Name: "caplin.subscibe-all-topics", + Usage: "Subscribe to all gossip topics", + Value: false, + } CaplinMevRelayUrl = cli.StringFlag{ Name: "caplin.mev-relay-url", Usage: "MEV relay endpoint. Caplin runs in builder mode if this is set", @@ -1794,6 +1799,8 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C cfg.CaplinConfig.CaplinDiscoveryAddr = ctx.String(CaplinDiscoveryAddrFlag.Name) cfg.CaplinConfig.CaplinDiscoveryPort = ctx.Uint64(CaplinDiscoveryPortFlag.Name) cfg.CaplinConfig.CaplinDiscoveryTCPPort = ctx.Uint64(CaplinDiscoveryTCPPortFlag.Name) + cfg.CaplinConfig.SubscribeAllTopics = ctx.Bool(CaplinSubscribeAllTopicsFlag.Name) + cfg.CaplinConfig.SentinelAddr = ctx.String(SentinelAddrFlag.Name) cfg.CaplinConfig.SentinelPort = ctx.Uint64(SentinelPortFlag.Name) cfg.CaplinConfig.BootstrapNodes = ctx.StringSlice(SentinelBootnodes.Name) diff --git a/turbo/cli/default_flags.go b/turbo/cli/default_flags.go index bf3b6b294b2..74209d0898d 100644 --- a/turbo/cli/default_flags.go +++ b/turbo/cli/default_flags.go @@ -182,6 +182,7 @@ var DefaultFlags = []cli.Flag{ &utils.CaplinDiscoveryPortFlag, &utils.CaplinDiscoveryTCPPortFlag, &utils.CaplinCheckpointSyncUrlFlag, + &utils.CaplinSubscribeAllTopicsFlag, &utils.SentinelAddrFlag, &utils.SentinelPortFlag, &utils.SentinelBootnodes,