Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/net/network/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,10 @@ impl<N: NetworkPrimitives> NetworkManager<N> {
self.swarm.state_mut().update_fork_id(transition.current);
}
}
NetworkHandleMessage::SetForkFilter { fork_filter } => {
let fork_id = self.swarm.sessions_mut().set_fork_filter(fork_filter);
self.swarm.state_mut().update_fork_id(fork_id);
}
NetworkHandleMessage::GetPeerInfos(tx) => {
let _ = tx.send(self.get_peer_infos());
}
Expand Down
24 changes: 23 additions & 1 deletion crates/net/network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use reth_eth_wire::{
BlockRangeUpdate, BroadcastPoolTransactions, DisconnectReason, EthNetworkPrimitives,
NetworkPrimitives, NewPooledTransactionHashes, SharedTransactions,
};
use reth_ethereum_forks::Head;
use reth_ethereum_forks::{ForkFilter, Head};
use reth_network_api::{
events::{NetworkPeersEvents, PeerEvent, PeerEventStream},
test_utils::{PeersHandle, PeersHandleProvider},
Expand Down Expand Up @@ -112,6 +112,18 @@ impl<N: NetworkPrimitives> NetworkHandle<N> {
self.send_message(NetworkHandleMessage::StatusUpdate { head });
}

/// Replaces the network's active [`ForkFilter`] with `fork_filter`, re-deriving the advertised
/// [`ForkId`](reth_ethereum_forks::ForkId) for future handshakes and updating the discovery
/// ENR entry.
///
/// This lets a running node adopt a fork schedule that changed at runtime (e.g. an
/// L1-signalled upgrade) without a restart. The caller must build `fork_filter` from the
/// updated chain spec advanced to the node's current head, and should do so before the fork's
/// activation timestamp so the node announces the upcoming fork ahead of time.
pub fn set_fork_filter(&self, fork_filter: ForkFilter) {
self.send_message(NetworkHandleMessage::SetForkFilter { fork_filter });
}

/// Announce a block over devp2p
///
/// Caution: in `PoS` this is a noop because new blocks are no longer announced over devp2p.
Expand Down Expand Up @@ -497,6 +509,11 @@ impl<N: NetworkPrimitives> NetworkSyncUpdater for NetworkHandle<N> {
fn update_block_range(&self, update: reth_eth_wire::BlockRangeUpdate) {
self.send_message(NetworkHandleMessage::InternalBlockRangeUpdate(update));
}

/// Replaces the active fork filter to adopt a runtime fork-schedule change.
fn set_fork_filter(&self, fork_filter: ForkFilter) {
self.send_message(NetworkHandleMessage::SetForkFilter { fork_filter });
}
}

impl<N: NetworkPrimitives> BlockDownloaderProvider for NetworkHandle<N> {
Expand Down Expand Up @@ -614,6 +631,11 @@ pub(crate) enum NetworkHandleMessage<N: NetworkPrimitives = EthNetworkPrimitives
/// The head status to apply.
head: Head,
},
/// Replaces the active fork filter to adopt a runtime fork-schedule change.
SetForkFilter {
/// The new fork filter, built from the updated chain spec advanced to the current head.
fork_filter: ForkFilter,
},
/// Retrieves the current status via a oneshot sender.
GetStatus(oneshot::Sender<NetworkStatus>),
/// Gets `PeerInfo` for the specified peer IDs.
Expand Down
17 changes: 17 additions & 0 deletions crates/net/network/src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,23 @@ impl<N: NetworkPrimitives> SessionManager<N> {
transition
}

/// Replaces the active [`ForkFilter`] with a newly derived one and returns the resulting
/// [`ForkId`].
///
/// This is used to adopt a fork schedule that changed at runtime (e.g. an L1-signalled
/// upgrade) without restarting the node. The caller is expected to build `fork_filter` from
/// the updated chain spec already advanced to the node's current head, so that
/// [`ForkFilter::current`] reflects the correct [`ForkId`] immediately.
///
/// Every subsequent handshake clones this filter and advertises the returned [`ForkId`], so
/// the node's advertised fork identity stays aligned with the rules it now enforces. Existing
/// active sessions are not revalidated here; see [`SessionManager::active_sessions`].
pub(crate) fn set_fork_filter(&mut self, fork_filter: ForkFilter) -> ForkId {
self.fork_filter = fork_filter;
self.status.forkid = self.fork_filter.current();
self.status.forkid
}

/// An incoming TCP connection was received. This starts the authentication process to turn this
/// stream into an active peer session.
///
Expand Down
13 changes: 12 additions & 1 deletion crates/net/p2p/src/sync.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Traits used when interacting with the sync status of the network.

use alloy_eips::eip2124::Head;
use alloy_eips::eip2124::{ForkFilter, Head};
use reth_eth_wire_types::BlockRangeUpdate;

/// A type that provides information about whether the node is currently syncing and the network is
Expand Down Expand Up @@ -31,6 +31,17 @@ pub trait NetworkSyncUpdater: std::fmt::Debug + Send + Sync + 'static {

/// Updates the advertised block range.
fn update_block_range(&self, update: BlockRangeUpdate);

/// Replaces the node's active [`ForkFilter`] to adopt a fork schedule that changed at runtime
/// (e.g. an L1-signalled upgrade) without a restart.
///
/// The caller must build `fork_filter` from the updated chain spec advanced to the node's
/// current head, and should do so before the fork's activation timestamp so the node
/// announces the upcoming fork ahead of time. Defaults to a no-op for updaters that do not
/// track a fork filter.
fn set_fork_filter(&self, fork_filter: ForkFilter) {
let _ = fork_filter;
}
}

/// The state the network is currently in when it comes to synchronization.
Expand Down
Loading