Skip to content

Conversation

noot
Copy link
Contributor

@noot noot commented Sep 24, 2025

📝 Summary

  • implement p2p crate which implements a simple libp2p node
  • p2p node has the ability to support various stream protocols and broadcasting to all peers on a protocol
  • note: this is not gossip; messages will only be sent to directly-connected peers. we currently assume a very small builder network (<10 nodes) so direct connectivity is okay, but for larger networks, this will need to be extended.
  • update flashblocks payload builder to broadcast newly built flashblock payloads over p2p
  • implement payload handler to handle incoming flashblock payloads from peers
  • NOTE: syncing and execution of flashblocks is not yet implemented; it will be added to the payload handler in a follow up PR.

future extensions:

  • connection management/max peer count/peer persistence
  • flashblock sync and execution
  • test fallback building (if one builder fails in the middle of a block after building some flashblocks, can another builder take over flashblock building?) be out of scope for this PR, as the main goal of this PR is to ensure flashblock sync over p2p.

💡 Motivation and Context

see https://hackmd.io/@nZ-twauPRISEa6G9zg3XRw/H1fekrwolx

✅ I have completed the following steps:

  • Run make lint
  • Run make test
  • Added tests (if applicable)

Copy link
Contributor

@akundaz akundaz left a 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

}

#[allow(clippy::large_enum_variant)]
#[derive(Debug)]
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use derive_more::From to get rid of the manual From impls below

}

impl NodeBuilder {
pub fn new() -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

Derive default instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is default() also, I like having both

loop {
match reader.next().await {
Some(Ok(str)) => {
let payload: M = serde_json::from_str(&str)
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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

@noot
Copy link
Contributor Author

noot commented Sep 30, 2025

How are you handling the race conditions p2p introduces? Like if two builder build different flashblocks or something like that.

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.

Not really sure what's happening in the p2p crate, please make sure it's documented well so that others can contribute easily

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(
Copy link
Collaborator

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?

Copy link
Contributor Author

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

@noot noot marked this pull request as ready for review October 6, 2025 00:15
@noot noot requested review from SozinM and karim-agha as code owners October 6, 2025 00:15
@noot noot changed the title feat: implement p2p layer for flashblocks feat: implement p2p layer and broadcast flashblocks Oct 6, 2025
@noot noot requested review from akundaz and avalonche October 6, 2025 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants