feat(discv4): neighbors packet logging (#12042)

Co-authored-by: Oliver Nordbjerg <hi@notbjerg.me>
This commit is contained in:
Kufre Samuel
2024-10-29 22:24:35 +01:00
committed by GitHub
parent 82784183e7
commit 734c78fdfb
3 changed files with 14 additions and 1 deletions

1
Cargo.lock generated
View File

@ -6922,6 +6922,7 @@ dependencies = [
"discv5", "discv5",
"enr", "enr",
"generic-array", "generic-array",
"itertools 0.13.0",
"parking_lot", "parking_lot",
"rand 0.8.5", "rand 0.8.5",
"reth-ethereum-forks", "reth-ethereum-forks",

View File

@ -42,6 +42,7 @@ parking_lot.workspace = true
rand = { workspace = true, optional = true } rand = { workspace = true, optional = true }
generic-array.workspace = true generic-array.workspace = true
serde = { workspace = true, optional = true } serde = { workspace = true, optional = true }
itertools.workspace = true
[dev-dependencies] [dev-dependencies]
assert_matches.workspace = true assert_matches.workspace = true

View File

@ -38,6 +38,7 @@ use discv5::{
ConnectionDirection, ConnectionState, ConnectionDirection, ConnectionState,
}; };
use enr::Enr; use enr::Enr;
use itertools::Itertools;
use parking_lot::Mutex; use parking_lot::Mutex;
use proto::{EnrRequest, EnrResponse}; use proto::{EnrRequest, EnrResponse};
use reth_ethereum_forks::ForkId; use reth_ethereum_forks::ForkId;
@ -861,7 +862,7 @@ impl Discv4Service {
let Some(bucket) = self.kbuckets.get_bucket(&key) else { return false }; let Some(bucket) = self.kbuckets.get_bucket(&key) else { return false };
if bucket.num_entries() < MAX_NODES_PER_BUCKET / 2 { if bucket.num_entries() < MAX_NODES_PER_BUCKET / 2 {
// skip half empty bucket // skip half empty bucket
return false; return false
} }
self.remove_key(node_id, key) self.remove_key(node_id, key)
} }
@ -1406,6 +1407,16 @@ impl Discv4Service {
} }
}; };
// log the peers we discovered
trace!(target: "discv4",
target=format!("{:#?}", node_id),
peers_count=msg.nodes.len(),
peers=format!("[{:#}]", msg.nodes.iter()
.map(|node_rec| node_rec.id
).format(", ")),
"Received peers from Neighbours packet"
);
// This is the recursive lookup step where we initiate new FindNode requests for new nodes // This is the recursive lookup step where we initiate new FindNode requests for new nodes
// that were discovered. // that were discovered.
for node in msg.nodes.into_iter().map(NodeRecord::into_ipv4_mapped) { for node in msg.nodes.into_iter().map(NodeRecord::into_ipv4_mapped) {