chore(disc): update discv5 and tracing (#408)

* chore(disc): update discv5 and tracing

* ignore
This commit is contained in:
Matthias Seitz
2022-12-13 18:12:59 +01:00
committed by GitHub
parent c6d38f0f6a
commit 95d99c4317
4 changed files with 14 additions and 16 deletions

4
Cargo.lock generated
View File

@ -987,7 +987,7 @@ dependencies = [
[[package]] [[package]]
name = "discv5" name = "discv5"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/sigp/discv5#46fb65ce6dfead94bcdd63b7c27c0adfae10e269" source = "git+https://github.com/sigp/discv5#d31e62e3a6973d94be7e9d02f812a43e2c9d9749"
dependencies = [ dependencies = [
"aes 0.7.5", "aes 0.7.5",
"aes-gcm", "aes-gcm",
@ -3267,12 +3267,12 @@ dependencies = [
"reth-primitives", "reth-primitives",
"reth-rlp", "reth-rlp",
"reth-rlp-derive", "reth-rlp-derive",
"reth-tracing",
"secp256k1", "secp256k1",
"thiserror", "thiserror",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
"tracing", "tracing",
"tracing-test",
"url", "url",
] ]

View File

@ -40,7 +40,7 @@ rand = { version = "0.8", optional = true }
[dev-dependencies] [dev-dependencies]
rand = "0.8" rand = "0.8"
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
tracing-test = "0.2" reth-tracing = { path = "../../tracing" }
[features] [features]
mock = ["rand"] mock = ["rand"]

View File

@ -50,7 +50,7 @@ use tokio::{
time::Interval, time::Interval,
}; };
use tokio_stream::{wrappers::ReceiverStream, Stream, StreamExt}; use tokio_stream::{wrappers::ReceiverStream, Stream, StreamExt};
use tracing::{debug, instrument, trace, warn}; use tracing::{debug, trace, warn};
pub mod bootnodes; pub mod bootnodes;
pub mod error; pub mod error;
@ -455,9 +455,8 @@ impl Discv4Service {
/// ///
/// This takes an optional Sender through which all successfully discovered nodes are sent once /// This takes an optional Sender through which all successfully discovered nodes are sent once
/// the request has finished. /// the request has finished.
#[instrument(skip_all, fields(?target), target = "net::discv4")]
fn lookup_with(&mut self, target: PeerId, tx: Option<NodeRecordSender>) { fn lookup_with(&mut self, target: PeerId, tx: Option<NodeRecordSender>) {
trace!("Starting lookup"); trace!(target : "net::discv4", ?target, "Starting lookup");
let key = kad_key(target); let key = kad_key(target);
// Start a lookup context with the 16 (MAX_NODES_PER_BUCKET) closest nodes // Start a lookup context with the 16 (MAX_NODES_PER_BUCKET) closest nodes
@ -473,7 +472,7 @@ impl Discv4Service {
// From those 16, pick the 3 closest to start the lookup. // From those 16, pick the 3 closest to start the lookup.
let closest = ctx.closest(ALPHA); let closest = ctx.closest(ALPHA);
trace!(num = closest.len(), "Start lookup closest nodes"); trace!(target : "net::discv4", ?target, num = closest.len(), "Start lookup closest nodes");
for node in closest { for node in closest {
self.find_node(&node, ctx.clone()); self.find_node(&node, ctx.clone());
@ -526,7 +525,6 @@ impl Discv4Service {
} }
let key = kad_key(record.id); let key = kad_key(record.id);
let entry = NodeEntry { record, last_seen: Instant::now() }; let entry = NodeEntry { record, last_seen: Instant::now() };
match self.kbuckets.insert_or_update( match self.kbuckets.insert_or_update(
&key, &key,
entry, entry,
@ -536,14 +534,14 @@ impl Discv4Service {
}, },
) { ) {
InsertResult::Inserted => { InsertResult::Inserted => {
trace!( target : "net::disc",?record, "inserted new record to table"); debug!(target : "net::disc",?record, "inserted new record to table");
self.notify(TableUpdate::Added(record)); self.notify(TableUpdate::Added(record));
} }
InsertResult::ValueUpdated { .. } | InsertResult::Updated { .. } => { InsertResult::ValueUpdated { .. } | InsertResult::Updated { .. } => {
trace!(target : "net::disc",?record, "updated record"); trace!(target : "net::disc",?record, "updated record");
} }
res => { res => {
debug!(target : "net::disc",?record, ?res, "failed to insert"); warn!(target : "net::disc",?record, ?res, "failed to insert");
} }
} }
} }
@ -1292,7 +1290,6 @@ mod tests {
bootnodes::mainnet_nodes, bootnodes::mainnet_nodes,
mock::{create_discv4, create_discv4_with_config}, mock::{create_discv4, create_discv4_with_config},
}; };
use tracing_test::traced_test;
#[test] #[test]
fn test_local_rotator() { fn test_local_rotator() {
@ -1314,7 +1311,6 @@ mod tests {
} }
#[tokio::test] #[tokio::test]
#[traced_test]
async fn test_pending_ping() { async fn test_pending_ping() {
let (_, mut service) = create_discv4().await; let (_, mut service) = create_discv4().await;
@ -1329,9 +1325,10 @@ mod tests {
} }
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
#[traced_test]
#[ignore] #[ignore]
async fn test_lookup() { async fn test_lookup() {
reth_tracing::init_tracing();
let all_nodes = mainnet_nodes(); let all_nodes = mainnet_nodes();
let config = Discv4Config::builder().add_boot_nodes(all_nodes).build(); let config = Discv4Config::builder().add_boot_nodes(all_nodes).build();
let (_discv4, mut service) = create_discv4_with_config(config).await; let (_discv4, mut service) = create_discv4_with_config(config).await;
@ -1356,8 +1353,9 @@ mod tests {
} }
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
#[traced_test]
async fn test_service_commands() { async fn test_service_commands() {
reth_tracing::init_tracing();
let config = Discv4Config::builder().build(); let config = Discv4Config::builder().build();
let (discv4, mut service) = create_discv4_with_config(config).await; let (discv4, mut service) = create_discv4_with_config(config).await;

View File

@ -273,13 +273,13 @@ mod tests {
use super::*; use super::*;
use crate::{Discv4Event, PingReason}; use crate::{Discv4Event, PingReason};
use std::net::{IpAddr, Ipv4Addr}; use std::net::{IpAddr, Ipv4Addr};
use tracing_test::traced_test;
/// This test creates two local UDP sockets. The mocked discovery service responds to specific /// This test creates two local UDP sockets. The mocked discovery service responds to specific
/// messages and we check the actual service receives answers /// messages and we check the actual service receives answers
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
#[traced_test]
async fn can_mock_discovery() { async fn can_mock_discovery() {
reth_tracing::init_tracing();
let mut rng = thread_rng(); let mut rng = thread_rng();
let (_, mut service) = create_discv4().await; let (_, mut service) = create_discv4().await;
let (mut mockv4, mut cmd) = MockDiscovery::new().await.unwrap(); let (mut mockv4, mut cmd) = MockDiscovery::new().await.unwrap();