2019-08-16 17:13:04 +00:00
|
|
|
package p2p
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
|
2021-08-27 01:34:20 +00:00
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2021-07-21 21:34:07 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2021-08-27 01:34:20 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
2021-05-17 18:32:04 +00:00
|
|
|
"google.golang.org/protobuf/proto"
|
2019-08-16 17:13:04 +00:00
|
|
|
)
|
|
|
|
|
2021-08-27 01:34:20 +00:00
|
|
|
// gossipTopicMappings represent the protocol ID to protobuf message type map for easy
|
2019-08-16 17:13:04 +00:00
|
|
|
// lookup.
|
2021-08-27 01:34:20 +00:00
|
|
|
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{},
|
|
|
|
}
|
|
|
|
|
|
|
|
// GossipTopicMappings is a function to return the assigned data type
|
|
|
|
// versioned by epoch.
|
|
|
|
func GossipTopicMappings(topic string, epoch types.Epoch) proto.Message {
|
|
|
|
if topic == BlockSubnetTopicFormat && epoch >= params.BeaconConfig().AltairForkEpoch {
|
|
|
|
return ðpb.SignedBeaconBlockAltair{}
|
|
|
|
}
|
|
|
|
return gossipTopicMappings[topic]
|
|
|
|
}
|
|
|
|
|
|
|
|
// AllTopics returns all topics stored in our
|
|
|
|
// gossip mapping.
|
|
|
|
func AllTopics() []string {
|
|
|
|
topics := []string{}
|
|
|
|
for k := range gossipTopicMappings {
|
|
|
|
topics = append(topics, k)
|
|
|
|
}
|
|
|
|
return topics
|
2019-08-16 17:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GossipTypeMapping is the inverse of GossipTopicMappings so that an arbitrary protobuf message
|
|
|
|
// can be mapped to a protocol ID string.
|
2021-08-27 01:34:20 +00:00
|
|
|
var GossipTypeMapping = make(map[reflect.Type]string, len(gossipTopicMappings))
|
2019-08-16 17:13:04 +00:00
|
|
|
|
|
|
|
func init() {
|
2021-08-27 01:34:20 +00:00
|
|
|
for k, v := range gossipTopicMappings {
|
2019-08-16 17:13:04 +00:00
|
|
|
GossipTypeMapping[reflect.TypeOf(v)] = k
|
|
|
|
}
|
2021-08-27 01:34:20 +00:00
|
|
|
// Specially handle Altair Objects.
|
|
|
|
GossipTypeMapping[reflect.TypeOf(ðpb.SignedBeaconBlockAltair{})] = BlockSubnetTopicFormat
|
2019-08-16 17:13:04 +00:00
|
|
|
}
|