From 29097d3dae02dd8c69382e2ecec2a60c2050e722 Mon Sep 17 00:00:00 2001 From: ethDreamer <37123614+ethDreamer@users.noreply.github.com> Date: Tue, 28 Sep 2021 18:09:08 -0500 Subject: [PATCH] Fork boundary fix (#2646) * Fixed Gossip Topics on Fork Boundary --- beacon_node/network/src/service.rs | 54 ++++++++++++++++-------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/beacon_node/network/src/service.rs b/beacon_node/network/src/service.rs index 05fccbba41..937fe2b5de 100644 --- a/beacon_node/network/src/service.rs +++ b/beacon_node/network/src/service.rs @@ -25,8 +25,8 @@ use task_executor::ShutdownReason; use tokio::sync::mpsc; use tokio::time::Sleep; use types::{ - ChainSpec, EthSpec, ForkContext, ForkName, RelativeEpoch, Slot, SubnetId, - SyncCommitteeSubscription, SyncSubnetId, Unsigned, ValidatorSubscription, + ChainSpec, EthSpec, ForkContext, RelativeEpoch, Slot, SubnetId, SyncCommitteeSubscription, + SyncSubnetId, Unsigned, ValidatorSubscription, }; mod tests; @@ -281,32 +281,34 @@ impl NetworkService { pub fn required_gossip_fork_digests(&self) -> Vec<[u8; 4]> { let fork_context = &self.fork_context; let spec = &self.beacon_chain.spec; - match fork_context.current_fork() { - ForkName::Base => { - // If we are SUBSCRIBE_DELAY_SLOTS before the fork slot, subscribe only to Base, - // else subscribe to Base and Altair. - let current_slot = self.beacon_chain.slot().unwrap_or(spec.genesis_slot); - match spec.next_fork_epoch::(current_slot) { - Some((_, fork_epoch)) => { - if current_slot.saturating_add(Slot::new(SUBSCRIBE_DELAY_SLOTS)) - >= fork_epoch.start_slot(T::EthSpec::slots_per_epoch()) - { - fork_context.all_fork_digests() - } else { - vec![fork_context.genesis_context_bytes()] - } - } - None => vec![fork_context.genesis_context_bytes()], - } + let current_slot = self.beacon_chain.slot().unwrap_or(spec.genesis_slot); + let current_fork = fork_context.current_fork(); + + let mut result = vec![fork_context + .to_context_bytes(current_fork) + .unwrap_or_else(|| { + panic!( + "{} fork bytes should exist as it's initialized in ForkContext", + current_fork + ) + })]; + + if let Some((next_fork, fork_epoch)) = spec.next_fork_epoch::(current_slot) { + if current_slot.saturating_add(Slot::new(SUBSCRIBE_DELAY_SLOTS)) + >= fork_epoch.start_slot(T::EthSpec::slots_per_epoch()) + { + let next_fork_context_bytes = + fork_context.to_context_bytes(next_fork).unwrap_or_else(|| { + panic!( + "context bytes should exist as spec.next_fork_epoch({}) returned Some({})", + current_slot, next_fork + ) + }); + result.push(next_fork_context_bytes); } - ForkName::Altair => vec![fork_context - .to_context_bytes(ForkName::Altair) - .expect("Altair fork bytes should exist as it's initialized in ForkContext")], - // TODO: check this.. what even is this? - ForkName::Merge => vec![fork_context - .to_context_bytes(ForkName::Merge) - .expect("Merge fork bytes should exist as it's initialized in ForkContext")], } + + result } }