mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
Final changes for fusaka-devnet-2 (#7655)
Closes #7467. This PR primarily addresses [the P2P changes](https://github.com/ethereum/EIPs/pull/9840) in [fusaka-devnet-2](https://fusaka-devnet-2.ethpandaops.io/). Specifically: * [the new `nfd` parameter added to the `ENR`](https://github.com/ethereum/EIPs/pull/9840) * [the modified `compute_fork_digest()` changes for every BPO fork](https://github.com/ethereum/EIPs/pull/9840) 90% of this PR was absolutely hacked together as fast as possible during the Berlinterop as fast as I could while running between Glamsterdam debates. Luckily, it seems to work. But I was unable to be as careful in avoiding bugs as I usually am. I've cleaned up the things *I remember* wanting to come back and have a closer look at. But still working on this. Progress: * [x] get it working on `fusaka-devnet-2` * [ ] [*optional* disconnect from peers with incorrect `nfd` at the fork boundary](https://github.com/ethereum/consensus-specs/pull/4407) - Can be addressed in a future PR if necessary * [x] first pass clean-up * [x] fix up all the broken tests * [x] final self-review * [x] more thorough review from people more familiar with affected code
This commit is contained in:
@@ -193,10 +193,15 @@ impl<E: EthSpec> Network<E> {
|
||||
|
||||
// set up a collection of variables accessible outside of the network crate
|
||||
// Create an ENR or load from disk if appropriate
|
||||
let next_fork_digest = ctx
|
||||
.fork_context
|
||||
.next_fork_digest()
|
||||
.unwrap_or_else(|| ctx.fork_context.current_fork_digest());
|
||||
let enr = crate::discovery::enr::build_or_load_enr::<E>(
|
||||
local_keypair.clone(),
|
||||
&config,
|
||||
&ctx.enr_fork_id,
|
||||
next_fork_digest,
|
||||
&ctx.chain_spec,
|
||||
)?;
|
||||
|
||||
@@ -280,27 +285,26 @@ impl<E: EthSpec> Network<E> {
|
||||
// Set up a scoring update interval
|
||||
let update_gossipsub_scores = tokio::time::interval(params.decay_interval);
|
||||
|
||||
let current_and_future_forks = ForkName::list_all().into_iter().filter_map(|fork| {
|
||||
if fork >= ctx.fork_context.current_fork() {
|
||||
ctx.fork_context
|
||||
.to_context_bytes(fork)
|
||||
.map(|fork_digest| (fork, fork_digest))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
let current_digest_epoch = ctx.fork_context.current_fork_epoch();
|
||||
let current_and_future_digests =
|
||||
ctx.chain_spec
|
||||
.all_digest_epochs()
|
||||
.filter_map(|digest_epoch| {
|
||||
if digest_epoch >= current_digest_epoch {
|
||||
Some((digest_epoch, ctx.fork_context.context_bytes(digest_epoch)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
|
||||
let all_topics_for_forks = current_and_future_forks
|
||||
.map(|(fork, fork_digest)| {
|
||||
let all_topics_for_digests = current_and_future_digests
|
||||
.map(|(epoch, digest)| {
|
||||
let fork = ctx.chain_spec.fork_name_at_epoch(epoch);
|
||||
all_topics_at_fork::<E>(fork, &ctx.chain_spec)
|
||||
.into_iter()
|
||||
.map(|topic| {
|
||||
Topic::new(GossipTopic::new(
|
||||
topic,
|
||||
GossipEncoding::default(),
|
||||
fork_digest,
|
||||
))
|
||||
.into()
|
||||
Topic::new(GossipTopic::new(topic, GossipEncoding::default(), digest))
|
||||
.into()
|
||||
})
|
||||
.collect::<Vec<TopicHash>>()
|
||||
})
|
||||
@@ -308,7 +312,7 @@ impl<E: EthSpec> Network<E> {
|
||||
|
||||
// For simplicity find the fork with the most individual topics and assume all forks
|
||||
// have the same topic count
|
||||
let max_topics_at_any_fork = all_topics_for_forks
|
||||
let max_topics_at_any_fork = all_topics_for_digests
|
||||
.iter()
|
||||
.map(|topics| topics.len())
|
||||
.max()
|
||||
@@ -359,7 +363,7 @@ impl<E: EthSpec> Network<E> {
|
||||
// If we are using metrics, then register which topics we want to make sure to keep
|
||||
// track of
|
||||
if ctx.libp2p_registry.is_some() {
|
||||
for topics in all_topics_for_forks {
|
||||
for topics in all_topics_for_digests {
|
||||
gossipsub.register_topics_for_metrics(topics);
|
||||
}
|
||||
}
|
||||
@@ -1347,6 +1351,12 @@ impl<E: EthSpec> Network<E> {
|
||||
self.enr_fork_id = enr_fork_id;
|
||||
}
|
||||
|
||||
pub fn update_nfd(&mut self, nfd: [u8; 4]) {
|
||||
if let Err(e) = self.discovery_mut().update_enr_nfd(nfd) {
|
||||
crit!(error = e, "Could not update nfd in ENR");
|
||||
}
|
||||
}
|
||||
|
||||
/* Private internal functions */
|
||||
|
||||
/// Updates the current meta data of the node to match the local ENR.
|
||||
|
||||
Reference in New Issue
Block a user