merge upstream

This commit is contained in:
realbigsean
2022-11-26 10:01:57 -05:00
29 changed files with 557 additions and 69 deletions

View File

@@ -36,6 +36,8 @@ pub struct GossipCache {
signed_contribution_and_proof: Option<Duration>,
/// Timeout for sync committee messages.
sync_committee_message: Option<Duration>,
/// Timeout for signed BLS to execution changes.
bls_to_execution_change: Option<Duration>,
}
#[derive(Default)]
@@ -59,6 +61,8 @@ pub struct GossipCacheBuilder {
signed_contribution_and_proof: Option<Duration>,
/// Timeout for sync committee messages.
sync_committee_message: Option<Duration>,
/// Timeout for signed BLS to execution changes.
bls_to_execution_change: Option<Duration>,
}
#[allow(dead_code)]
@@ -117,6 +121,12 @@ impl GossipCacheBuilder {
self
}
/// Timeout for BLS to execution change messages.
pub fn bls_to_execution_change_timeout(mut self, timeout: Duration) -> Self {
self.bls_to_execution_change = Some(timeout);
self
}
pub fn build(self) -> GossipCache {
let GossipCacheBuilder {
default_timeout,
@@ -129,6 +139,7 @@ impl GossipCacheBuilder {
attester_slashing,
signed_contribution_and_proof,
sync_committee_message,
bls_to_execution_change,
} = self;
GossipCache {
expirations: DelayQueue::default(),
@@ -142,6 +153,7 @@ impl GossipCacheBuilder {
attester_slashing: attester_slashing.or(default_timeout),
signed_contribution_and_proof: signed_contribution_and_proof.or(default_timeout),
sync_committee_message: sync_committee_message.or(default_timeout),
bls_to_execution_change: bls_to_execution_change.or(default_timeout),
}
}
}
@@ -165,6 +177,7 @@ impl GossipCache {
GossipKind::AttesterSlashing => self.attester_slashing,
GossipKind::SignedContributionAndProof => self.signed_contribution_and_proof,
GossipKind::SyncCommitteeMessage(_) => self.sync_committee_message,
GossipKind::BlsToExecutionChange => self.bls_to_execution_change,
};
let expire_timeout = match expire_timeout {
Some(expire_timeout) => expire_timeout,

View File

@@ -199,6 +199,7 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
.attester_slashing_timeout(half_epoch * 2)
// .signed_contribution_and_proof_timeout(timeout) // Do not retry
// .sync_committee_message_timeout(timeout) // Do not retry
.bls_to_execution_change_timeout(half_epoch * 2)
.build()
};

View File

@@ -253,6 +253,7 @@ pub(crate) fn create_whitelist_filter(
add(ProposerSlashing);
add(AttesterSlashing);
add(SignedContributionAndProof);
add(BlsToExecutionChange);
add(BeaconBlocksAndBlobsSidecar);
for id in 0..attestation_subnet_count {
add(Attestation(SubnetId::new(id)));

View File

@@ -15,8 +15,8 @@ use types::{
Attestation, AttesterSlashing, BlobsSidecar, EthSpec, ForkContext, ForkName, ProposerSlashing,
SignedAggregateAndProof, SignedBeaconBlock, SignedBeaconBlockAltair,
SignedBeaconBlockAndBlobsSidecar, SignedBeaconBlockBase, SignedBeaconBlockCapella,
SignedBeaconBlockEip4844, SignedBeaconBlockMerge, SignedContributionAndProof,
SignedVoluntaryExit, SubnetId, SyncCommitteeMessage, SyncSubnetId,
SignedBeaconBlockEip4844, SignedBeaconBlockMerge, SignedBlsToExecutionChange,
SignedContributionAndProof, SignedVoluntaryExit, SubnetId, SyncCommitteeMessage, SyncSubnetId,
};
#[derive(Debug, Clone, PartialEq)]
@@ -39,6 +39,8 @@ pub enum PubsubMessage<T: EthSpec> {
SignedContributionAndProof(Box<SignedContributionAndProof<T>>),
/// Gossipsub message providing notification of unaggregated sync committee signatures with its subnet id.
SyncCommitteeMessage(Box<(SyncSubnetId, SyncCommitteeMessage)>),
/// Gossipsub message for BLS to execution change messages.
BlsToExecutionChange(Box<SignedBlsToExecutionChange>),
}
// Implements the `DataTransform` trait of gossipsub to employ snappy compression
@@ -124,6 +126,7 @@ impl<T: EthSpec> PubsubMessage<T> {
PubsubMessage::AttesterSlashing(_) => GossipKind::AttesterSlashing,
PubsubMessage::SignedContributionAndProof(_) => GossipKind::SignedContributionAndProof,
PubsubMessage::SyncCommitteeMessage(data) => GossipKind::SyncCommitteeMessage(data.0),
PubsubMessage::BlsToExecutionChange(_) => GossipKind::BlsToExecutionChange,
}
}
@@ -249,6 +252,14 @@ impl<T: EthSpec> PubsubMessage<T> {
sync_committee,
))))
}
GossipKind::BlsToExecutionChange => {
let bls_to_execution_change =
SignedBlsToExecutionChange::from_ssz_bytes(data)
.map_err(|e| format!("{:?}", e))?;
Ok(PubsubMessage::BlsToExecutionChange(Box::new(
bls_to_execution_change,
)))
}
}
}
}
@@ -271,6 +282,7 @@ impl<T: EthSpec> PubsubMessage<T> {
PubsubMessage::Attestation(data) => data.1.as_ssz_bytes(),
PubsubMessage::SignedContributionAndProof(data) => data.as_ssz_bytes(),
PubsubMessage::SyncCommitteeMessage(data) => data.1.as_ssz_bytes(),
PubsubMessage::BlsToExecutionChange(data) => data.as_ssz_bytes(),
}
}
}
@@ -311,6 +323,13 @@ impl<T: EthSpec> std::fmt::Display for PubsubMessage<T> {
PubsubMessage::SyncCommitteeMessage(data) => {
write!(f, "Sync committee message: subnet_id: {}", *data.0)
}
PubsubMessage::BlsToExecutionChange(data) => {
write!(
f,
"Signed BLS to execution change: validator_index: {}, address: {:?}",
data.message.validator_index, data.message.to_execution_address
)
}
}
}
}

