mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
69 lines
2.6 KiB
Go
69 lines
2.6 KiB
Go
package p2p
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/config/params"
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/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{},
|
|
BlobSubnetTopicFormat: ðpb.SignedBlobSidecar{},
|
|
}
|
|
|
|
// 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
|
|
}
|