Skip to content

fix: Incorrect P2PContext in bcast example#347

Merged
emlautarom1 merged 1 commit into
mainfrom
emlautarom1/fix-bcast-example
Apr 21, 2026
Merged

fix: Incorrect P2PContext in bcast example#347
emlautarom1 merged 1 commit into
mainfrom
emlautarom1/fix-bcast-example

Conversation

@emlautarom1
Copy link
Copy Markdown
Collaborator

The bcast example (https://github.com/NethermindEth/pluto/blob/c4c922a19c0efc29baf882d3ed438e4ccdc73f82/crates/dkg/examples/bcast.rs) is currently broken due to the usage of an incorrect P2PContext which results in active connections to known peers not getting updated, thus failing to broadcast despite the connections actually being active.

This PR implements the minimal fix required to sort out the issue, but some comments are included to avoid similar situations in the future.

.await
.expect("Failed to register demo bcast message");

let mut component = None;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This handle approach is similar to what we have in parsigex: #291 (comment).

The design is very cumbersome to use so it requires some further work.

args.filter_private_addrs,
known_peers,
|builder, keypair, relay_client| {
let p2p_context = builder.p2p_context();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can you try to remove this and use the outer p2p_context, that will be cleaner without having the mut component

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We can, I was just following the patterns that we already have in bootnode and parsigex:

let mut node: Node<ExampleBehaviour> = Node::new(
p2p_config,
pk,
NodeType::QUIC,
false,
known_peers.clone(),
|builder, keypair, relay_client| {
let p2p_context = builder.p2p_context();
let local_peer_id = keypair.public().to_peer_id();
// Create identify config
let identify_config =
identify::Config::new("/charon/1.0.0".to_string(), keypair.public());
builder.with_gater(conn_gater).with_inner(ExampleBehaviour {
relay: relay_client,
relay_reservation: MutableRelayReservation::new(relays.clone()),
relay_router: RelayRouter::new(relays.clone(), p2p_context, local_peer_id),
identify: identify::Behaviour::new(identify_config),
ping: ping::Behaviour::new(ping::Config::new()),
})
},
)?;

let mut parsigex_handle: Option<Handle> = None;
let mut node: Node<CombinedBehaviour> = Node::new(
p2p_config,
key,
NodeType::QUIC,
args.filter_private_addrs,
known_peers.clone(),
|builder, keypair, relay_client| {
let p2p_context = builder.p2p_context();
let local_peer_id = keypair.public().to_peer_id();
let config = parsigex::Config::new(
local_peer_id,
p2p_context.clone(),
verifier.clone(),
duty_gater.clone(),
)
.with_timeout(Duration::from_secs(10));
let (parsigex, handle) = parsigex::Behaviour::new(config);
parsigex_handle = Some(handle);
builder
.with_gater(conn_gater)
.with_inner(CombinedBehaviour {
parsigex,
relay: relay_client,
relay_reservation: MutableRelayReservation::new(relays.clone()),
relay_router: RelayRouter::new(relays.clone(), p2p_context, local_peer_id),
})
},
)?;
let parsigex_handle =
parsigex_handle.ok_or_else(|| anyhow!("parsigex handle should be created"))?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe we will revisit these examples to see if we can have a cleaner approach. LGTM now

);
print_cluster_overview(&cluster_info);

let mut connected_cluster_peers = HashSet::<PeerId>::new();
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This set duplicates the information that P2PContext and its PeerStore already manage. ClusterInfo is in the same situation, where pretty much all information is duplicated in some way.

@emlautarom1 emlautarom1 merged commit 3b234a0 into main Apr 21, 2026
20 checks passed
@emlautarom1 emlautarom1 deleted the emlautarom1/fix-bcast-example branch April 21, 2026 19:20
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