Skip to content

refactor(l1): discovery service #1768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Jan 28, 2025
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7d023c2
refactor: initial removal of discovery code from net move discovery t…
MarcosNicolau Jan 21, 2025
dca6bea
refactor: avoid cloning self and move message handling to new function
MarcosNicolau Jan 22, 2025
7c1bbf7
fix: ping and pong send tcp_ports from node
MarcosNicolau Jan 22, 2025
5038e16
refactor: messages errors type and remove old todos
MarcosNicolau Jan 22, 2025
d9fbd93
refactor: lookups
MarcosNicolau Jan 22, 2025
2540d39
refactor: merge with main
MarcosNicolau Jan 22, 2025
b2dbfa6
Merge branch 'refactor/discovery-v2' into refactor/discovery
MarcosNicolau Jan 23, 2025
e3e68a4
chore: remove old files from merge
MarcosNicolau Jan 23, 2025
a98e9f9
Merge branch 'main' into refactor/discovery
MarcosNicolau Jan 23, 2025
4cc7a84
refactor: enr messages
MarcosNicolau Jan 23, 2025
4f4bc6a
refactor: lookups
MarcosNicolau Jan 23, 2025
7c59825
chore: address clippy warnings
MarcosNicolau Jan 23, 2025
381ba16
refactor: remove uwnrap on node record decoding
MarcosNicolau Jan 23, 2025
4c233ed
refactor: proper erro handling in network start
MarcosNicolau Jan 23, 2025
bd1330c
refactor: better debug on handle message errors
MarcosNicolau Jan 23, 2025
7f82351
refactor: pass node_id directly instead of msg
MarcosNicolau Jan 23, 2025
9f871bb
refactor: remove usage of discv max packet size in rlpx
MarcosNicolau Jan 23, 2025
6fc235c
test: re-enable discovery tests
MarcosNicolau Jan 23, 2025
f1ba350
fix: sanity checks
MarcosNicolau Jan 23, 2025
399ef4c
refactor: use try_add_peer_and_ping in ping msg
MarcosNicolau Jan 23, 2025
522a2f7
refactor: handle messages more rustacean code
MarcosNicolau Jan 23, 2025
02d2b06
Merge branch 'main' into refactor/discovery
MarcosNicolau Jan 23, 2025
2f5a38a
test: fix lookups assertion
MarcosNicolau Jan 24, 2025
7d69b81
refactor: handle messages
MarcosNicolau Jan 24, 2025
4da7c89
refactor: enr_seq calculate it once on startup
MarcosNicolau Jan 24, 2025
c01d2fc
fix: enr messages with new calculated seq
MarcosNicolau Jan 24, 2025
b6a4ed5
test: enr with new calculated seq
MarcosNicolau Jan 24, 2025
a8ea0e6
Merge branch 'main' into refactor/discovery
MarcosNicolau Jan 24, 2025
4ec15ba
refactor: usage of context in discv4 module
MarcosNicolau Jan 24, 2025
2e35002
refactor: use node.addr() instead of creating socket addr
MarcosNicolau Jan 24, 2025
4ecebfc
fix: add anr remove request msgs checks
MarcosNicolau Jan 27, 2025
d6532fc
refactor: apply some review suggestions
MarcosNicolau Jan 27, 2025
6487eff
docs: discv4 server
MarcosNicolau Jan 27, 2025
5e76cce
refactor: remove time_now_unix from kademlia table
MarcosNicolau Jan 27, 2025
fb16d77
refactor: discv4 helpers
MarcosNicolau Jan 27, 2025
28f97de
refactor: move discv4 server from mod to new file
MarcosNicolau Jan 27, 2025
a61ea36
Merge branch 'main' into refactor/discovery
MarcosNicolau Jan 27, 2025
68ada44
chore: address clippy warnings
MarcosNicolau Jan 27, 2025
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
7 changes: 2 additions & 5 deletions cmd/ethrex/ethrex.rs
Original file line number Diff line number Diff line change
@@ -264,18 +264,15 @@ async fn main() {
let block_producer_engine = ethrex_dev::block_producer::start_block_producer(url, authrpc_jwtsecret.into(), head_block_hash, max_tries, 1000, ethrex_core::Address::default());
tracker.spawn(block_producer_engine);
} else {
let networking = ethrex_net::start_network(
ethrex_net::start_network(
local_p2p_node,
tracker.clone(),
udp_socket_addr,
tcp_socket_addr,
bootnodes,
signer,
peer_table.clone(),
store,
)
.into_future();
tracker.spawn(networking);
.await.expect("Network starts");
Comment on lines -278 to +275
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we don't need to spawn the networking as a task. This allows us to panic if there is an err during the network startup.

tracker.spawn(ethrex_net::periodically_show_peer_stats(peer_table));
}
}
29 changes: 29 additions & 0 deletions crates/networking/p2p/discv4/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::time::{Duration, SystemTime, UNIX_EPOCH};

pub fn get_msg_expiration_from_seconds(seconds: u64) -> u64 {
(SystemTime::now() + Duration::from_secs(seconds))
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_secs()
}

pub fn is_msg_expired(expiration: u64) -> bool {
// this cast to a signed integer is needed as the rlp decoder doesn't take into account the sign
// otherwise if a msg contains a negative expiration, it would pass since as it would wrap around the u64.
(expiration as i64) < (current_unix_time() as i64)
}

pub fn elapsed_time_since(unix_timestamp: u64) -> u64 {
let time = SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(unix_timestamp);
SystemTime::now()
.duration_since(time)
.unwrap_or_default()
.as_secs()
}

pub fn current_unix_time() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_secs()
}
Loading