-
Notifications
You must be signed in to change notification settings - Fork 974
/
gossip_topic_mappings.go
67 lines (60 loc) · 2.51 KB
/
gossip_topic_mappings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package p2p
import (
"reflect"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"google.golang.org/protobuf/proto"
)
// gossipTopicMappings represent the protocol ID to protobuf message type map for easy
// lookup.
var gossipTopicMappings = map[string]proto.Message{
BlockSubnetTopicFormat: ðpb.SignedBeaconBlock{},
AttestationSubnetTopicFormat: ðpb.Attestation{},
ExitSubnetTopicFormat: ðpb.SignedVoluntaryExit{},
ProposerSlashingSubnetTopicFormat: ðpb.ProposerSlashing{},
AttesterSlashingSubnetTopicFormat: ðpb.AttesterSlashing{},
AggregateAndProofSubnetTopicFormat: ðpb.SignedAggregateAttestationAndProof{},
SyncContributionAndProofSubnetTopicFormat: ðpb.SignedContributionAndProof{},
SyncCommitteeSubnetTopicFormat: ðpb.SyncCommitteeMessage{},
BlsToExecutionChangeSubnetTopicFormat: ðpb.SignedBLSToExecutionChange{},
}
// GossipTopicMappings is a function to return the assigned data type
// versioned by epoch.
func GossipTopicMappings(topic string, epoch primitives.Epoch) proto.Message {
if topic == BlockSubnetTopicFormat {
if epoch >= params.BeaconConfig().CapellaForkEpoch {
return ðpb.SignedBeaconBlockCapella{}
}
if epoch >= params.BeaconConfig().BellatrixForkEpoch {
return ðpb.SignedBeaconBlockBellatrix{}
}
if epoch >= params.BeaconConfig().AltairForkEpoch {
return ðpb.SignedBeaconBlockAltair{}
}
}
return gossipTopicMappings[topic]
}
// AllTopics returns all topics stored in our
// gossip mapping.
func AllTopics() []string {
var topics []string
for k := range gossipTopicMappings {
topics = append(topics, k)
}
return topics
}
// GossipTypeMapping is the inverse of GossipTopicMappings so that an arbitrary protobuf message
// can be mapped to a protocol ID string.
var GossipTypeMapping = make(map[reflect.Type]string, len(gossipTopicMappings))
func init() {
for k, v := range gossipTopicMappings {
GossipTypeMapping[reflect.TypeOf(v)] = k
}
// Specially handle Altair objects.
GossipTypeMapping[reflect.TypeOf(ðpb.SignedBeaconBlockAltair{})] = BlockSubnetTopicFormat
// Specially handle Bellatrix objects.
GossipTypeMapping[reflect.TypeOf(ðpb.SignedBeaconBlockBellatrix{})] = BlockSubnetTopicFormat
// Specially handle Capella objects
GossipTypeMapping[reflect.TypeOf(ðpb.SignedBeaconBlockCapella{})] = BlockSubnetTopicFormat
}