-
Notifications
You must be signed in to change notification settings - Fork 212
feat(node/p2p): extend network actor test with block propagation. reduce test flakiness #2693
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| use std::net::{IpAddr, SocketAddr}; | ||
|
|
||
| use alloy_primitives::Address; | ||
| use discv5::multiaddr::Protocol; | ||
| use futures::future::OptionFuture; | ||
| use kona_disc::Discv5Driver; | ||
| use kona_gossip::{ConnectionGater, GossipDriver, PEER_SCORE_INSPECT_FREQUENCY}; | ||
| use kona_sources::{BlockSigner, BlockSignerStartError}; | ||
| use libp2p::TransportError; | ||
| use libp2p::{Multiaddr, TransportError}; | ||
| use tokio::sync::watch; | ||
|
|
||
| use crate::actors::network::handler::NetworkHandler; | ||
|
|
@@ -15,6 +18,11 @@ pub struct NetworkDriver { | |
| pub gossip: GossipDriver<ConnectionGater>, | ||
| /// The discovery driver. | ||
| pub discovery: Discv5Driver, | ||
| /// Whether to update the ENR socket after the libp2p Swarm is started. | ||
| /// This is set to true by default. | ||
| /// This may be set to false if the node is configured to use a static advertised address (when | ||
| /// used with a nat for example). | ||
| pub enr_update: bool, | ||
| /// The unsafe block signer sender. | ||
| pub unsafe_block_signer_sender: watch::Sender<Address>, | ||
| /// A block signer. This is optional and should be set if the node is configured to sign blocks | ||
|
|
@@ -30,17 +38,46 @@ pub enum NetworkDriverError { | |
| /// An error occurred starting the block signer client. | ||
| #[error("error starting block signer client: {0}")] | ||
| BlockSignerStartError(#[from] BlockSignerStartError), | ||
| /// An error occurred parsing the gossip listen address. | ||
| #[error("error parsing gossip listen address: {0}")] | ||
| InvalidGossipListenAddr(Multiaddr), | ||
| } | ||
|
|
||
| impl NetworkDriver { | ||
| /// Starts the network. | ||
| pub async fn start(mut self) -> Result<NetworkHandler, NetworkDriverError> { | ||
| // Start the libp2p Swarm | ||
| let gossip_listen_addr = self.gossip.start().await?; | ||
|
|
||
| if self.enr_update { | ||
| // Update the local ENR socket to the gossip listen address. | ||
| // Parse the multiaddr to a socket address. | ||
| let ip_address = gossip_listen_addr | ||
| .iter() | ||
| .find_map(|p| match p { | ||
| Protocol::Ip4(ip) => Some(IpAddr::V4(ip)), | ||
| Protocol::Ip6(ip) => Some(IpAddr::V6(ip)), | ||
| _ => None, | ||
| }) | ||
| .ok_or_else(|| { | ||
| NetworkDriverError::InvalidGossipListenAddr(gossip_listen_addr.clone()) | ||
| })?; | ||
| let port = gossip_listen_addr | ||
| .iter() | ||
| .find_map(|p| match p { | ||
| Protocol::Tcp(port) => Some(port), | ||
| _ => None, | ||
| }) | ||
| .ok_or_else(|| { | ||
| NetworkDriverError::InvalidGossipListenAddr(gossip_listen_addr.clone()) | ||
| })?; | ||
|
|
||
| self.discovery.disc.update_local_enr_socket(SocketAddr::new(ip_address, port), true); | ||
| } | ||
|
Comment on lines
+52
to
+76
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good candidate for a refactor in a separate method.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would that really increase readability? We're not really doing that much here and we don't really have this pattern elsewhere. I can refactor this out if we ever decide to add this pattern in other parts of the codebase |
||
|
|
||
| // Start the discovery service. | ||
| let (handler, enr_receiver) = self.discovery.start(); | ||
|
|
||
| // Start the libp2p Swarm | ||
| self.gossip.start().await?; | ||
|
|
||
| // We are checking the peer scores every [`PEER_SCORE_INSPECT_FREQUENCY`] seconds. | ||
| let peer_score_inspector = tokio::time::interval(*PEER_SCORE_INSPECT_FREQUENCY); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,135 @@ | ||||||||||||||||||||||||||||
| use std::time::SystemTime; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| use alloy_consensus::{Block, EMPTY_OMMER_ROOT_HASH}; | ||||||||||||||||||||||||||||
| use alloy_eips::Encodable2718; | ||||||||||||||||||||||||||||
| use alloy_primitives::Bytes; | ||||||||||||||||||||||||||||
| use arbitrary::{Arbitrary, Unstructured}; | ||||||||||||||||||||||||||||
| use libp2p::bytes::BufMut; | ||||||||||||||||||||||||||||
| use op_alloy_consensus::OpTxEnvelope; | ||||||||||||||||||||||||||||
| use op_alloy_rpc_types_engine::{OpExecutionPayload, OpExecutionPayloadEnvelope}; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| use crate::actors::generator::seed::SeedGenerator; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] | ||||||||||||||||||||||||||||
| pub(crate) enum PayloadVersion { | ||||||||||||||||||||||||||||
| V1, | ||||||||||||||||||||||||||||
| #[allow(dead_code)] | ||||||||||||||||||||||||||||
| V2, | ||||||||||||||||||||||||||||
| #[allow(dead_code)] | ||||||||||||||||||||||||||||
| V3, | ||||||||||||||||||||||||||||
| #[allow(dead_code)] | ||||||||||||||||||||||||||||
| V4, | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| impl SeedGenerator { | ||||||||||||||||||||||||||||
| /// Generate a random op execution payload. | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| /// Generate a random op execution payload. | |
| /// Generate a random op execution payload for the specified payload version. | |
| /// | |
| /// This function creates a random, valid `OpExecutionPayloadEnvelope` by constructing a block | |
| /// compatible with the given `PayloadVersion`. Each version corresponds to a different set of | |
| /// protocol features and header/body fields: | |
| /// | |
| /// - `V1`: The minimal version, omits withdrawals, blob gas, parent beacon block root, and requests hash. | |
| /// - `V2`: Adds withdrawals and the corresponding withdrawals root to the block. | |
| /// - `V3`: Adds blob gas fields and parent beacon block root, in addition to withdrawals. | |
| /// - `V4`: Currently identical to V3, but reserved for future protocol extensions. | |
| /// | |
| /// This allows testing and validation of payload handling across different protocol upgrades. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| pub(crate) mod block_builder; | ||
| pub(crate) mod seed; |
Uh oh!
There was an error while loading. Please reload this page.