Skip to content

Commit

Permalink
Caplin: Add flag to listen to entire network traffic (#12226)
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio2002 authored Oct 4, 2024
1 parent 3117d74 commit a6e319c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions cl/clparams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type CaplinConfig struct {
CaplinDiscoveryTCPPort uint64
SentinelAddr string
SentinelPort uint64
SubscribeAllTopics bool
// Erigon Sync
LoopBlockLimit uint64
// Beacon API router configuration
Expand Down
5 changes: 3 additions & 2 deletions cl/sentinel/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions cl/sentinel/service/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
17 changes: 9 additions & 8 deletions cmd/caplin/caplin1/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 7 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ var DefaultFlags = []cli.Flag{
&utils.CaplinDiscoveryPortFlag,
&utils.CaplinDiscoveryTCPPortFlag,
&utils.CaplinCheckpointSyncUrlFlag,
&utils.CaplinSubscribeAllTopicsFlag,
&utils.SentinelAddrFlag,
&utils.SentinelPortFlag,
&utils.SentinelBootnodes,
Expand Down

0 comments on commit a6e319c

Please sign in to comment.