From f31c0b69e3a49d4b1111bc780d3201ce055f5a53 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Sat, 1 Feb 2025 23:54:50 +0300 Subject: [PATCH] add focil epoch activation --- beacon_node/beacon_processor/src/lib.rs | 20 +++++++-- .../lighthouse_network/src/types/pubsub.rs | 31 ++++++++++--- .../src/network_beacon_processor/mod.rs | 24 +++++++++++ beacon_node/network/src/router.rs | 16 ++++++- consensus/types/src/chain_spec.rs | 43 +++++++++++++++++++ 5 files changed, 123 insertions(+), 11 deletions(-) diff --git a/beacon_node/beacon_processor/src/lib.rs b/beacon_node/beacon_processor/src/lib.rs index 2a69b04c91..d83426a274 100644 --- a/beacon_node/beacon_processor/src/lib.rs +++ b/beacon_node/beacon_processor/src/lib.rs @@ -136,6 +136,7 @@ pub struct BeaconProcessorQueueLengths { lc_optimistic_update_queue: usize, lc_finality_update_queue: usize, lc_update_range_queue: usize, + gossip_inclusion_list_queue: usize, api_request_p0_queue: usize, api_request_p1_queue: usize, } @@ -204,6 +205,8 @@ impl BeaconProcessorQueueLengths { lc_optimistic_update_queue: 512, lc_finality_update_queue: 512, lc_update_range_queue: 512, + // TODO(focil) pick proper values + gossip_inclusion_list_queue: 64, api_request_p0_queue: 1024, api_request_p1_queue: 1024, }) @@ -625,6 +628,7 @@ pub enum Work { LightClientOptimisticUpdateRequest(BlockingFn), LightClientFinalityUpdateRequest(BlockingFn), LightClientUpdatesByRangeRequest(BlockingFn), + GossipInclusionList(BlockingFn), ApiRequestP0(BlockingOrAsync), ApiRequestP1(BlockingOrAsync), } @@ -677,6 +681,7 @@ pub enum WorkType { LightClientOptimisticUpdateRequest, LightClientFinalityUpdateRequest, LightClientUpdatesByRangeRequest, + GossipInclusionList, ApiRequestP0, ApiRequestP1, } @@ -734,6 +739,7 @@ impl Work { Work::UnknownLightClientOptimisticUpdate { .. } => { WorkType::UnknownLightClientOptimisticUpdate } + Work::GossipInclusionList { .. } => WorkType::GossipInclusionList, Work::ApiRequestP0 { .. } => WorkType::ApiRequestP0, Work::ApiRequestP1 { .. } => WorkType::ApiRequestP1, } @@ -909,6 +915,8 @@ impl BeaconProcessor { let mut lc_finality_update_queue = FifoQueue::new(queue_lengths.lc_finality_update_queue); let mut lc_update_range_queue = FifoQueue::new(queue_lengths.lc_update_range_queue); + let mut gossip_inclusion_list_queue = + FifoQueue::new(queue_lengths.gossip_inclusion_list_queue); let mut api_request_p0_queue = FifoQueue::new(queue_lengths.api_request_p0_queue); let mut api_request_p1_queue = FifoQueue::new(queue_lengths.api_request_p1_queue); @@ -1180,6 +1188,9 @@ impl BeaconProcessor { None } } + // TODO(focil) figure out priority and maybe introduce batching + } else if let Some(item) = gossip_inclusion_list_queue.pop() { + Some(item) // Check sync committee messages after attestations as their rewards are lesser // and they don't influence fork choice. } else if let Some(item) = sync_contribution_queue.pop() { @@ -1412,6 +1423,9 @@ impl BeaconProcessor { Work::UnknownBlockSamplingRequest { .. } => { unknown_block_sampling_request_queue.push(work, work_id, &self.log) } + Work::GossipInclusionList { .. } => { + gossip_inclusion_list_queue.push(work, work_id, &self.log) + } Work::ApiRequestP0 { .. } => { api_request_p0_queue.push(work, work_id, &self.log) } @@ -1479,6 +1493,7 @@ impl BeaconProcessor { WorkType::LightClientFinalityUpdateRequest => { lc_finality_update_queue.len() } + WorkType::GossipInclusionList => gossip_inclusion_list_queue.len(), WorkType::LightClientUpdatesByRangeRequest => lc_update_range_queue.len(), WorkType::ApiRequestP0 => api_request_p0_queue.len(), WorkType::ApiRequestP1 => api_request_p1_queue.len(), @@ -1633,9 +1648,8 @@ impl BeaconProcessor { | Work::LightClientBootstrapRequest(process_fn) | Work::LightClientOptimisticUpdateRequest(process_fn) | Work::LightClientFinalityUpdateRequest(process_fn) - | Work::LightClientUpdatesByRangeRequest(process_fn) => { - task_spawner.spawn_blocking(process_fn) - } + | Work::LightClientUpdatesByRangeRequest(process_fn) + | Work::GossipInclusionList(process_fn) => task_spawner.spawn_blocking(process_fn), }; } } diff --git a/beacon_node/lighthouse_network/src/types/pubsub.rs b/beacon_node/lighthouse_network/src/types/pubsub.rs index 176b904179..e61ab1bf2d 100644 --- a/beacon_node/lighthouse_network/src/types/pubsub.rs +++ b/beacon_node/lighthouse_network/src/types/pubsub.rs @@ -9,12 +9,13 @@ use std::sync::Arc; use types::{ Attestation, AttestationBase, AttestationElectra, AttesterSlashing, AttesterSlashingBase, AttesterSlashingElectra, BlobSidecar, DataColumnSidecar, DataColumnSubnetId, EthSpec, - ForkContext, ForkName, InclusionList, LightClientFinalityUpdate, LightClientOptimisticUpdate, + ForkContext, ForkName, LightClientFinalityUpdate, LightClientOptimisticUpdate, ProposerSlashing, SignedAggregateAndProof, SignedAggregateAndProofBase, SignedAggregateAndProofElectra, SignedBeaconBlock, SignedBeaconBlockAltair, SignedBeaconBlockBase, SignedBeaconBlockBellatrix, SignedBeaconBlockCapella, SignedBeaconBlockDeneb, SignedBeaconBlockElectra, SignedBlsToExecutionChange, - SignedContributionAndProof, SignedVoluntaryExit, SubnetId, SyncCommitteeMessage, SyncSubnetId, + SignedContributionAndProof, SignedInclusionList, SignedVoluntaryExit, SubnetId, + SyncCommitteeMessage, SyncSubnetId, }; #[derive(Debug, Clone, PartialEq)] @@ -46,7 +47,7 @@ pub enum PubsubMessage { /// Gossipsub message providing notification of a light client optimistic update. LightClientOptimisticUpdate(Box>), /// Gossipsub message providing notification of an inclusion list. - InclusionList(Box>), + InclusionList(Box>), } // Implements the `DataTransform` trait of gossipsub to employ snappy compression @@ -394,9 +395,27 @@ impl PubsubMessage { ))) } GossipKind::InclusionList => { - let il = - InclusionList::from_ssz_bytes(data).map_err(|e| format!("{:?}", e))?; - Ok(PubsubMessage::InclusionList(Box::new(il))) + match fork_context.from_context_bytes(gossip_topic.fork_digest) { + Some(fork) if fork.electra_enabled() => { + let il = SignedInclusionList::from_ssz_bytes(data) + .map_err(|e| format!("{:?}", e))?; + let focil_enabled = fork_context.spec.is_focil_enabled_for_epoch( + il.message.slot.epoch(E::slots_per_epoch()), + ); + if focil_enabled { + Ok(PubsubMessage::InclusionList(Box::new(il))) + } else { + Err(format!( + "inclusion_List topic invalid for given fork digest {:?}", + gossip_topic.fork_digest + )) + } + } + Some(_) | None => Err(format!( + "inclusion_List topic invalid for given fork digest {:?}", + gossip_topic.fork_digest + )), + } } } } diff --git a/beacon_node/network/src/network_beacon_processor/mod.rs b/beacon_node/network/src/network_beacon_processor/mod.rs index d81d964e7c..49564657d1 100644 --- a/beacon_node/network/src/network_beacon_processor/mod.rs +++ b/beacon_node/network/src/network_beacon_processor/mod.rs @@ -298,6 +298,30 @@ impl NetworkBeaconProcessor { }) } + /// Create a new `Work` event for some inclusion list. + pub fn send_gossip_inclusion_list( + self: &Arc, + message_id: MessageId, + peer_id: PeerId, + signed_inclusion_list: SignedInclusionList, + seen_timestamp: Duration, + ) -> Result<(), Error> { + let processor = self.clone(); + let process_fn = move || { + processor.process_gossip_inclusion_list( + message_id, + peer_id, + signed_inclusion_list, + seen_timestamp, + ) + }; + + self.try_send(BeaconWorkEvent { + drop_during_sync: true, + work: Work::GossipInclusionList(Box::new(process_fn)), + }) + } + /// Create a new `Work` event for some sync committee contribution. pub fn send_gossip_sync_contribution( self: &Arc, diff --git a/beacon_node/network/src/router.rs b/beacon_node/network/src/router.rs index 88dd33bd4d..76291f378f 100644 --- a/beacon_node/network/src/router.rs +++ b/beacon_node/network/src/router.rs @@ -541,8 +541,20 @@ impl Router { bls_to_execution_change, ), ), - PubsubMessage::InclusionList(_il) => { - // TODO(focil) + PubsubMessage::InclusionList(inclusion_list) => { + trace!( + self.log, + "Received inclusion list"; + "peer_id" => %peer_id + ); + self.handle_beacon_processor_send_result( + self.network_beacon_processor.send_gossip_inclusion_list( + message_id, + peer_id, + *inclusion_list, + timestamp_now(), + ), + ) } } } diff --git a/consensus/types/src/chain_spec.rs b/consensus/types/src/chain_spec.rs index 07529ad265..1b0ab7bbfd 100644 --- a/consensus/types/src/chain_spec.rs +++ b/consensus/types/src/chain_spec.rs @@ -208,6 +208,11 @@ pub struct ChainSpec { pub number_of_columns: usize, pub samples_per_slot: u64, + /* + * FOCIL params + */ + pub eip7805_fork_epoch: Option, + /* * Networking */ @@ -439,6 +444,20 @@ impl ChainSpec { }) } + /// Returns true if the given epoch is greater than or equal to the `EIP7805_FORK_EPOCH`. + pub fn is_focil_enabled_for_epoch(&self, block_epoch: Epoch) -> bool { + self.eip7805_fork_epoch.map_or(false, |eip7805_fork_epoch| { + block_epoch >= eip7805_fork_epoch + }) + } + + /// Returns true if `EIP7805_FORK_EPOCH` is set and is not set to `FAR_FUTURE_EPOCH`. + pub fn is_focil_scheduled(&self) -> bool { + self.eip7805_fork_epoch.map_or(false, |eip7805_fork_epoch| { + eip7805_fork_epoch != self.far_future_epoch + }) + } + /// Returns a full `Fork` struct for a given epoch. pub fn fork_at_epoch(&self, epoch: Epoch) -> Fork { let current_fork_name = self.fork_name_at_epoch(epoch); @@ -827,6 +846,11 @@ impl ChainSpec { number_of_columns: 128, samples_per_slot: 8, + /* + * FOCIL params + */ + eip7805_fork_epoch: None, + /* * Network specific */ @@ -935,6 +959,8 @@ impl ChainSpec { .expect("calculation does not overflow"), // PeerDAS eip7594_fork_epoch: None, + // FOCIL + eip7805_fork_epoch: None, // Other network_id: 2, // lighthouse testnet network id deposit_chain_id: 5, @@ -1151,6 +1177,12 @@ impl ChainSpec { data_column_sidecar_subnet_count: 128, number_of_columns: 128, samples_per_slot: 8, + + /* + * FOCIL params + */ + eip7805_fork_epoch: None, + /* * Network specific */ @@ -1282,6 +1314,11 @@ pub struct Config { #[serde(deserialize_with = "deserialize_fork_epoch")] pub eip7594_fork_epoch: Option>, + #[serde(default)] + #[serde(serialize_with = "serialize_fork_epoch")] + #[serde(deserialize_with = "deserialize_fork_epoch")] + pub eip7805_fork_epoch: Option>, + #[serde(with = "serde_utils::quoted_u64")] seconds_per_slot: u64, #[serde(with = "serde_utils::quoted_u64")] @@ -1681,6 +1718,10 @@ impl Config { .eip7594_fork_epoch .map(|epoch| MaybeQuoted { value: epoch }), + eip7805_fork_epoch: spec + .eip7805_fork_epoch + .map(|epoch| MaybeQuoted { value: epoch }), + seconds_per_slot: spec.seconds_per_slot, seconds_per_eth1_block: spec.seconds_per_eth1_block, min_validator_withdrawability_delay: spec.min_validator_withdrawability_delay, @@ -1761,6 +1802,7 @@ impl Config { electra_fork_epoch, electra_fork_version, eip7594_fork_epoch, + eip7805_fork_epoch, seconds_per_slot, seconds_per_eth1_block, min_validator_withdrawability_delay, @@ -1824,6 +1866,7 @@ impl Config { electra_fork_epoch: electra_fork_epoch.map(|q| q.value), electra_fork_version, eip7594_fork_epoch: eip7594_fork_epoch.map(|q| q.value), + eip7805_fork_epoch: eip7805_fork_epoch.map(|q| q.value), seconds_per_slot, seconds_per_eth1_block, min_validator_withdrawability_delay,