Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
eb5427e
initial discv5
ElFantasma Dec 9, 2025
dd0990b
Merge branch 'main' into discv5
ElFantasma Dec 9, 2025
a61953f
discv5 stub modules
ElFantasma Dec 10, 2025
637aaac
Merge branch 'main' into discv5
ElFantasma Dec 10, 2025
e1a8a83
Ordinary packet
ElFantasma Dec 11, 2025
fec454e
Added WhoAreYou packet
ElFantasma Dec 11, 2025
2e65c2e
Merge branch 'main' into discv5
ElFantasma Dec 11, 2025
6ecfb65
WhoAreYou decode test pass
ElFantasma Dec 11, 2025
0de7e39
WhoAreYou encode test pass
ElFantasma Dec 11, 2025
a56f4da
protocol version check
ElFantasma Dec 11, 2025
7a8541b
Added Discv5Codec
ElFantasma Dec 12, 2025
334044e
feat(l1): implement `discv5`'s `Pong` message (#5616)
azteca1998 Dec 12, 2025
ac66212
Merge branch 'main' into discv5
ElFantasma Dec 12, 2025
31b82d2
Added decryption and corrected Ping decoding
ElFantasma Dec 12, 2025
db0a79c
Corrected Ping encoding
ElFantasma Dec 12, 2025
3020428
feat(l1): implement discv5 TalkReq message coding (#5631)
edg-l Dec 15, 2025
552160a
feat(l1): implement discv5 nodes message coding (#5630)
edg-l Dec 15, 2025
d2da66c
feat(l1): implement discv5's FindNode message (#5629)
edg-l Dec 15, 2025
4af6e40
chore(l1): fix discv5 branch lints (#5633)
edg-l Dec 15, 2025
e247d48
chore(l1): improve discv5 new_nonce (#5652)
edg-l Dec 16, 2025
13b1e16
chore(l1): put all discv5 behind a feature flag (#5651)
edg-l Dec 16, 2025
48282da
feat(l1): implement discv5 TICKET message codec (#5650)
edg-l Dec 16, 2025
2907a37
feat(l1): implement `discv5` `TalkRes` message codec (#5632)
azteca1998 Dec 16, 2025
c547ab5
Merge branch 'main' into discv5
ElFantasma Dec 16, 2025
52fa23e
Merge branch 'main' into discv5
ElFantasma Dec 16, 2025
4aae22c
feat(l1): implement discv5 handshake encoding/decoding (#5653)
edg-l Dec 16, 2025
92ea30a
Merge branch 'main' into discv5
edg-l Dec 17, 2025
f2e8501
feat(l1): discv5, add ordinary packet coding (#5665)
edg-l Dec 17, 2025
0eda82b
Merge branch 'main' into discv5
ElFantasma Dec 17, 2025
8cab21f
Merge branch 'main' into discv5
edg-l Dec 18, 2025
bb8e46a
feat(l1): add discv5 session structures and remaining official vector…
edg-l Dec 18, 2025
1a3fca7
Initial server code - WIP
ElFantasma Dec 18, 2025
60c7e3f
Merge branch 'discv5' into discv5-server
ElFantasma Dec 18, 2025
16da2ac
rename feature
edg-l Dec 18, 2025
de865e2
rename
edg-l Dec 18, 2025
aba0c28
Corrected FindNode and sending it inside a Package - WIP
ElFantasma Dec 18, 2025
e314828
Random FindNode message - WIP
ElFantasma Dec 18, 2025
45d01e2
Merge branch 'main' into discv5
ElFantasma Dec 18, 2025
c0c293e
Improving protocol - WIP
ElFantasma Dec 18, 2025
a43b915
address comments
edg-l Dec 19, 2025
afdaeba
Merge branch 'main' into discv5
edg-l Dec 19, 2025
d7ada2b
Updated some types
ElFantasma Dec 19, 2025
9e562dd
Merge branch 'main' into discv5
ElFantasma Dec 19, 2025
683191a
Merge branch 'discv5' into discv5-server
ElFantasma Dec 19, 2025
3e93c71
Updated feature name
ElFantasma Dec 19, 2025
2aca677
Addressed PR comments and corrected req_id type
ElFantasma Dec 19, 2025
6b819a1
Corrected static_header type
ElFantasma Dec 19, 2025
41d100e
Removed unnecessary stuff
ElFantasma Dec 19, 2025
c1d3031
Merge branch 'main' into discv5
ElFantasma Dec 19, 2025
ffd7c61
Merge branch 'discv5' into discv5-server
ElFantasma Dec 19, 2025
ec85eb5
Several refactors to support partially decoded Packets - WIP
ElFantasma Dec 22, 2025
79354b6
Merge branch 'main' into discv5-server
ElFantasma Dec 22, 2025
06652ed
Merge branch 'main' into discv5-server
ElFantasma Dec 22, 2025
3a07910
Saving messages by nonce
ElFantasma Dec 22, 2025
438fb8d
Building handshake message from WhoAreYou
ElFantasma Dec 23, 2025
a0a92ea
Merge branch 'main' into discv5-server
ElFantasma Dec 23, 2025
377fc00
Fixing tests improving code
ElFantasma Dec 24, 2025
1115a8a
Merge branch 'main' into discv5-server
ElFantasma Dec 24, 2025
e237fa7
Improved tests
ElFantasma Dec 24, 2025
3040f2e
More tests and a fix in FindNode
ElFantasma Dec 26, 2025
82ac8dc
Merge branch 'main' into discv5-server
ElFantasma Dec 26, 2025
1dbf0c6
Removed DecodedPacket dependencies in server
ElFantasma Dec 26, 2025
9072f7c
Fixed some error in NodeRecord decoding
ElFantasma Dec 29, 2025
fc7f1d4
Removed DecodedPacket to use Packet only - WIP
ElFantasma Jan 5, 2026
206e613
Added PacketTypeWrapper for better Packet handling
ElFantasma Jan 6, 2026
f532169
Merge branch 'main' into discv5-server
ElFantasma Jan 6, 2026
1645035
Better FindNode randomization and handling Nodes message
ElFantasma Jan 6, 2026
dff4a4a
Nodes messages handling and some bug fixes
ElFantasma Jan 7, 2026
c453579
Nodes messages handling and some bug fixes
ElFantasma Jan 7, 2026
6637230
Merge branch 'main' into discv5-server
ElFantasma Jan 7, 2026
f19fa11
Put peer_table and discovery_server behind discv5 feature flag
ElFantasma Jan 7, 2026
94a0fbc
Reordered p2p.rs
ElFantasma Jan 7, 2026
6e1ff33
Merge branch 'main' into discv5-server
ElFantasma Jan 7, 2026
76ec6b9
Added links to github issues on comments
ElFantasma Jan 8, 2026
ba152dd
Merge branch 'main' into discv5-server
ElFantasma Jan 9, 2026
b91d7d0
Merge branch 'main' into discv5-server
ElFantasma Jan 12, 2026
21acbf3
Merge branch 'main' into discv5-server
ElFantasma Jan 12, 2026
49d7db7
Merge branch 'main' into discv5-server
ElFantasma Jan 13, 2026
c6b9b96
Merge branch 'main' into discv5-server
ElFantasma Jan 13, 2026
7fdcef3
Addressed PR comments
ElFantasma Jan 14, 2026
08cdc24
Merge branch 'main' into discv5-server
ElFantasma Jan 14, 2026
7c62ef8
Removed duplicate code
ElFantasma Jan 14, 2026
0d11c39
Merge branch 'main' into discv5-server
ElFantasma Jan 14, 2026
5f06156
Merge branch 'main' into discv5-server
ElFantasma Jan 14, 2026
d8a79c0
Added PacketTrait to reduce code duplication
ElFantasma Jan 15, 2026
63b7318
Replaced packet_type_flag function with an associated constant
ElFantasma Jan 15, 2026
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
6 changes: 2 additions & 4 deletions cmd/ethrex/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ use ethrex_blockchain::{
};
use ethrex_common::types::{Block, DEFAULT_BUILDER_GAS_CEIL, Genesis, validate_block_body};
use ethrex_p2p::{
discv4::{peer_table::TARGET_PEERS, server::INITIAL_LOOKUP_INTERVAL_MS},
sync::SyncMode,
tx_broadcaster::BROADCAST_INTERVAL_MS,
types::Node,
discv4::server::INITIAL_LOOKUP_INTERVAL_MS, peer_table::TARGET_PEERS, sync::SyncMode,
tx_broadcaster::BROADCAST_INTERVAL_MS, types::Node,
};
use ethrex_rlp::encode::RLPEncode;
use ethrex_storage::error::StoreError;
Expand Down
2 changes: 1 addition & 1 deletion cmd/ethrex/ethrex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ethrex::{
initializers::{init_l1, init_tracing},
utils::{NodeConfigFile, get_client_version, is_memory_datadir, store_node_config_file},
};
use ethrex_p2p::{discv4::peer_table::PeerTable, types::NodeRecord};
use ethrex_p2p::{peer_table::PeerTable, types::NodeRecord};
use serde::Deserialize;
use std::{path::Path, time::Duration};
use tokio::signal::unix::{SignalKind, signal};
Expand Down
2 changes: 1 addition & 1 deletion cmd/ethrex/initializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use ethrex_metrics::profiling::{FunctionProfilingLayer, initialize_block_process
use ethrex_metrics::rpc::initialize_rpc_metrics;
use ethrex_p2p::rlpx::initiator::RLPxInitiator;
use ethrex_p2p::{
discv4::peer_table::PeerTable,
network::P2PContext,
peer_handler::PeerHandler,
peer_table::PeerTable,
sync::SyncMode,
sync_manager::SyncManager,
types::{Node, NodeRecord},
Expand Down
2 changes: 1 addition & 1 deletion cmd/ethrex/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bytes::Bytes;
use directories::ProjectDirs;
use ethrex_common::types::{Block, Genesis};
use ethrex_p2p::{
discv4::peer_table::PeerTable,
peer_table::PeerTable,
sync::SyncMode,
types::{Node, NodeRecord},
};
Expand Down
4 changes: 4 additions & 0 deletions crates/common/rlp/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ impl<'a> Decoder<'a> {
pub const fn finish_unchecked(self) -> &'a [u8] {
self.remaining
}

pub const fn get_payload_len(&self) -> usize {
self.payload.len()
}
}

fn field_decode_error<T>(field_name: &str, err: RLPDecodeError) -> RLPDecodeError {
Expand Down
6 changes: 3 additions & 3 deletions crates/networking/p2p/discv4/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use crate::{
ENRRequestMessage, ENRResponseMessage, FindNodeMessage, Message, NeighborsMessage,
Packet, PacketDecodeErr, PingMessage, PongMessage,
},
peer_table::{Contact, OutMessage as PeerTableOutMessage, PeerTable, PeerTableError},
},
metrics::METRICS,
peer_table::{Contact, OutMessage as PeerTableOutMessage, PeerTable, PeerTableError},
types::{Endpoint, Node, NodeRecord},
utils::{
get_msg_expiration_from_seconds, is_msg_expired, node_id, public_key_from_signing_key,
Expand Down Expand Up @@ -98,7 +98,7 @@ impl DiscoveryServer {
storage: Store,
local_node: Node,
signer: SecretKey,
udp_socket: Arc<UdpSocket>,
udp_socket: UdpSocket,
mut peer_table: PeerTable,
bootnodes: Vec<Node>,
initial_lookup_interval: f64,
Expand All @@ -117,7 +117,7 @@ impl DiscoveryServer {
local_node: local_node.clone(),
local_node_record,
signer,
udp_socket,
udp_socket: Arc::new(udp_socket),
store: storage.clone(),
peer_table: peer_table.clone(),
find_node_message: Self::random_message(&signer),
Expand Down
63 changes: 7 additions & 56 deletions crates/networking/p2p/discv5/codec.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,17 @@
use crate::discv5::messages::{Packet, PacketCodecError};
use crate::discv5::session::Session;

use bytes::BytesMut;
use ethrex_common::H256;
use rand::{RngCore, thread_rng};
use tokio_util::codec::{Decoder, Encoder};

#[derive(Debug)]
pub struct Discv5Codec {
dest_id: H256,
/// Outgoing message count, used for nonce generation as per the spec.
counter: u32,
session: Option<Session>,
local_node_id: H256,
}

impl Discv5Codec {
pub fn new(dest_id: H256) -> Self {
Self {
dest_id,
counter: 0,
session: None,
}
}

pub fn with_session(dest_id: H256, session: Session) -> Self {
Self {
dest_id,
counter: 0,
session: Some(session),
}
}

pub fn set_session(&mut self, session: Session) {
self.session = Some(session);
}

/// Generates a 96-bit AES-GCM nonce
/// ## Spec Recommendation
/// Encode the current outgoing message count into the first 32 bits of the nonce and fill the remaining 64 bits with random data generated
/// by a cryptographically secure random number generator.
pub fn next_nonce<R: RngCore>(&mut self, rng: &mut R) -> [u8; 12] {
let counter = self.counter;
self.counter = self.counter.wrapping_add(1);

let mut nonce = [0u8; 12];
nonce[..4].copy_from_slice(&counter.to_be_bytes());
rng.fill_bytes(&mut nonce[4..]);
nonce
pub fn new(local_node_id: H256) -> Self {
Self { local_node_id }
}
}

Expand All @@ -56,13 +21,8 @@ impl Decoder for Discv5Codec {

fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
if !buf.is_empty() {
let key: &[u8; 16] = match &self.session {
Some(session) => session.inbound_key(),
None => &[0; 16],
};
Ok(Some(Packet::decode(
&self.dest_id,
key,
&self.local_node_id,
&buf.split_to(buf.len()),
)?))
} else {
Expand All @@ -74,17 +34,8 @@ impl Decoder for Discv5Codec {
impl Encoder<Packet> for Discv5Codec {
type Error = PacketCodecError;

fn encode(&mut self, packet: Packet, buf: &mut BytesMut) -> Result<(), Self::Error> {
let masking_iv: u128 = rand::random();
let mut rng = thread_rng();
let nonce = self.next_nonce(&mut rng);
// key isnt needed in WHOAREYOU packets
let key = match (&packet, &mut self.session) {
(Packet::WhoAreYou(_), _) => &[][..],
(_, Some(session)) => session.outbound_key(),
(_, None) => return Err(PacketCodecError::SessionNotEstablished),
};

packet.encode(buf, masking_iv, &nonce, &self.dest_id, key)
fn encode(&mut self, _packet: Packet, _buf: &mut BytesMut) -> Result<(), Self::Error> {
// We are not going to use Discv5Coded to send messages, only to receive them
unimplemented!();
}
}
Loading