2019-08-16 17:13:04 +00:00
|
|
|
package p2p
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/config/params"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
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{
|
2021-12-07 17:52:39 +00:00
|
|
|
BlockSubnetTopicFormat: ðpb.SignedBeaconBlock{},
|
|
|
|
AttestationSubnetTopicFormat: ðpb.Attestation{},
|
|
|
|
ExitSubnetTopicFormat: ðpb.SignedVoluntaryExit{},
|
|
|
|
ProposerSlashingSubnetTopicFormat: ðpb.ProposerSlashing{},
|
|
|
|
AttesterSlashingSubnetTopicFormat: ðpb.AttesterSlashing{},
|
|
|
|
AggregateAndProofSubnetTopicFormat: ðpb.SignedAggregateAttestationAndProof{},
|
2021-08-27 01:34:20 +00:00
|
|
|
SyncContributionAndProofSubnetTopicFormat: ðpb.SignedContributionAndProof{},
|
|
|
|
SyncCommitteeSubnetTopicFormat: ðpb.SyncCommitteeMessage{},
|
2022-11-26 19:07:05 +00:00
|
|
|
BlsToExecutionChangeSubnetTopicFormat: ðpb.SignedBLSToExecutionChange{},
|
2023-05-18 16:13:18 +00:00
|
|
|
BlobSubnetTopicFormat: ðpb.SignedBlobSidecar{},
|
2021-08-27 01:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GossipTopicMappings is a function to return the assigned data type
|
|
|
|
// versioned by epoch.
|
2023-01-26 14:40:12 +00:00
|
|
|
func GossipTopicMappings(topic string, epoch primitives.Epoch) proto.Message {
|
2022-01-20 14:12:15 +00:00
|
|
|
if topic == BlockSubnetTopicFormat {
|
2023-07-10 19:02:44 +00:00
|
|
|
if epoch >= params.BeaconConfig().DenebForkEpoch {
|
|
|
|
return ðpb.SignedBeaconBlockDeneb{}
|
|
|
|
}
|
2022-11-09 23:11:46 +00:00
|
|
|
if epoch >= params.BeaconConfig().CapellaForkEpoch {
|
|
|
|
return ðpb.SignedBeaconBlockCapella{}
|
|
|
|
}
|
2022-01-20 14:12:15 +00:00
|
|
|
if epoch >= params.BeaconConfig().BellatrixForkEpoch {
|
2022-01-26 07:24:47 +00:00
|
|
|
return ðpb.SignedBeaconBlockBellatrix{}
|
2022-01-20 14:12:15 +00:00
|
|
|
}
|
|
|
|
if epoch >= params.BeaconConfig().AltairForkEpoch {
|
|
|
|
return ðpb.SignedBeaconBlockAltair{}
|
|
|
|
}
|
2021-08-27 01:34:20 +00:00
|
|
|
}
|
|
|
|
return gossipTopicMappings[topic]
|
|
|
|
}
|
|
|
|
|
|
|
|
// AllTopics returns all topics stored in our
|
|
|
|
// gossip mapping.
|
|
|
|
func AllTopics() []string {
|
2021-09-24 17:42:16 +00:00
|
|
|
var topics []string
|
2021-08-27 01:34:20 +00:00
|
|
|
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
|
|
|
|
}
|
2022-05-13 18:20:39 +00:00
|
|
|
// Specially handle Altair objects.
|
2021-08-27 01:34:20 +00:00
|
|
|
GossipTypeMapping[reflect.TypeOf(ðpb.SignedBeaconBlockAltair{})] = BlockSubnetTopicFormat
|
2022-05-13 18:20:39 +00:00
|
|
|
// Specially handle Bellatrix objects.
|
2022-01-26 07:24:47 +00:00
|
|
|
GossipTypeMapping[reflect.TypeOf(ðpb.SignedBeaconBlockBellatrix{})] = BlockSubnetTopicFormat
|
2023-06-16 18:37:34 +00:00
|
|
|
// Specially handle Capella objects.
|
2022-11-09 23:11:46 +00:00
|
|
|
GossipTypeMapping[reflect.TypeOf(ðpb.SignedBeaconBlockCapella{})] = BlockSubnetTopicFormat
|
2023-06-16 18:37:34 +00:00
|
|
|
// Specially handle Deneb objects.
|
|
|
|
GossipTypeMapping[reflect.TypeOf(ðpb.SignedBeaconBlockDeneb{})] = BlockSubnetTopicFormat
|
2019-08-16 17:13:04 +00:00
|
|
|
}
|