Fork boundary fix (#2646)

* Fixed Gossip Topics on Fork Boundary
This commit is contained in:
ethDreamer
2021-09-28 18:09:08 -05:00
committed by GitHub
parent e559bd9f59
commit 29097d3dae

View File

@@ -25,8 +25,8 @@ use task_executor::ShutdownReason;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tokio::time::Sleep; use tokio::time::Sleep;
use types::{ use types::{
ChainSpec, EthSpec, ForkContext, ForkName, RelativeEpoch, Slot, SubnetId, ChainSpec, EthSpec, ForkContext, RelativeEpoch, Slot, SubnetId, SyncCommitteeSubscription,
SyncCommitteeSubscription, SyncSubnetId, Unsigned, ValidatorSubscription, SyncSubnetId, Unsigned, ValidatorSubscription,
}; };
mod tests; mod tests;
@@ -281,32 +281,34 @@ impl<T: BeaconChainTypes> NetworkService<T> {
pub fn required_gossip_fork_digests(&self) -> Vec<[u8; 4]> { pub fn required_gossip_fork_digests(&self) -> Vec<[u8; 4]> {
let fork_context = &self.fork_context; let fork_context = &self.fork_context;
let spec = &self.beacon_chain.spec; let spec = &self.beacon_chain.spec;
match fork_context.current_fork() { let current_slot = self.beacon_chain.slot().unwrap_or(spec.genesis_slot);
ForkName::Base => { let current_fork = fork_context.current_fork();
// If we are SUBSCRIBE_DELAY_SLOTS before the fork slot, subscribe only to Base,
// else subscribe to Base and Altair. let mut result = vec![fork_context
let current_slot = self.beacon_chain.slot().unwrap_or(spec.genesis_slot); .to_context_bytes(current_fork)
match spec.next_fork_epoch::<T::EthSpec>(current_slot) { .unwrap_or_else(|| {
Some((_, fork_epoch)) => { panic!(
if current_slot.saturating_add(Slot::new(SUBSCRIBE_DELAY_SLOTS)) "{} fork bytes should exist as it's initialized in ForkContext",
>= fork_epoch.start_slot(T::EthSpec::slots_per_epoch()) current_fork
{ )
fork_context.all_fork_digests() })];
} else {
vec![fork_context.genesis_context_bytes()] if let Some((next_fork, fork_epoch)) = spec.next_fork_epoch::<T::EthSpec>(current_slot) {
} if current_slot.saturating_add(Slot::new(SUBSCRIBE_DELAY_SLOTS))
} >= fork_epoch.start_slot(T::EthSpec::slots_per_epoch())
None => vec![fork_context.genesis_context_bytes()], {
} 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
} }
} }