View File

@@ -19,8 +19,9 @@ pub const PROPOSER_SLASHING_TOPIC: &str = "proposer_slashing";
pub const ATTESTER_SLASHING_TOPIC: &str = "attester_slashing";
pub const SIGNED_CONTRIBUTION_AND_PROOF_TOPIC: &str = "sync_committee_contribution_and_proof";
pub const SYNC_COMMITTEE_PREFIX_TOPIC: &str = "sync_committee_";
pub const BLS_TO_EXECUTION_CHANGE_TOPIC: &str = "bls_to_execution_change";
pub const CORE_TOPICS: [GossipKind; 7] = [
pub const CORE_TOPICS: [GossipKind; 8] = [
GossipKind::BeaconBlock,
GossipKind::BeaconBlocksAndBlobsSidecar,
GossipKind::BeaconAggregateAndProof,
@@ -28,6 +29,7 @@ pub const CORE_TOPICS: [GossipKind; 7] = [
GossipKind::ProposerSlashing,
GossipKind::AttesterSlashing,
GossipKind::SignedContributionAndProof,
GossipKind::BlsToExecutionChange,
];
/// A gossipsub topic which encapsulates the type of messages that should be sent and received over
@@ -67,6 +69,8 @@ pub enum GossipKind {
/// Topic for publishing unaggregated sync committee signatures on a particular subnet.
#[strum(serialize = "sync_committee")]
SyncCommitteeMessage(SyncSubnetId),
/// Topic for validator messages which change their withdrawal address.
BlsToExecutionChange,
}
impl std::fmt::Display for GossipKind {
@@ -141,6 +145,7 @@ impl GossipTopic {
VOLUNTARY_EXIT_TOPIC => GossipKind::VoluntaryExit,
PROPOSER_SLASHING_TOPIC => GossipKind::ProposerSlashing,
ATTESTER_SLASHING_TOPIC => GossipKind::AttesterSlashing,
BLS_TO_EXECUTION_CHANGE_TOPIC => GossipKind::BlsToExecutionChange,
topic => match committee_topic_index(topic) {
Some(subnet) => match subnet {
Subnet::Attestation(s) => GossipKind::Attestation(s),
@@ -177,30 +182,8 @@ impl From<GossipTopic> for Topic {
impl From<GossipTopic> for String {
fn from(topic: GossipTopic) -> String {
let encoding = match topic.encoding {
GossipEncoding::SSZSnappy => SSZ_SNAPPY_ENCODING_POSTFIX,
};
let kind = match topic.kind {
GossipKind::BeaconBlock => BEACON_BLOCK_TOPIC.into(),
GossipKind::BeaconBlocksAndBlobsSidecar => BEACON_BLOCK_AND_BLOBS_SIDECAR_TOPIC.into(),
GossipKind::BeaconAggregateAndProof => BEACON_AGGREGATE_AND_PROOF_TOPIC.into(),
GossipKind::VoluntaryExit => VOLUNTARY_EXIT_TOPIC.into(),
GossipKind::ProposerSlashing => PROPOSER_SLASHING_TOPIC.into(),
GossipKind::AttesterSlashing => ATTESTER_SLASHING_TOPIC.into(),
GossipKind::Attestation(index) => format!("{}{}", BEACON_ATTESTATION_PREFIX, *index,),
GossipKind::SignedContributionAndProof => SIGNED_CONTRIBUTION_AND_PROOF_TOPIC.into(),
GossipKind::SyncCommitteeMessage(index) => {
format!("{}{}", SYNC_COMMITTEE_PREFIX_TOPIC, *index)
}
};
format!(
"/{}/{}/{}/{}",
TOPIC_PREFIX,
hex::encode(topic.fork_digest),
kind,
encoding
)
// Use the `Display` implementation below.
topic.to_string()
}
}
@@ -222,6 +205,7 @@ impl std::fmt::Display for GossipTopic {
GossipKind::SyncCommitteeMessage(index) => {
format!("{}{}", SYNC_COMMITTEE_PREFIX_TOPIC, *index)
}
GossipKind::BlsToExecutionChange => BLS_TO_EXECUTION_CHANGE_TOPIC.into(),
};
write!(
f,