mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
d9799e6b6c
* Rename BeaconBlockBodyMerge to BeaconBlockBodyBellatrix * Rename SignedBeaconBlockMerge to SignedBeaconBlockBellatrix * Rename CopyBeaconBlockMerge to CopyBeaconBlockMerge * Rename NewBeaconBlockMerge to NewBeaconBlockBellatrix * Rename BeaconBlockMerge to BeaconBlockBellatrix * Rename some comments and strings in pkg proto: Merge -> Bellatrix * Rename PbMergeBlock to PbBellatrixBlock * Many renames of merge -> bellatrix in proto package * Rename some Merge -> Bellatrix in beacon chain package * More names * Fix formating in config/params/config.go * Rename Merge -> Bellatrix in proto/prysm/storage * Several renames and corrections Merge -> Bellatrix Co-authored-by: Potuz <potuz@potuz.net> Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Potuz <potuz@potuz.net> Co-authored-by: Nishant Das <nishdas93@gmail.com>
61 lines
2.1 KiB
Go
61 lines
2.1 KiB
Go
package p2p
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
|
ethpb "github.com/prysmaticlabs/prysm/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{},
|
|
}
|
|
|
|
// 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 {
|
|
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
|
|
GossipTypeMapping[reflect.TypeOf(ðpb.SignedBeaconBlockBellatrix{})] = BlockSubnetTopicFormat
|
|
}
|