-
Notifications
You must be signed in to change notification settings - Fork 28
feat: implement p2p layer and broadcast flashblocks #275
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are you handling the race conditions p2p introduces? Like if two builder build different flashblocks or something like that.
Not really sure what's happening in the p2p crate, please make sure it's documented well so that others can contribute easily
crates/p2p/src/lib.rs
Outdated
loop { | ||
match reader.next().await { | ||
Some(Ok(str)) => { | ||
let payload: M = serde_json::from_str(&str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't deserialization happen in op-rbuilder code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i originally had it there, i was debating if the serialization format should be internal or external to the p2p layer. i'm going to refactor this to not be json anyways. could change the p2p layer back to just handle Bytes
instead of Message
if you prefer that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good, i'll look again after you refactor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks better now that it's over Message
, just fix the error messages about flashblocks
out of scope for this PR, i am assuming the high availability setup will be used where op-conductor will manage which party is building at a specific time.
yes will add! PR is still draft, not ready for review yet tbh, will ping you again when it's fully ready. |
&self.evm_config | ||
} | ||
|
||
pub(super) fn into_op_payload_builder_ctx( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not for conversions between the types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm probably going to remove this function after cleanup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a P2P layer for flashblocks using libp2p to enable broadcasting and receiving flashblock payloads between builder nodes. The implementation adds a new p2p
crate with basic networking capabilities and integrates it into the flashblocks payload builder to broadcast newly built payloads.
- Implements P2P crate with libp2p node supporting stream protocols and broadcasting
- Updates flashblocks payload builder to broadcast payloads over P2P instead of just WebSocket
- Adds payload handler to manage incoming P2P flashblock messages and route them to the payload builder service
Reviewed Changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
crates/p2p/src/lib.rs |
Core P2P node implementation with libp2p networking, message handling, and stream management |
crates/p2p/src/outgoing.rs |
Outgoing stream handler for broadcasting messages to connected peers |
crates/p2p/src/behaviour.rs |
libp2p network behavior configuration with protocols like identify, ping, mDNS |
crates/op-rbuilder/src/builders/flashblocks/service.rs |
Integration of P2P node into flashblocks service with payload handler |
crates/op-rbuilder/src/builders/flashblocks/payload_handler.rs |
Handler for routing built payloads and incoming P2P messages |
crates/op-rbuilder/src/builders/flashblocks/payload.rs |
Updated payload builder to send payloads via channel instead of direct engine calls |
crates/op-rbuilder/src/builders/flashblocks/p2p.rs |
P2P message types and conversions for flashblock payloads |
crates/op-rbuilder/src/args/op.rs |
Added CLI arguments for P2P configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 15 out of 16 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 15 out of 16 changed files in this pull request and generated 4 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 15 out of 16 changed files in this pull request and generated 5 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
{ | ||
let private_key_hex = std::fs::read_to_string(private_key_file) | ||
.wrap_err_with(|| { | ||
format!("failed to read p2p private key file: {private_key_file}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not include the error here
pub(super) const AGENT_VERSION: &str = "op-rbuilder/1.0.0"; | ||
pub(super) const FLASHBLOCKS_STREAM_PROTOCOL: p2p::StreamProtocol = | ||
p2p::StreamProtocol::new("/flashblocks/1.0.0"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are the versions meant to be updated manually
Some(payload) = built_rx.recv() => { | ||
let _ = payload_events_handle.send(Events::BuiltPayload(payload.clone())); | ||
// TODO: only broadcast if `!no_tx_pool`? | ||
// ignore error here; if p2p was disabled, the channel will be closed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm what is p2p is enabled and an error occurs here?
we'll still want to broadcast on no_tx_pool because it contains state changes around deposit transactions that other builders need
pub p2p_enabled: bool, | ||
|
||
/// Port for the p2p node | ||
pub p2p_port: u16, | ||
|
||
/// Optional hex-encoded private key file path for the p2p node | ||
pub p2p_private_key_file: Option<String>, | ||
|
||
/// Comma-separated list of multiaddresses of known peers to connect to | ||
pub p2p_known_peers: Option<String>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can wrap these into P2PArgs like GasLimiterArgs
flashblocks_block_time: 200, | ||
flashblocks_leeway_time: 100, | ||
flashblocks_fixed: false, | ||
flashblocks_calculate_state_root: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think this is redundant if default is specified
}; | ||
use std::{convert::Infallible, time::Duration}; | ||
|
||
const DEFAULT_MAX_PEER_COUNT: u32 = 200; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this can be an op-rbuilder arg
.map(|addr| { | ||
addr.clone() | ||
.with_p2p(self.peer_id) | ||
.expect("can add peer ID to multiaddr") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are the error cases when peer id can't be added?
📝 Summary
future extensions:
💡 Motivation and Context
see https://hackmd.io/@nZ-twauPRISEa6G9zg3XRw/H1fekrwolx
✅ I have completed the following steps:
make lint
make test