Skip to content

refactor(p2p): not allow builder to set p2p_context#348

Merged
iamquang95 merged 4 commits intomainfrom
iamquang95/remove-default-p2pcontext-v2
Apr 24, 2026
Merged

refactor(p2p): not allow builder to set p2p_context#348
iamquang95 merged 4 commits intomainfrom
iamquang95/remove-default-p2pcontext-v2

Conversation

@iamquang95
Copy link
Copy Markdown
Collaborator

This fixes a P2PContext ownership misuseAPI in the P2P builder flow.

Previously, Node::new created a P2PContext internally while callers could also create one externally and PlutoBehaviourBuilder could overwrite it again. That made it possible for Node, PlutoBehaviour, and inner behaviours to accidentally use different contexts.

This change makes P2PContext an explicit constructor input to Node::new / Node::new_server, removes with_p2p_context from the builder, and moves local peer binding into Node.

Benefit: one node now has one authoritative shared P2PContext, making the API safer and preventing split state between node-level and behaviour-level components.

@emlautarom1
Copy link
Copy Markdown
Collaborator

Looks like a reasonable solution, 👍

Copy link
Copy Markdown
Collaborator

@varex83 varex83 left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment thread crates/relay-server/src/p2p.rs Outdated
let relay_config = create_relay_config(config);
// Relay servers don't track cluster peers - they serve all connections
let known_peers: Vec<libp2p::PeerId> = vec![];
let p2p_context = P2PContext::default();
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.

I think you can inline this into new_server function

@iamquang95 iamquang95 marked this pull request as ready for review April 24, 2026 02:48
@iamquang95 iamquang95 merged commit 37de823 into main Apr 24, 2026
12 checks passed
@iamquang95 iamquang95 deleted the iamquang95/remove-default-p2pcontext-v2 branch April 24, 2026 03:09
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