Skip to content

network: hybrid networking#5800

Merged
cce merged 8 commits intofeature/p2pfrom
hybrid-p2p
Nov 14, 2023
Merged

network: hybrid networking#5800
cce merged 8 commits intofeature/p2pfrom
hybrid-p2p

Conversation

@cce
Copy link
Copy Markdown
Contributor

@cce cce commented Oct 24, 2023

WIP draft PR for GossipNode implementation that combines WebsocketNetwork and P2PNetwork.

Comment thread network/p2p/p2p.go
libp2p.Muxer("/yamux/1.0.0", &ymx),
libp2p.Peerstore(pstore),
libp2p.ListenAddrStrings(listenAddr),
libp2p.Security(noise.ID, noise.New),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it does not look used except adding a new endpoint here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is setting the configuration for libp2p transport, making explicit more of the default configuration we are relying on (and also disabling TLS 1.3 which is a second-priority fallback by default). It is also possible to configure no encryption at all (like wsNetwork currently uses) and expose that as a config option — we could revisit if we want to consider that for performance reasons.

Comment thread config/localTemplate.go
EnableP2P bool `version[31]:"false"`

// EnableP2PHybridMode turns on both websockets and P2P networking.
EnableP2PHybridMode bool `version[31]:"false"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

move to v32, v31 was released a few days ago

Comment thread network/hybridNetwork.go Outdated
Comment thread network/hybridNetwork.go
Comment thread network/hybridNetwork.go

// Broadcast implements GossipNode
func (n *HybridP2PNetwork) Broadcast(ctx context.Context, tag protocol.Tag, data []byte, wait bool, except Peer) error {
return n.runParallel(func(net GossipNode) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shouldn't we limit type of traffic broadcasted with p2p in hybrid mode? I'm afraid of xN bandwidth increase

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm assuming there is a constant number of peers "out there", so there wouldn't just x2 rather than a shifting / splitting of existing bandwidth amounts between different transport/connection types. We will also be able to set limits for total # of connections for each network type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree about a constant number of peers, but I think we'd still need logic to prevent peers from "doubling up" and connecting to each other over both networks. If that logic's in this PR I haven't identified it yet

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 25, 2023

Codecov Report

Merging #5800 (5db8ed6) into master (c4e94fe) will decrease coverage by 0.11%.
Report is 3 commits behind head on master.
The diff coverage is 20.62%.

@@            Coverage Diff             @@
##           master    #5800      +/-   ##
==========================================
- Coverage   55.57%   55.47%   -0.11%     
==========================================
  Files         475      476       +1     
  Lines       66838    67006     +168     
==========================================
+ Hits        37147    37171      +24     
- Misses      27172    27320     +148     
+ Partials     2519     2515       -4     
Files Coverage Δ
catchup/ledgerFetcher.go 53.09% <100.00%> (ø)
config/localTemplate.go 72.02% <ø> (ø)
node/follower_node.go 45.16% <100.00%> (ø)
rpcs/blockService.go 73.20% <100.00%> (-1.14%) ⬇️
rpcs/httpTxSync.go 50.00% <100.00%> (ø)
network/gossipNode.go 76.47% <0.00%> (-10.20%) ⬇️
network/wsPeer.go 70.74% <0.00%> (-2.13%) ⬇️
network/netidentity.go 97.14% <77.77%> (-2.86%) ⬇️
network/p2p/p2p.go 12.34% <0.00%> (-0.65%) ⬇️
node/node.go 22.44% <14.28%> (-0.16%) ⬇️
... and 4 more

... and 13 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment thread network/p2pNetwork.go
func (n *P2PNetwork) txTopicValidator(ctx context.Context, peerID peer.ID, msg *pubsub.Message) pubsub.ValidationResult {
inmsg := IncomingMessage{
Sender: msg.ReceivedFrom,
Sender: gossipSubPeer{peerID: msg.ReceivedFrom, net: n},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you know if msg.ReceivedFrom will be the same as the peerID argument?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh good point. I'm not sure but for this case I think it is best to use the peerID, not the ReceivedFrom.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

AFAICT in go-libp2p-pubsub pubsub.go it sets peer ID to msg.ReceivedFrom (in pushMsg and PushLocal) when calling the validators. Odd.

Comment thread network/hybridNetwork.go
Comment thread network/hybridNetwork.go

// Broadcast implements GossipNode
func (n *HybridP2PNetwork) Broadcast(ctx context.Context, tag protocol.Tag, data []byte, wait bool, except Peer) error {
return n.runParallel(func(net GossipNode) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree about a constant number of peers, but I think we'd still need logic to prevent peers from "doubling up" and connecting to each other over both networks. If that logic's in this PR I haven't identified it yet

Copy link
Copy Markdown
Contributor

@algorandskiy algorandskiy left a comment

Choose a reason for hiding this comment

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

This implementations allows node to run on both p2p and ws networks, and appears to be missing stage 1 restrictions for using p2p for discovery only. @cce please comment

@cce cce changed the base branch from master to feature/p2p November 7, 2023 16:37
@cce cce marked this pull request as ready for review November 14, 2023 23:54
@cce
Copy link
Copy Markdown
Contributor Author

cce commented Nov 14, 2023

Merging to feature/p2p, even though this doesn't yet support for using the identityTracker to prevent duplicate connections to the same peer ID on both networks — will follow in a future PR on the feature branch.

@cce cce merged commit b6f8a69 into feature/p2p Nov 14, 2023
@cce cce deleted the hybrid-p2p branch November 14, 2023 23:56
@algorandskiy algorandskiy added the p2p Work related to the p2p project label Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement p2p Work related to the p2p project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants