Skip to content

Commit

Permalink
chore: use pow for bsc p2p example (paradigmxyz#13380)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored and emhane committed Dec 13, 2024
1 parent 4933f42 commit 7252ef0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/net/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ impl<N: NetworkPrimitives> NetworkConfigBuilder<N> {
self
}

/// Configures the network to use proof-of-work.
///
/// This effectively allows block propagation in the `eth` sub-protocol, which has been
/// soft-deprecated with ethereum `PoS` after the merge. Even if block propagation is
/// technically allowed, according to the eth protocol, it is not expected to be used in `PoS`
/// networks and peers are supposed to terminate the connection if they receive a `NewBlock`
/// message.
pub const fn with_pow(self) -> Self {
self.network_mode(NetworkMode::Work)
}

/// Sets the highest synced block.
///
/// This is used to construct the appropriate [`ForkFilter`] and [`Status`] message.
Expand Down
2 changes: 2 additions & 0 deletions examples/bsc-p2p/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ async fn main() {
// The network configuration
let mut net_cfg = NetworkConfig::builder(secret_key)
.listener_addr(local_addr)
// we need to explicitly set the network mode to PoW to allow block propagation, see docs
.with_pow()
.build_with_noop_provider(bsc_chain_spec())
.set_discovery_v4(
Discv4ConfigBuilder::default()
Expand Down

0 comments on commit 7252ef0

Please sign in to comment.