Skip to content

Commit

Permalink
Listen to two random attestation subnets (#12254)
Browse files Browse the repository at this point in the history
randomly choosing two attestation subnets and subscribing indefinitely.

Co-authored-by: shota.silagadze <[email protected]>
  • Loading branch information
shotasilagadze and shotasilagadzetaal authored Oct 10, 2024
1 parent 709c6ba commit 39b62b4
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions cl/sentinel/service/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package service
import (
"context"
"fmt"
"math/rand/v2"
"net"
"strings"
"time"
Expand All @@ -41,6 +42,8 @@ import (
"github.com/erigontech/erigon/cl/cltypes"
)

const AttestationSubnetSubscriptions = 2

type ServerConfig struct {
Network string
Addr string
Expand All @@ -56,6 +59,12 @@ func generateSubnetsTopics(template string, maxIds int) []sentinel.GossipTopic {
CodecStr: sentinel.SSZSnappyCodec,
})
}

if template == gossip.TopicNamePrefixBeaconAttestation {
rand.Shuffle(len(topics), func(i, j int) {
topics[i], topics[j] = topics[j], topics[i]
})
}
return topics
}

Expand Down Expand Up @@ -112,12 +121,16 @@ func createSentinel(
gossip.TopicNamePrefixBlobSidecar,
int(cfg.BeaconConfig.MaxBlobsPerBlock),
)...)

attestationSubnetTopics := generateSubnetsTopics(
gossip.TopicNamePrefixBeaconAttestation,
int(cfg.NetworkConfig.AttestationSubnetCount),
)

gossipTopics = append(
gossipTopics,
generateSubnetsTopics(
gossip.TopicNamePrefixBeaconAttestation,
int(cfg.NetworkConfig.AttestationSubnetCount),
)...)
attestationSubnetTopics[AttestationSubnetSubscriptions:]...)

gossipTopics = append(
gossipTopics,
generateSubnetsTopics(
Expand All @@ -137,6 +150,17 @@ func createSentinel(
logger.Error("[Sentinel] failed to start sentinel", "err", err)
}
}

for k := 0; k < AttestationSubnetSubscriptions; k++ {
if err := sent.Unsubscribe(attestationSubnetTopics[k]); err != nil {
logger.Error("[Sentinel] failed to start sentinel", "err", err)
continue
}
_, err := sent.SubscribeGossip(attestationSubnetTopics[k], time.Unix(0, math.MaxInt64)) // Listen forever.
if err != nil {
logger.Error("[Sentinel] failed to start sentinel", "err", err)
}
}
return sent, nil
}

Expand Down

0 comments on commit 39b62b4

Please sign in to comment.