Skip to content

Commit 9a92fed

Browse files
authored
op-node/p2p: ensure all topics are added to the topic scoring map (ethereum-optimism#15314)
* introduce allBlocksTopics helper * modify test to assert all block topics are present currently failing * add all block topics to map * spacing
1 parent 39666f4 commit 9a92fed

3 files changed

Lines changed: 49 additions & 32 deletions

File tree

op-node/p2p/gossip.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,20 @@ func blocksTopicV4(cfg *rollup.Config) string {
8282
return fmt.Sprintf("/optimism/%s/3/blocks", cfg.L2ChainID.String())
8383
}
8484

85-
// BuildSubscriptionFilter builds a simple subscription filter,
86-
// to help protect against peers spamming useless subscriptions.
87-
func BuildSubscriptionFilter(cfg *rollup.Config) pubsub.SubscriptionFilter {
88-
return pubsub.NewAllowlistSubscriptionFilter(
85+
func allBlocksTopics(cfg *rollup.Config) []string {
86+
return []string{
8987
blocksTopicV1(cfg),
9088
blocksTopicV2(cfg),
9189
blocksTopicV3(cfg),
92-
blocksTopicV4(cfg), // add more topics here in the future, if any.
93-
)
90+
blocksTopicV4(cfg),
91+
// add more topics here in the future, if any.
92+
}
93+
}
94+
95+
// BuildSubscriptionFilter builds a simple subscription filter,
96+
// to help protect against peers spamming useless subscriptions.
97+
func BuildSubscriptionFilter(cfg *rollup.Config) pubsub.SubscriptionFilter {
98+
return pubsub.NewAllowlistSubscriptionFilter(allBlocksTopics(cfg)...)
9499
}
95100

96101
var msgBufPool = sync.Pool{New: func() any {

op-node/p2p/peer_params.go

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,34 @@ func LightPeerScoreParams(cfg *rollup.Config) pubsub.PeerScoreParams {
4343
tenEpochs := 10 * epoch
4444
oneHundredEpochs := 100 * epoch
4545
invalidDecayPeriod := 50 * epoch
46+
47+
defaultTopicScoreParams := pubsub.TopicScoreParams{
48+
TopicWeight: 0.8,
49+
TimeInMeshWeight: MaxInMeshScore / inMeshCap(slot),
50+
TimeInMeshQuantum: slot,
51+
TimeInMeshCap: inMeshCap(slot),
52+
FirstMessageDeliveriesWeight: 1,
53+
FirstMessageDeliveriesDecay: ScoreDecay(20*epoch, slot),
54+
FirstMessageDeliveriesCap: 23,
55+
MeshMessageDeliveriesWeight: MeshWeight,
56+
MeshMessageDeliveriesDecay: ScoreDecay(DecayEpoch*epoch, slot),
57+
MeshMessageDeliveriesCap: float64(uint64(epoch/slot) * uint64(DecayEpoch)),
58+
MeshMessageDeliveriesThreshold: float64(uint64(epoch/slot) * uint64(DecayEpoch) / 10),
59+
MeshMessageDeliveriesWindow: 2 * time.Second,
60+
MeshMessageDeliveriesActivation: 4 * epoch,
61+
MeshFailurePenaltyWeight: MeshWeight,
62+
MeshFailurePenaltyDecay: ScoreDecay(DecayEpoch*epoch, slot),
63+
InvalidMessageDeliveriesWeight: -140.4475,
64+
InvalidMessageDeliveriesDecay: ScoreDecay(invalidDecayPeriod, slot),
65+
}
66+
67+
topics := make(map[string]*pubsub.TopicScoreParams)
68+
for _, topic := range allBlocksTopics(cfg) {
69+
topics[topic] = &defaultTopicScoreParams
70+
}
71+
4672
return pubsub.PeerScoreParams{
47-
Topics: map[string]*pubsub.TopicScoreParams{
48-
blocksTopicV1(cfg): {
49-
TopicWeight: 0.8,
50-
TimeInMeshWeight: MaxInMeshScore / inMeshCap(slot),
51-
TimeInMeshQuantum: slot,
52-
TimeInMeshCap: inMeshCap(slot),
53-
FirstMessageDeliveriesWeight: 1,
54-
FirstMessageDeliveriesDecay: ScoreDecay(20*epoch, slot),
55-
FirstMessageDeliveriesCap: 23,
56-
MeshMessageDeliveriesWeight: MeshWeight,
57-
MeshMessageDeliveriesDecay: ScoreDecay(DecayEpoch*epoch, slot),
58-
MeshMessageDeliveriesCap: float64(uint64(epoch/slot) * uint64(DecayEpoch)),
59-
MeshMessageDeliveriesThreshold: float64(uint64(epoch/slot) * uint64(DecayEpoch) / 10),
60-
MeshMessageDeliveriesWindow: 2 * time.Second,
61-
MeshMessageDeliveriesActivation: 4 * epoch,
62-
MeshFailurePenaltyWeight: MeshWeight,
63-
MeshFailurePenaltyDecay: ScoreDecay(DecayEpoch*epoch, slot),
64-
InvalidMessageDeliveriesWeight: -140.4475,
65-
InvalidMessageDeliveriesDecay: ScoreDecay(invalidDecayPeriod, slot),
66-
},
67-
},
73+
Topics: topics,
6874
TopicScoreCap: 34,
6975
AppSpecificScore: func(p peer.ID) float64 {
7076
return 0

op-node/p2p/peer_params_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
9+
"github.com/ethereum-optimism/optimism/op-node/rollup"
910
pubsub "github.com/libp2p/go-libp2p-pubsub"
1011
"github.com/stretchr/testify/suite"
1112
)
@@ -65,11 +66,7 @@ func (testSuite *PeerParamsTestSuite) TestGetPeerScoreParams_Light() {
6566
scoringParams, err := GetScoringParams("light", cfg)
6667
peerParams := scoringParams.PeerScoring
6768
testSuite.NoError(err)
68-
// Topics should contain options for block topic
69-
testSuite.Len(peerParams.Topics, 1)
70-
topicParams, ok := peerParams.Topics[blocksTopicV1(cfg)]
71-
testSuite.True(ok, "should have block topic params")
72-
testSuite.NotZero(topicParams.TimeInMeshQuantum)
69+
requireAllTopicsPresent(testSuite, peerParams, cfg)
7370
testSuite.Equal(peerParams.TopicScoreCap, float64(34))
7471
testSuite.Equal(peerParams.AppSpecificWeight, float64(1))
7572
testSuite.Equal(peerParams.IPColocationFactorWeight, float64(-35))
@@ -96,6 +93,15 @@ func (testSuite *PeerParamsTestSuite) TestGetPeerScoreParams_Light() {
9693
testSuite.Equal(slot, appParams.DecayInterval)
9794
}
9895

96+
// requireAllTopicsPresent checks that all block topics are present in the peer params.
97+
func requireAllTopicsPresent(testSuite *PeerParamsTestSuite, peerParams pubsub.PeerScoreParams, cfg *rollup.Config) {
98+
for _, topic := range allBlocksTopics(cfg) {
99+
topicParams, ok := peerParams.Topics[topic]
100+
testSuite.True(ok, "should have block topic params, topic: %s", topic)
101+
testSuite.NotZero(topicParams.TimeInMeshQuantum, "should have nonzero TimeInMeshQuantum")
102+
}
103+
}
104+
99105
// TestParamsZeroBlockTime validates peer score params use default slot for 0 block time.
100106
func (testSuite *PeerParamsTestSuite) TestParamsZeroBlockTime() {
101107
cfg := chaincfg.OPSepolia()

0 commit comments

Comments
 (0)