From 024dbf6efc89ffaa312b77bac151ea1d8342e8b3 Mon Sep 17 00:00:00 2001 From: jacobkaufmann Date: Mon, 25 Nov 2024 16:27:36 -0700 Subject: [PATCH] add IL type, gossip kind, and pubsub message --- .../src/service/gossip_cache.rs | 1 + .../lighthouse_network/src/types/pubsub.rs | 14 ++++- .../lighthouse_network/src/types/topics.rs | 9 +++- beacon_node/network/src/router.rs | 3 ++ consensus/types/src/eth_spec.rs | 15 +++++- consensus/types/src/inclusion_list.rs | 53 +++++++++++++++++++ consensus/types/src/lib.rs | 2 + 7 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 consensus/types/src/inclusion_list.rs diff --git a/beacon_node/lighthouse_network/src/service/gossip_cache.rs b/beacon_node/lighthouse_network/src/service/gossip_cache.rs index 0ad31ff2e8..13b31579f9 100644 --- a/beacon_node/lighthouse_network/src/service/gossip_cache.rs +++ b/beacon_node/lighthouse_network/src/service/gossip_cache.rs @@ -211,6 +211,7 @@ impl GossipCache { GossipKind::BlsToExecutionChange => self.bls_to_execution_change, GossipKind::LightClientFinalityUpdate => self.light_client_finality_update, GossipKind::LightClientOptimisticUpdate => self.light_client_optimistic_update, + GossipKind::InclusionList => None, }; let Some(expire_timeout) = expire_timeout else { return; diff --git a/beacon_node/lighthouse_network/src/types/pubsub.rs b/beacon_node/lighthouse_network/src/types/pubsub.rs index 9f68278e28..176b904179 100644 --- a/beacon_node/lighthouse_network/src/types/pubsub.rs +++ b/beacon_node/lighthouse_network/src/types/pubsub.rs @@ -9,7 +9,7 @@ use std::sync::Arc; use types::{ Attestation, AttestationBase, AttestationElectra, AttesterSlashing, AttesterSlashingBase, AttesterSlashingElectra, BlobSidecar, DataColumnSidecar, DataColumnSubnetId, EthSpec, - ForkContext, ForkName, LightClientFinalityUpdate, LightClientOptimisticUpdate, + ForkContext, ForkName, InclusionList, LightClientFinalityUpdate, LightClientOptimisticUpdate, ProposerSlashing, SignedAggregateAndProof, SignedAggregateAndProofBase, SignedAggregateAndProofElectra, SignedBeaconBlock, SignedBeaconBlockAltair, SignedBeaconBlockBase, SignedBeaconBlockBellatrix, SignedBeaconBlockCapella, @@ -45,6 +45,8 @@ pub enum PubsubMessage { LightClientFinalityUpdate(Box>), /// Gossipsub message providing notification of a light client optimistic update. LightClientOptimisticUpdate(Box>), + /// Gossipsub message providing notification of an inclusion list. + InclusionList(Box>), } // Implements the `DataTransform` trait of gossipsub to employ snappy compression @@ -138,6 +140,7 @@ impl PubsubMessage { PubsubMessage::LightClientOptimisticUpdate(_) => { GossipKind::LightClientOptimisticUpdate } + PubsubMessage::InclusionList(_) => GossipKind::InclusionList, } } @@ -390,6 +393,11 @@ impl PubsubMessage { light_client_optimistic_update, ))) } + GossipKind::InclusionList => { + let il = + InclusionList::from_ssz_bytes(data).map_err(|e| format!("{:?}", e))?; + Ok(PubsubMessage::InclusionList(Box::new(il))) + } } } } @@ -416,6 +424,7 @@ impl PubsubMessage { PubsubMessage::BlsToExecutionChange(data) => data.as_ssz_bytes(), PubsubMessage::LightClientFinalityUpdate(data) => data.as_ssz_bytes(), PubsubMessage::LightClientOptimisticUpdate(data) => data.as_ssz_bytes(), + PubsubMessage::InclusionList(data) => data.as_ssz_bytes(), } } } @@ -477,6 +486,9 @@ impl std::fmt::Display for PubsubMessage { PubsubMessage::LightClientOptimisticUpdate(_data) => { write!(f, "Light CLient Optimistic Update") } + PubsubMessage::InclusionList(_data) => { + write!(f, "Inclusion List") + } } } } diff --git a/beacon_node/lighthouse_network/src/types/topics.rs b/beacon_node/lighthouse_network/src/types/topics.rs index 174787f999..6970218883 100644 --- a/beacon_node/lighthouse_network/src/types/topics.rs +++ b/beacon_node/lighthouse_network/src/types/topics.rs @@ -23,6 +23,7 @@ pub const SYNC_COMMITTEE_PREFIX_TOPIC: &str = "sync_committee_"; pub const BLS_TO_EXECUTION_CHANGE_TOPIC: &str = "bls_to_execution_change"; pub const LIGHT_CLIENT_FINALITY_UPDATE: &str = "light_client_finality_update"; pub const LIGHT_CLIENT_OPTIMISTIC_UPDATE: &str = "light_client_optimistic_update"; +pub const INCLUSION_LIST_TOPIC: &str = "inclusion_list"; pub const BASE_CORE_TOPICS: [GossipKind; 5] = [ GossipKind::BeaconBlock, @@ -43,6 +44,8 @@ pub const LIGHT_CLIENT_GOSSIP_TOPICS: [GossipKind; 2] = [ pub const DENEB_CORE_TOPICS: [GossipKind; 0] = []; +pub const ELECTRA_CORE_TOPICS: [GossipKind; 1] = [GossipKind::InclusionList]; + /// Returns the core topics associated with each fork that are new to the previous fork pub fn fork_core_topics(fork_name: &ForkName, spec: &ChainSpec) -> Vec { match fork_name { @@ -60,7 +63,7 @@ pub fn fork_core_topics(fork_name: &ForkName, spec: &ChainSpec) -> V deneb_topics.append(&mut deneb_blob_topics); deneb_topics } - ForkName::Electra => vec![], + ForkName::Electra => ELECTRA_CORE_TOPICS.to_vec(), } } @@ -135,6 +138,8 @@ pub enum GossipKind { LightClientFinalityUpdate, /// Topic for publishing optimistic updates for light clients. LightClientOptimisticUpdate, + /// Topic for publishing inclusion lists. + InclusionList, } impl std::fmt::Display for GossipKind { @@ -217,6 +222,7 @@ impl GossipTopic { BLS_TO_EXECUTION_CHANGE_TOPIC => GossipKind::BlsToExecutionChange, LIGHT_CLIENT_FINALITY_UPDATE => GossipKind::LightClientFinalityUpdate, LIGHT_CLIENT_OPTIMISTIC_UPDATE => GossipKind::LightClientOptimisticUpdate, + INCLUSION_LIST_TOPIC => GossipKind::InclusionList, topic => match subnet_topic_index(topic) { Some(kind) => kind, None => return Err(format!("Unknown topic: {}", topic)), @@ -282,6 +288,7 @@ impl std::fmt::Display for GossipTopic { GossipKind::BlsToExecutionChange => BLS_TO_EXECUTION_CHANGE_TOPIC.into(), GossipKind::LightClientFinalityUpdate => LIGHT_CLIENT_FINALITY_UPDATE.into(), GossipKind::LightClientOptimisticUpdate => LIGHT_CLIENT_OPTIMISTIC_UPDATE.into(), + GossipKind::InclusionList => INCLUSION_LIST_TOPIC.into(), }; write!( f, diff --git a/beacon_node/network/src/router.rs b/beacon_node/network/src/router.rs index e1badfda9d..ee87eccfc9 100644 --- a/beacon_node/network/src/router.rs +++ b/beacon_node/network/src/router.rs @@ -542,6 +542,9 @@ impl Router { bls_to_execution_change, ), ), + PubsubMessage::InclusionList(il) => { + // TODO + } } } diff --git a/consensus/types/src/eth_spec.rs b/consensus/types/src/eth_spec.rs index 09ef8e3c1a..c8e6fbaa97 100644 --- a/consensus/types/src/eth_spec.rs +++ b/consensus/types/src/eth_spec.rs @@ -160,6 +160,11 @@ pub trait EthSpec: type MaxAttestationsElectra: Unsigned + Clone + Sync + Send + Debug + PartialEq; type MaxWithdrawalRequestsPerPayload: Unsigned + Clone + Sync + Send + Debug + PartialEq; + /* + * FOCIL + */ + type MaxTransactionsPerInclusionList: Unsigned + Clone + Sync + Send + Debug + PartialEq; + fn default_spec() -> ChainSpec; fn spec_name() -> EthSpecId; @@ -374,6 +379,11 @@ pub trait EthSpec: fn kzg_commitments_inclusion_proof_depth() -> usize { Self::KzgCommitmentsInclusionProofDepth::to_usize() } + + /// Returns the `MAX_TRANSACTIONS_PER_INCLUSION_LIST` constant for this specification. + fn max_transactions_per_inclusion_list() -> usize { + Self::MaxTransactionsPerInclusionList::to_usize() + } } /// Macro to inherit some type values from another EthSpec. @@ -438,6 +448,7 @@ impl EthSpec for MainnetEthSpec { type MaxAttesterSlashingsElectra = U1; type MaxAttestationsElectra = U8; type MaxWithdrawalRequestsPerPayload = U16; + type MaxTransactionsPerInclusionList = U16; fn default_spec() -> ChainSpec { ChainSpec::mainnet() @@ -503,7 +514,8 @@ impl EthSpec for MinimalEthSpec { PendingBalanceDepositsLimit, MaxConsolidationRequestsPerPayload, MaxAttesterSlashingsElectra, - MaxAttestationsElectra + MaxAttestationsElectra, + MaxTransactionsPerInclusionList }); fn default_spec() -> ChainSpec { @@ -569,6 +581,7 @@ impl EthSpec for GnosisEthSpec { type FieldElementsPerExtBlob = U8192; type BytesPerCell = U2048; type KzgCommitmentsInclusionProofDepth = U4; + type MaxTransactionsPerInclusionList = U16; fn default_spec() -> ChainSpec { ChainSpec::gnosis() diff --git a/consensus/types/src/inclusion_list.rs b/consensus/types/src/inclusion_list.rs new file mode 100644 index 0000000000..3a8bb19970 --- /dev/null +++ b/consensus/types/src/inclusion_list.rs @@ -0,0 +1,53 @@ +use crate::test_utils::TestRandom; +use crate::{EthSpec, Hash256, Signature, Slot, Transaction}; + +use derivative::Derivative; +use serde::{Deserialize, Serialize}; +use ssz_derive::{Decode, Encode}; +use ssz_types::VariableList; +use test_random_derive::TestRandom; +use tree_hash::TreeHash; +use tree_hash_derive::TreeHash; + +#[derive( + Debug, + Clone, + Serialize, + Deserialize, + Encode, + Decode, + TreeHash, + TestRandom, + Derivative, + arbitrary::Arbitrary, +)] +#[serde(bound = "E: EthSpec")] +#[arbitrary(bound = "E: EthSpec")] +#[derivative(PartialEq, Eq, Hash(bound = "E: EthSpec"))] +pub struct InclusionList { + pub slot: Slot, + #[serde(with = "serde_utils::quoted_u64")] + pub validator_index: u64, + pub inclusion_list_committee_root: Hash256, + pub transactions: + VariableList, E::MaxTransactionsPerInclusionList>, +} + +#[derive( + Debug, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, Derivative, arbitrary::Arbitrary, +)] +#[serde(bound = "E: EthSpec")] +#[arbitrary(bound = "E: EthSpec")] +#[derivative(PartialEq, Eq, Hash(bound = "E: EthSpec"))] +pub struct SignedInclusionList { + pub message: InclusionList, + pub signature: Signature, +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::*; + + ssz_and_tree_hash_tests!(InclusionList); +} diff --git a/consensus/types/src/lib.rs b/consensus/types/src/lib.rs index eff5237834..6a3aebe724 100644 --- a/consensus/types/src/lib.rs +++ b/consensus/types/src/lib.rs @@ -48,6 +48,7 @@ pub mod fork_versioned_response; pub mod graffiti; pub mod historical_batch; pub mod historical_summary; +pub mod inclusion_list; pub mod indexed_attestation; pub mod light_client_bootstrap; pub mod light_client_finality_update; @@ -178,6 +179,7 @@ pub use crate::fork_name::{ForkName, InconsistentFork}; pub use crate::fork_versioned_response::{ForkVersionDeserialize, ForkVersionedResponse}; pub use crate::graffiti::{Graffiti, GRAFFITI_BYTES_LEN}; pub use crate::historical_batch::HistoricalBatch; +pub use crate::inclusion_list::{InclusionList, SignedInclusionList}; pub use crate::indexed_attestation::{ IndexedAttestation, IndexedAttestationBase, IndexedAttestationElectra, IndexedAttestationRef, };