feat(node/p2p): extend network actor test with block propagation. reduce test flakiness#2693
feat(node/p2p): extend network actor test with block propagation. reduce test flakiness#2693
Conversation
Codecov Report❌ Patch coverage is
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ef94b72 to
e766f6e
Compare
| 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); | ||
| } |
There was a problem hiding this comment.
This is a good candidate for a refactor in a separate method.
There was a problem hiding this comment.
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
refcell
left a comment
There was a problem hiding this comment.
No blockers from my side
1c31545 to
77f5bef
Compare
|
Claude finished @theochap's task —— View job PR Review Complete ✅I've completed my review of this PR which extends network actor tests with block propagation and reduces test flakiness. Here's my comprehensive feedback: Todo List:
Review Feedback✅ Strengths
|
There was a problem hiding this comment.
Pull Request Overview
This PR extends the network actor testing infrastructure with comprehensive block propagation tests and reduces test flakiness by using kernel-allocated ports for discovery/gossip protocols.
- Adds comprehensive sequencer network tests for block signature and propagation
- Replaces static port allocation with kernel-allocated ports to avoid race conditions
- Introduces random valid block building logic for payload generation
Reviewed Changes
Copilot reviewed 17 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/gossip/src/main.rs | Enables ENR update for gossip command configuration |
| crates/node/service/tests/actors/utils.rs | Removes legacy seed generator utilities (file deleted) |
| crates/node/service/tests/actors/network/sequencer.rs | Adds new sequencer network connectivity and propagation tests |
| crates/node/service/tests/actors/network/p2p.rs | Adds basic P2P network connectivity tests |
| crates/node/service/tests/actors/network/mod.rs | Restructures network test module organization |
| crates/node/service/tests/actors/network/mocks/mod.rs | Creates new test network mock infrastructure |
| crates/node/service/tests/actors/network/mocks/builder.rs | Implements test network builder with configurable sequencer support |
| crates/node/service/tests/actors/network/mocks.rs | Removes legacy test network mock implementation (file deleted) |
| crates/node/service/tests/actors/mod.rs | Updates module structure to include generator utilities |
| crates/node/service/tests/actors/generator/seed.rs | Adds improved seed generator with thread-safe atomic operations |
| crates/node/service/tests/actors/generator/mod.rs | Creates generator module structure |
| crates/node/service/tests/actors/generator/block_builder.rs | Implements random valid block generation for different payload versions |
| crates/node/service/src/actors/network/driver.rs | Updates network driver to support ENR socket updates after gossip startup |
| crates/node/service/src/actors/network/config.rs | Adds ENR update configuration option |
| crates/node/service/src/actors/network/builder.rs | Enhances network builder with ENR update support |
| crates/node/service/Cargo.toml | Adds consensus-related dependencies for test block generation |
| crates/node/gossip/src/driver.rs | Updates gossip driver to return actual listen address after startup |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } | ||
|
|
||
| fn next(&self) -> u64 { | ||
| self.0.fetch_add(1, Ordering::SeqCst) |
There was a problem hiding this comment.
Using Ordering::SeqCst is unnecessarily strong for a simple counter. Consider using Ordering::Relaxed since the exact ordering of seed generation doesn't require sequential consistency.
| self.0.fetch_add(1, Ordering::SeqCst) | |
| self.0.fetch_add(1, Ordering::Relaxed) |
| } | ||
|
|
||
| impl SeedGenerator { | ||
| /// Generate a random op execution payload. |
There was a problem hiding this comment.
The function lacks documentation explaining the purpose and behavior of generating different payload versions. Consider adding a docstring that describes what makes each version valid and how they differ.
| /// 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. |
| /// We are setting up a linear network topology, and we check that the block propagates to every | ||
| /// block of the network. | ||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn test_sequencer_network_propagation() -> anyhow::Result<()> { |
There was a problem hiding this comment.
[nitpick] The magic number 10 should be documented or made configurable. Consider adding a comment explaining why this specific number of networks is used for the propagation test.
| async fn test_sequencer_network_propagation() -> anyhow::Result<()> { | |
| async fn test_sequencer_network_propagation() -> anyhow::Result<()> { | |
| // Use 10 networks to ensure propagation is tested across a reasonably sized network. | |
| // This value is chosen to balance test coverage and execution time. |
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn test_large_network_conn() -> anyhow::Result<()> { |
There was a problem hiding this comment.
[nitpick] The magic number 10 should be documented or made configurable. Consider adding a comment explaining why this specific number of networks is used for the large network test.
| async fn test_large_network_conn() -> anyhow::Result<()> { | |
| async fn test_large_network_conn() -> anyhow::Result<()> { | |
| // Use 10 networks to simulate a moderately large P2P network and ensure scalability. | |
| // This value balances test coverage and execution time. |
| other: &Self, | ||
| ) -> Result<(), TestNetworkError> { | ||
| (async || self.is_connected_to(other).await) | ||
| .retry(ExponentialBuilder::default().with_total_delay(Some(Duration::from_secs(360)))) |
There was a problem hiding this comment.
[nitpick] The 360-second timeout is quite long and may slow down tests significantly if connections fail. Consider making this configurable or documenting why such a long timeout is necessary.
| .retry(ExponentialBuilder::default().with_total_delay(Some(Duration::from_secs(360)))) | |
| /// | |
| /// The total retry timeout is configurable (default: 360 seconds). A long timeout may be necessary | |
| /// in CI or slow environments, but can be reduced for faster feedback during development. | |
| pub(super) async fn is_connected_to_with_retries( | |
| &self, | |
| other: &Self, | |
| timeout_secs: Option<u64>, | |
| ) -> Result<(), TestNetworkError> { | |
| let total_delay = Duration::from_secs(timeout_secs.unwrap_or(360)); | |
| (async || self.is_connected_to(other).await) | |
| .retry(ExponentialBuilder::default().with_total_delay(Some(total_delay))) |
|
Claude finished @theochap's task —— View job PR Review Complete ✅I've completed my review of this PR which extends network actor tests with block propagation and reduces test flakiness. Here's my comprehensive feedback: Todo List:
Review Feedback✅ Strengths
|
…uce test flakiness (op-rs/kona#2693) ## Description This PR achieves the following goals: - Extend the simple p2p connection tests of op-rs/kona#2679 with more comprehensive tests involving block signature and propagation (a follow PR will add the cases for higher block versions, it requires updating the rollup config with hardfork times) - Fixes the network bootstrap logic to remove flakiness. In particular, it uses kernel allocated ports for discovery/gossip to avoid static modification races. - It adds random valid block building logic
…uce test flakiness (op-rs/kona#2693) ## Description This PR achieves the following goals: - Extend the simple p2p connection tests of #2679 with more comprehensive tests involving block signature and propagation (a follow PR will add the cases for higher block versions, it requires updating the rollup config with hardfork times) - Fixes the network bootstrap logic to remove flakiness. In particular, it uses kernel allocated ports for discovery/gossip to avoid static modification races. - It adds random valid block building logic
Description
This PR achieves the following goals: