Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
ce7a635
Cap mock
Mechanix97 May 15, 2025
c08a153
Fix capability struct
Mechanix97 May 15, 2025
8bf6d4c
Merge branch 'main' into refactor/capability-struct-instead-of-tuple
Mechanix97 May 15, 2025
74eaad7
fix forgotten capability
Mechanix97 May 15, 2025
f606799
Merge branch 'refactor/capability-struct-instead-of-tuple' of github.…
Mechanix97 May 15, 2025
2188f89
Merge branch 'main' into refactor/capability-struct-instead-of-tuple
Mechanix97 May 15, 2025
5e360bd
Fix lint
Mechanix97 May 15, 2025
e23fd22
Merge branch 'refactor/capability-struct-instead-of-tuple' of github.…
Mechanix97 May 15, 2025
899fdd6
Use constants now
Mechanix97 May 15, 2025
d2b8022
Status version 68
Mechanix97 May 16, 2025
2c7dd3a
fix CAP_SNAP_1
Mechanix97 May 16, 2025
2b00b99
Merge branch 'main' into refactor/capability-struct-instead-of-tuple
Mechanix97 May 16, 2025
f567433
Add eth 69
Mechanix97 May 16, 2025
352d92c
Add receipt logic
Mechanix97 May 16, 2025
c302e06
Merge branch 'main' into refactor/capability-struct-instead-of-tuple
Mechanix97 May 16, 2025
0a349d5
temp
Mechanix97 May 16, 2025
ea5d2cf
Go back receipts
Mechanix97 May 19, 2025
cf4d358
Fix correct capabilities settings
Mechanix97 May 19, 2025
637ecc2
Merge branch 'main' into feat/capability-negotation
Mechanix97 May 19, 2025
551bdea
Fix merge
Mechanix97 May 19, 2025
c98a398
Not eth 69 supported yet
Mechanix97 May 19, 2025
36d73df
Fix lint
Mechanix97 May 19, 2025
16f6ed5
Merge branch 'main' into feat/capability-negotation
Mechanix97 May 19, 2025
52ece3a
Fix if
Mechanix97 May 19, 2025
c03eccd
Merge branch 'feat/capability-negotation' into feat/backward-cap-comp…
Mechanix97 May 19, 2025
60fd8fb
Fix test
Mechanix97 May 19, 2025
0d979d9
new has_bloom fn
Mechanix97 May 20, 2025
eaad8d9
new bloom filter
Mechanix97 May 20, 2025
7acd82f
Merge branch 'main' into feat/backward-cap-compatibility
Mechanix97 May 20, 2025
e4b3e4a
Add receipt69
Mechanix97 May 20, 2025
2e3e62d
remove eth/69 calls
Mechanix97 May 20, 2025
64de71c
empty to true
Mechanix97 May 20, 2025
0fe49af
unsync
Mechanix97 May 20, 2025
92a50db
Merge branch 'main' into feat/implement-eth/69
Mechanix97 May 20, 2025
3278ab4
Status message 69
Mechanix97 May 20, 2025
4b8c5b6
encode receipt68
Mechanix97 May 20, 2025
6022f07
Remove bloom
Mechanix97 May 21, 2025
5a2c0c8
Add comments
Mechanix97 May 21, 2025
ee96809
Receipt encode69
Mechanix97 May 21, 2025
9ca211b
Merge branch 'main' into feat/implement-eth/69
Mechanix97 May 21, 2025
e2da4d7
fix lint
Mechanix97 May 21, 2025
ab299e0
Fix tests
Mechanix97 May 21, 2025
bb8a0b4
remove eth/69 cap
Mechanix97 May 21, 2025
f628ee8
New Receipt68 struct
Mechanix97 May 21, 2025
51a79e5
CI with eth68 only
Mechanix97 May 21, 2025
de55189
Fix merkle root receipts
Mechanix97 May 21, 2025
7017646
Fix has_bloom
Mechanix97 May 21, 2025
261ab9c
Merge branch 'main' into feat/implement-eth/69
Mechanix97 May 21, 2025
a1b5ec5
Fix log blooms
Mechanix97 May 22, 2025
342c436
Fix receipt encoding
Mechanix97 May 22, 2025
66f4854
rangeblockupdate message
Mechanix97 May 22, 2025
5e0264d
Merge branch 'main' into feat/implement-eth/69
Mechanix97 May 23, 2025
9fb0b30
Add msg decode to BlockRangeUpdate
Mechanix97 May 23, 2025
b577c60
Fix code in eth68 and eth69
Mechanix97 May 23, 2025
794dd07
Send update msg periodically
Mechanix97 May 23, 2025
3a30b1f
Remove dep
Mechanix97 May 23, 2025
2f65c04
Add from to receipt
Mechanix97 May 26, 2025
11e7a73
Move log placement
Mechanix97 May 26, 2025
68ff774
Fix test
Mechanix97 May 26, 2025
2bc26eb
Change range update trigger
Mechanix97 May 26, 2025
0c3d8d6
Merge branch 'main' into feat/implement-eth/69
Mechanix97 May 27, 2025
83df7f5
Fix update code
Mechanix97 May 27, 2025
66b7f97
Merge branch 'main' into feat/implement-eth/69
Mechanix97 Jun 2, 2025
bcd366b
Fix hash fn
Mechanix97 Jun 2, 2025
15ef5f8
Update fix hash
Mechanix97 Jun 2, 2025
b0015a1
Merge branch 'main' into feat/implement-eth/69
Mechanix97 Jun 3, 2025
8889f58
Merge branch 'main' into feat/implement-eth/69
Mechanix97 Jun 3, 2025
bb49f14
Fix snap offset for eth68
Mechanix97 Jun 3, 2025
11e19f2
Desactivate eth/69
Mechanix97 Jun 3, 2025
9edef2f
Merge branch 'main' into feat/implement-eth/69
Mechanix97 Jun 3, 2025
8c5cc9d
Add protocol in codec
Mechanix97 Jun 4, 2025
f3a7b5e
Add offset by protocol
Mechanix97 Jun 4, 2025
1f9bb65
Merge branch 'main' into mecha/implement-protocols
Mechanix97 Jun 4, 2025
d5decf5
Remove receipts68 & 69
Mechanix97 Jun 4, 2025
a110a2e
refactor status msg
Mechanix97 Jun 4, 2025
c002742
make private encode fns
Mechanix97 Jun 5, 2025
60e9b88
Add errors
Mechanix97 Jun 5, 2025
b80bb81
Fix test
Mechanix97 Jun 5, 2025
c9cf5ff
Fix test storage
Mechanix97 Jun 5, 2025
d8d188e
name receipts_with_bloom
Mechanix97 Jun 5, 2025
c05500f
Add assert to codec
Mechanix97 Jun 5, 2025
6321125
Merge branch 'main' into mecha/implement-protocols
Mechanix97 Jun 5, 2025
099c0aa
Add DEFAULT_P2P_PROTOCOL_VERSION
Mechanix97 Jun 5, 2025
f9e96e8
Merge branch 'mecha/implement-protocols' of github.com:lambdaclass/et…
Mechanix97 Jun 6, 2025
09a4d21
Remove codec assert
Mechanix97 Jun 6, 2025
b93dc62
Remove assert from status
Mechanix97 Jun 6, 2025
64c7d04
Add validations in blockrangeupdate
Mechanix97 Jun 6, 2025
e60fc05
Add validations to codec
Mechanix97 Jun 6, 2025
4ff1651
Use ok_or instead of let some
Mechanix97 Jun 9, 2025
b348442
Add ok_or to eth and snap in decode
Mechanix97 Jun 9, 2025
df81a9b
add Receipts trait, along with Receipts68 and Receipts69 structs
ricomateo Jun 18, 2025
a3735e1
Merge branch 'main' into mecha/implement-protocols
ricomateo Jun 18, 2025
48e6ded
add StatusMessage trait, along with Status68Message and Status69Messa…
ricomateo Jun 18, 2025
04721b8
fix clippy errors
ricomateo Jun 18, 2025
2d454ae
Merge branch 'main' into mecha/implement-protocols
ricomateo Jun 19, 2025
98f9346
revert style changes in the init_peer_conn function
ricomateo Jun 19, 2025
ea3c1a2
Merge branch 'mecha/implement-protocols' of github.com:lambdaclass/et…
ricomateo Jun 19, 2025
4cc0034
fix the order in the GetReceipts handler
ricomateo Jun 19, 2025
0e08f26
test: not empty receipts encoding and encoding
ricomateo Jun 19, 2025
4c5609a
remove Receipts trait and use Message::Receipts68 and Message::Receip…
ricomateo Jun 19, 2025
a0145ae
change Receipts68 encoding and decoding to include all receipts with …
ricomateo Jun 19, 2025
4dbc297
simplify test data
ricomateo Jun 19, 2025
9581976
add Status68 and Status69 variants for the Message enum
ricomateo Jun 19, 2025
569863c
re-add IncompatibleProtocol error type
ricomateo Jun 19, 2025
057a449
return error when the negotiated capability does not match any of the…
ricomateo Jun 19, 2025
bf17558
return IncompatibleProtocol error when the capability is not supported
ricomateo Jun 19, 2025
6bfaa1d
Merge branch 'main' into mecha/implement-protocols
ricomateo Jun 23, 2025
8c408f0
fix typo in the handle_message pattern matching
ricomateo Jun 23, 2025
f6c7f21
Merge branch 'mecha/implement-protocols' of github.com:lambdaclass/et…
ricomateo Jun 23, 2025
01dab4b
enable only eth/69 to check if hive tests keep working
ricomateo Jun 23, 2025
2fbd7db
include both eth/68 and eth/69 in SUPPORTED_ETH_CAPABILITIES
ricomateo Jun 23, 2025
3ac486b
Merge branch 'main' into mecha/implement-protocols
ricomateo Jul 3, 2025
9809590
handle messages according to the negotiated eth version
ricomateo Jul 3, 2025
dcfee00
set capabilities version in the codec
ricomateo Jul 3, 2025
e0db4dc
Revert "set capabilities version in the codec"
ricomateo Jul 3, 2025
ac7e243
add shared Capabilities struct to both Established and RLPxCodec structs
ricomateo Jul 3, 2025
723dfbd
add capabilities field to RLPxCodec
ricomateo Jul 3, 2025
79083da
wrap mutex locks inside blocks to release the mutex immediately
ricomateo Jul 3, 2025
e3b88b6
update the capabilities while holding the lock
ricomateo Jul 4, 2025
cf8915b
add doc comments
ricomateo Jul 4, 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
2 changes: 1 addition & 1 deletion crates/common/rlp/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ pub fn decode_bytes(data: &[u8]) -> Result<(&[u8], &[u8]), RLPDecodeError> {
/// Pads a slice of bytes with zeros on the left to make it a fixed size slice.
/// The size of the data must be less than or equal to the size of the output array.
#[inline]
pub fn static_left_pad<const N: usize>(data: &[u8]) -> Result<[u8; N], RLPDecodeError> {
pub(crate) fn static_left_pad<const N: usize>(data: &[u8]) -> Result<[u8; N], RLPDecodeError> {
let mut result = [0; N];

if data.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion crates/common/rlp/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl<T: RLPEncode> RLPEncode for Vec<T> {
}
}

pub fn encode_length(total_len: usize, buf: &mut dyn BufMut) {
pub(crate) fn encode_length(total_len: usize, buf: &mut dyn BufMut) {
if total_len < 56 {
buf.put_u8(0xc0 + total_len as u8);
} else {
Expand Down
4 changes: 4 additions & 0 deletions crates/common/rlp/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ pub enum RLPDecodeError {
pub enum RLPEncodeError {
#[error("InvalidCompression")]
InvalidCompression(#[from] snap::Error),
#[error("IncompatibleProtocol")]
IncompatibleProtocol,
#[error("MalformedData")]
MalformedData,
#[error("{0}")]
Custom(String),
}
2 changes: 0 additions & 2 deletions crates/networking/p2p/discv4/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ impl PingMessage {
}
}

// TODO: remove when used
#[allow(unused)]
pub fn with_enr_seq(self, enr_seq: u64) -> Self {
Self {
enr_seq: Some(enr_seq),
Expand Down
12 changes: 9 additions & 3 deletions crates/networking/p2p/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,15 @@ impl PeerHandler {
if let Some(receipts) = tokio::time::timeout(PEER_REPLY_TIMEOUT, async move {
loop {
match receiver.recv().await {
Some(RLPxMessage::Receipts(receipts)) => {
if receipts.get_id() == request_id {
return Some(receipts.get_receipts());
Some(RLPxMessage::Receipts68(receipts)) => {
if receipts.id == request_id {
return Some(receipts.receipts);
}
return None;
}
Some(RLPxMessage::Receipts69(receipts)) => {
if receipts.id == request_id {
return Some(receipts.receipts);
}
return None;
}
Expand Down
71 changes: 69 additions & 2 deletions crates/networking/p2p/rlpx/connection/codec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::rlpx::connection::server::Capabilities;
use crate::rlpx::{error::RLPxError, message as rlpx, utils::ecdh_xchng};
use std::sync::Arc;
use tokio::sync::Mutex;

use super::handshake::{LocalState, RemoteState};
use aes::{
Expand All @@ -24,13 +27,15 @@ pub(crate) struct RLPxCodec {
pub(crate) egress_mac: Keccak256,
pub(crate) ingress_aes: Aes256Ctr64BE,
pub(crate) egress_aes: Aes256Ctr64BE,
pub capabilities: Arc<Mutex<Capabilities>>,
}

impl RLPxCodec {
pub(crate) fn new(
local_state: &LocalState,
remote_state: &RemoteState,
hashed_nonces: [u8; 32],
capabilities: Arc<Mutex<Capabilities>>,
) -> Result<Self, RLPxError> {
let ephemeral_key_secret = ecdh_xchng(
&local_state.ephemeral_key,
Expand Down Expand Up @@ -67,8 +72,49 @@ impl RLPxCodec {
egress_mac,
ingress_aes,
egress_aes,
capabilities,
})
}

// pub fn set_p2p_protocol(&mut self, cap: &Capability) -> Result<(), RLPxError> {
// if !cap.is_p2p() {
// return Err(RLPxError::InternalError(
// "The protocol should be p2p".into(),
// ));
// }
// self.p2p_protocol = Some(cap.clone());
// Ok(())
// }

// pub fn set_eth_protocol(&mut self, cap: &Capability) -> Result<(), RLPxError> {
// if !cap.is_eth() {
// return Err(RLPxError::InternalError(
// "The protocol should be eth".into(),
// ));
// }
// if self.p2p_protocol.is_none() {
// return Err(RLPxError::InternalError(
// "p2p protocol should be established first".into(),
// ));
// }
// self.eth_protocol = Some(cap.clone());
// Ok(())
// }

// pub fn set_snap_protocol(&mut self, cap: &Capability) -> Result<(), RLPxError> {
// if !cap.is_snap() {
// return Err(RLPxError::InternalError(
// "The protocol should be snap".into(),
// ));
// }
// if self.eth_protocol.is_none() {
// return Err(RLPxError::InternalError(
// "Eth protocol should be established first".into(),
// ));
// }
// self.snap_protocol = Some(cap.clone());
// Ok(())
// }
}

impl Decoder for RLPxCodec {
Expand Down Expand Up @@ -193,7 +239,18 @@ impl Decoder for RLPxCodec {
let (frame_data, _padding) = frame_ciphertext.split_at(frame_size);

let (msg_id, msg_data): (u8, _) = RLPDecode::decode_unfinished(frame_data)?;
Ok(Some(rlpx::Message::decode(msg_id, msg_data)?))

// NOTE: this crashes since it is not possible to create a runtime within an async context.
// Find the right way to lock the capabilities mutex
let rt = tokio::runtime::Runtime::new().unwrap();
let capabilities = rt.block_on(async { self.capabilities.lock().await });
Ok(Some(rlpx::Message::decode(
msg_id,
msg_data,
&capabilities.p2p,
&capabilities.eth,
&capabilities.snap,
)?))
}

fn decode_eof(&mut self, buf: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
Expand Down Expand Up @@ -222,7 +279,17 @@ impl Encoder<rlpx::Message> for RLPxCodec {

fn encode(&mut self, message: rlpx::Message, buffer: &mut BytesMut) -> Result<(), Self::Error> {
let mut frame_data = vec![];
message.encode(&mut frame_data)?;

// NOTE: this crashes since it is not possible to create a runtime within an async context.
// Find the right way to lock the capabilities mutex
let rt = tokio::runtime::Runtime::new().unwrap();
let capabilities = rt.block_on(async { self.capabilities.lock().await });
message.encode(
&mut frame_data,
&capabilities.p2p,
&capabilities.eth,
&capabilities.snap,
)?;

let mac_aes_cipher = Aes256Enc::new_from_slice(&self.mac_key.0)?;

Expand Down
20 changes: 15 additions & 5 deletions crates/networking/p2p/rlpx/connection/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use crate::{
rlpx::{
connection::server::{Established, InnerState},
connection::server::{Capabilities, Established, InnerState},
error::RLPxError,
utils::{
compress_pubkey, decompress_pubkey, ecdh_xchng, kdf, log_peer_debug, sha256,
Expand Down Expand Up @@ -64,6 +64,7 @@ pub(crate) struct LocalState {
pub(crate) async fn perform(
state: InnerState,
) -> Result<(Established, SplitStream<Framed<TcpStream, RLPxCodec>>), RLPxError> {
let capabilities = Arc::new(Mutex::new(Capabilities::default()));
let (context, node, framed, inbound) = match state {
InnerState::Initiator(Initiator { context, node }) => {
let addr = SocketAddr::new(node.ip, node.tcp_port);
Expand All @@ -81,7 +82,12 @@ pub(crate) async fn perform(
// keccak256(nonce || initiator-nonce)
let hashed_nonces: [u8; 32] =
Keccak256::digest([remote_state.nonce.0, local_state.nonce.0].concat()).into();
let codec = RLPxCodec::new(&local_state, &remote_state, hashed_nonces)?;
let codec = RLPxCodec::new(
&local_state,
&remote_state,
hashed_nonces,
capabilities.clone(),
)?;
log_peer_debug(&node, "Completed handshake as initiator");
(context, node, Framed::new(stream, codec), false)
}
Expand All @@ -99,7 +105,12 @@ pub(crate) async fn perform(
// keccak256(nonce || initiator-nonce)
let hashed_nonces: [u8; 32] =
Keccak256::digest([local_state.nonce.0, remote_state.nonce.0].concat()).into();
let codec = RLPxCodec::new(&local_state, &remote_state, hashed_nonces)?;
let codec = RLPxCodec::new(
&local_state,
&remote_state,
hashed_nonces,
capabilities.clone(),
)?;
let node = Node::new(
peer_addr.ip(),
peer_addr.port(),
Expand All @@ -122,8 +133,6 @@ pub(crate) async fn perform(
storage: context.storage.clone(),
blockchain: context.blockchain.clone(),
capabilities: vec![],
negotiated_eth_capability: None,
negotiated_snap_capability: None,
last_block_range_update_block: 0,
broadcasted_txs: HashSet::new(),
requested_pooled_txs: HashMap::new(),
Expand All @@ -132,6 +141,7 @@ pub(crate) async fn perform(
table: context.table.clone(),
backend_channel: None,
inbound,
negotiated_capabilities: capabilities,
},
stream,
))
Expand Down
Loading
Loading