Skip to content

Commit 60d8cea

Browse files
committed
TopicFromMessage: Do not assume anymore that all Fulu specific topics are V3 only.
1 parent e0a3998 commit 60d8cea

File tree

2 files changed

+37
-52
lines changed

2 files changed

+37
-52
lines changed

beacon-chain/p2p/rpc_topic_mappings.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ var (
193193
}
194194

195195
// Maps all the RPC messages which are to updated in altair.
196-
altairMapping = map[string]bool{
197-
BeaconBlocksByRangeMessageName: true,
198-
BeaconBlocksByRootsMessageName: true,
199-
MetadataMessageName: true,
196+
altairMapping = map[string]string{
197+
BeaconBlocksByRangeMessageName: SchemaVersionV2,
198+
BeaconBlocksByRootsMessageName: SchemaVersionV2,
199+
MetadataMessageName: SchemaVersionV2,
200200
}
201201

202202
// Maps all the RPC messages which are to updated in fulu.
203-
fuluMapping = map[string]bool{
204-
MetadataMessageName: true,
203+
fuluMapping = map[string]string{
204+
MetadataMessageName: SchemaVersionV3,
205205
}
206206

207207
versionMapping = map[string]bool{
@@ -344,13 +344,17 @@ func TopicFromMessage(msg string, epoch primitives.Epoch) (string, error) {
344344
beaconConfig := params.BeaconConfig()
345345

346346
// Check if the message is to be updated in fulu.
347-
if epoch >= beaconConfig.FuluForkEpoch && fuluMapping[msg] {
348-
return protocolPrefix + msg + SchemaVersionV3, nil
347+
if epoch >= beaconConfig.FuluForkEpoch {
348+
if version, ok := fuluMapping[msg]; ok {
349+
return protocolPrefix + msg + version, nil
350+
}
349351
}
350352

351353
// Check if the message is to be updated in altair.
352-
if epoch >= beaconConfig.AltairForkEpoch && altairMapping[msg] {
353-
return protocolPrefix + msg + SchemaVersionV2, nil
354+
if epoch >= beaconConfig.AltairForkEpoch {
355+
if version, ok := altairMapping[msg]; ok {
356+
return protocolPrefix + msg + version, nil
357+
}
354358
}
355359

356360
return protocolPrefix + msg + SchemaVersionV1, nil

beacon-chain/p2p/rpc_topic_mappings_test.go

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -119,50 +119,31 @@ func TestTopicFromMessage_CorrectType(t *testing.T) {
119119
})
120120

121121
t.Run("after altair fork but before fulu fork", func(t *testing.T) {
122-
for m := range messageMapping {
123-
topic, err := TopicFromMessage(m, altairForkEpoch)
124-
require.NoError(t, err)
125-
126-
if altairMapping[m] {
127-
require.Equal(t, true, strings.Contains(topic, SchemaVersionV2))
128-
_, _, version, err := TopicDeconstructor(topic)
129-
require.NoError(t, err)
130-
require.Equal(t, SchemaVersionV2, version)
131-
continue
132-
}
133-
134-
require.Equal(t, true, strings.Contains(topic, SchemaVersionV1))
135-
_, _, version, err := TopicDeconstructor(topic)
136-
require.NoError(t, err)
137-
require.Equal(t, SchemaVersionV1, version)
138-
}
122+
// Not modified in altair fork.
123+
topic, err := TopicFromMessage(GoodbyeMessageName, altairForkEpoch)
124+
require.NoError(t, err)
125+
require.Equal(t, "/eth2/beacon_chain/req/goodbye/1", topic)
126+
127+
// Modified in altair fork.
128+
topic, err = TopicFromMessage(MetadataMessageName, altairForkEpoch)
129+
require.NoError(t, err)
130+
require.Equal(t, "/eth2/beacon_chain/req/metadata/2", topic)
139131
})
140132

141133
t.Run("after fulu fork", func(t *testing.T) {
142-
for m := range messageMapping {
143-
topic, err := TopicFromMessage(m, fuluForkEpoch)
144-
require.NoError(t, err)
145-
146-
if fuluMapping[m] {
147-
require.Equal(t, true, strings.Contains(topic, SchemaVersionV3))
148-
_, _, version, err := TopicDeconstructor(topic)
149-
require.NoError(t, err)
150-
require.Equal(t, SchemaVersionV3, version)
151-
continue
152-
}
153-
154-
if altairMapping[m] {
155-
require.Equal(t, true, strings.Contains(topic, SchemaVersionV2))
156-
_, _, version, err := TopicDeconstructor(topic)
157-
require.NoError(t, err)
158-
require.Equal(t, SchemaVersionV2, version)
159-
continue
160-
}
161-
162-
require.Equal(t, true, strings.Contains(topic, SchemaVersionV1))
163-
_, _, version, err := TopicDeconstructor(topic)
164-
require.NoError(t, err)
165-
require.Equal(t, SchemaVersionV1, version)
166-
}
134+
// Not modified in any fork.
135+
topic, err := TopicFromMessage(GoodbyeMessageName, fuluForkEpoch)
136+
require.NoError(t, err)
137+
require.Equal(t, "/eth2/beacon_chain/req/goodbye/1", topic)
138+
139+
// Modified in altair fork.
140+
topic, err = TopicFromMessage(BeaconBlocksByRangeMessageName, fuluForkEpoch)
141+
require.NoError(t, err)
142+
require.Equal(t, "/eth2/beacon_chain/req/beacon_blocks_by_range/2", topic)
143+
144+
// Modified both in altair and fulu fork.
145+
topic, err = TopicFromMessage(MetadataMessageName, fuluForkEpoch)
146+
require.NoError(t, err)
147+
require.Equal(t, "/eth2/beacon_chain/req/metadata/3", topic)
167148
})
168149
}

0 commit comments

Comments
 (0)