reth_discv5/
network_stack_id.rs

1//! Keys of ENR [`ForkId`](reth_ethereum_forks::ForkId) kv-pair. Identifies which network stack a
2//! node belongs to.
3
4use reth_chainspec::EthChainSpec;
5
6/// Identifies which Ethereum network stack a node belongs to, on the discovery network.
7#[derive(Debug)]
8pub struct NetworkStackId;
9
10impl NetworkStackId {
11    /// ENR fork ID kv-pair key, for an Ethereum L1 EL node.
12    pub const ETH: &'static [u8] = b"eth";
13
14    /// ENR fork ID kv-pair key, for an Ethereum L1 CL node.
15    pub const ETH2: &'static [u8] = b"eth2";
16
17    /// ENR fork ID kv-pair key, for an Optimism EL node.
18    pub const OPEL: &'static [u8] = b"opel";
19
20    /// ENR fork ID kv-pair key, for an Optimism CL node.
21    pub const OPSTACK: &'static [u8] = b"opstack";
22
23    /// Returns the [`NetworkStackId`] that matches the given chain spec.
24    pub fn id(chain: impl EthChainSpec) -> Option<&'static [u8]> {
25        if chain.is_optimism() {
26            return Some(Self::OPEL)
27        } else if chain.is_ethereum() {
28            return Some(Self::ETH)
29        }
30
31        None
32    }
33}