Skip to content
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

refactor(l1): improve error handling in RLPx modules #1017

Merged
merged 20 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
339831c
Added some error handling in connection module
ElFantasma Oct 30, 2024
4f95e55
Refactored connection.rs to remove unhandled unwraps()
ElFantasma Oct 31, 2024
ab6182c
Merge branch 'main' into 845-improve-error-handling-in-rlpx-modules
ElFantasma Oct 31, 2024
17903aa
Fixed ack decoding test and moved to proper module
ElFantasma Oct 31, 2024
132b342
Better format for test
ElFantasma Oct 31, 2024
788af33
Removed outdated comment
ElFantasma Oct 31, 2024
7609609
Updated rlpx/errors.rs
ElFantasma Oct 31, 2024
4c36d20
Merge branch 'main' into 845-improve-error-handling-in-rlpx-modules
ElFantasma Oct 31, 2024
2225526
Updated rlpx/handshake.rs to handle internal errors
ElFantasma Oct 31, 2024
af12ffc
Merge branch 'main' into 845-improve-error-handling-in-rlpx-modules
ElFantasma Oct 31, 2024
09c149a
Changed function visibility
ElFantasma Nov 5, 2024
9f2e08d
Merge branch 'main' into 845-improve-error-handling-in-rlpx-modules
ElFantasma Nov 5, 2024
ebd7026
Merge branch 'main' into 845-improve-error-handling-in-rlpx-modules
ElFantasma Nov 5, 2024
0f81e98
Making p2p messages code consistent with the rest of the capabilities
ElFantasma Nov 5, 2024
fc64092
Refactored snappy decompress duplicated code
ElFantasma Nov 6, 2024
232ecd7
Improved error handling in frame.rs module and some refactors
ElFantasma Nov 6, 2024
560cdfc
Merge branch 'main' into 845-improve-error-handling-in-rlpx-modules
ElFantasma Nov 6, 2024
618ff01
Merge branch 'main' into 845-improve-error-handling-in-rlpx-modules
ElFantasma Nov 6, 2024
50103ce
Added some slice bounds checks
ElFantasma Nov 7, 2024
7108d35
Merge branch 'main' into 845-improve-error-handling-in-rlpx-modules
ElFantasma Nov 7, 2024
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ jsonwebtoken = "9.3.0"
rand = "0.8.5"
cfg-if = "1.0.0"
reqwest = { version = "0.12.7", features = ["json"] }
snap = "1.1.1"
1 change: 1 addition & 0 deletions crates/common/rlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ bytes.workspace = true
hex.workspace = true
lazy_static.workspace = true
ethereum-types.workspace = true
snap.workspace = true

[dev-dependencies]
hex-literal.workspace = true
Expand Down
4 changes: 3 additions & 1 deletion crates/common/rlp/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub enum RLPDecodeError {
UnexpectedList,
#[error("UnexpectedString")]
UnexpectedString,
#[error("InvalidCompression")]
InvalidCompression(#[from] snap::Error),
#[error("{0}")]
Custom(String),
}
Expand All @@ -21,7 +23,7 @@ pub enum RLPDecodeError {
#[derive(Debug, Error)]
pub enum RLPEncodeError {
#[error("InvalidCompression")]
InvalidCompression,
InvalidCompression(#[from] snap::Error),
#[error("{0}")]
Custom(String),
}
20 changes: 14 additions & 6 deletions crates/networking/p2p/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use tokio::{
sync::Mutex,
try_join,
};
use tracing::{debug, info};
use tracing::{debug, error, info};
use types::{Endpoint, Node};

pub mod bootnode;
Expand Down Expand Up @@ -774,8 +774,12 @@ async fn handle_peer_as_initiator(
.connect(SocketAddr::new(node.ip, node.tcp_port))
.await
.unwrap();
let conn = RLPxConnection::initiator(signer, msg, stream, storage).await;
handle_peer(conn, table).await;
match RLPxConnection::initiator(signer, msg, stream, storage).await {
Ok(conn) => handle_peer(conn, table).await,
Err(e) => {
error!("Error: {e}, Could not start connection with {node:?}");
}
}
}

async fn handle_peer(mut conn: RLPxConnection<TcpStream>, table: Arc<Mutex<KademliaTable>>) {
Expand All @@ -785,9 +789,13 @@ async fn handle_peer(mut conn: RLPxConnection<TcpStream>, table: Arc<Mutex<Kadem
Err(e) => info!("Error during RLPx connection: ({e})"),
},
Err(e) => {
// Discard peer from kademlia table
info!("Handshake failed, discarding peer: ({e})");
table.lock().await.replace_peer(conn.get_remote_node_id());
if let Ok(node_id) = conn.get_remote_node_id() {
// Discard peer from kademlia table
info!("Handshake failed: ({e}), discarding peer {node_id}");
table.lock().await.replace_peer(node_id);
} else {
info!("Handshake failed: ({e}), unknown peer");
}
}
}
}
Expand Down
Loading
Loading