Skip to content
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

chore: use pow for bsc p2p example #13380

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading