feat: add PeersInfo::local_enr (#7539)

This commit is contained in:
Matthias Seitz
2024-04-10 16:38:57 +02:00
committed by GitHub
parent e50f942d47
commit 4b84b99351
5 changed files with 29 additions and 2 deletions

View File

@ -17,11 +17,13 @@ reth-primitives.workspace = true
reth-eth-wire.workspace = true
reth-rpc-types.workspace = true
reth-discv4.workspace = true
# io
serde = { workspace = true, features = ["derive"], optional = true }
# eth
enr = { workspace = true, default-features = false, features = ["rust-secp256k1"] }
# misc
thiserror.workspace = true
serde = { workspace = true, features = ["derive"], optional = true }
tokio = { workspace = true, features = ["sync"] }
[features]

View File

@ -57,6 +57,9 @@ pub trait PeersInfo: Send + Sync {
/// Returns the Ethereum Node Record of the node.
fn local_node_record(&self) -> NodeRecord;
/// Returns the local ENR of the node.
fn local_enr(&self) -> enr::Enr<enr::secp256k1::SecretKey>;
}
/// Provides an API for managing the peers of the network.

View File

@ -7,6 +7,7 @@ use crate::{
NetworkError, NetworkInfo, PeerInfo, PeerKind, Peers, PeersInfo, Reputation,
ReputationChangeKind,
};
use enr::{secp256k1::SecretKey, Enr};
use reth_discv4::DEFAULT_DISCOVERY_PORT;
use reth_eth_wire::{DisconnectReason, ProtocolVersion};
use reth_primitives::{Chain, NodeRecord, PeerId};
@ -60,6 +61,11 @@ impl PeersInfo for NoopNetwork {
fn local_node_record(&self) -> NodeRecord {
NodeRecord::new(self.local_addr(), PeerId::random())
}
fn local_enr(&self) -> Enr<SecretKey> {
let sk = SecretKey::from_slice(&[0xcd; 32]).unwrap();
Enr::builder().build(&sk).unwrap()
}
}
impl Peers for NoopNetwork {