p2p: support new msg broadcast features;#3043
Conversation
|
need a better var name than |
29675a6 to
683cc58
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR implements new peer-to-peer broadcast features and related configuration updates to support a more efficient message propagation mechanism for block and vote messages between validators. The key changes include adding new configuration fields for direct broadcast and proxied validator lists, updating peer and handler logic in both the P2P and ETH subsystems to handle these new features, and extending system contract upgrade mechanisms with the maxwell upgrade details.
Reviewed Changes
Copilot reviewed 19 out of 22 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| p2p/enode/node.go | Added parsing for V4 public key to support new node ID formation. |
| p2p/enode/idscheme.go | Introduced V4NodeIDFromPublicKey to generate node IDs from public keys. |
| p2p/config_toml.go, p2p/config.go | Extended configuration with DirectBroadcastList and ProxyedValidatorList. |
| node/config.go | Added EnableBroadcastFeatures flag to node config. |
| eth/protocols/eth/peer.go | Exposed NodeID method on Peer for use in broadcast logic. |
| eth/peerset*.go, eth/peerset_test.go | Updated peer set logic along with comprehensive tests for new features. |
| eth/handler.go | Integrated broadcast feature flags and peer selection adjustments. |
| eth/ethconfig/* and eth/backend.go | Updated configuration marshalling and shutdown handling to reflect new P2P fields. |
| consensus/parlia/* | Extended StakeHub and ABI definitions to accommodate new validator node ID support. |
| core/systemcontracts/upgrade.go | Added maxwell upgrade entries as part of the system contract upgrade suite. |
Files not reviewed (3)
- core/systemcontracts/maxwell/chapel/StakeHubContract: Language not supported
- core/systemcontracts/maxwell/mainnet/StakeHubContract: Language not supported
- core/systemcontracts/maxwell/rialto/StakeHubContract: Language not supported
Comments suppressed due to low confidence (1)
p2p/config_toml.go:34
- [nitpick] Consider renaming 'ProxyedValidatorList' to 'ProxiedValidatorList' for clarity and consistency with standard spelling.
ProxyedValidatorList []enode.ID `toml:",omitempty"`
MatusKysel
left a comment
There was a problem hiding this comment.
except inefficiencies with slices it's all good
chore: renaming some vars & fields;
There was a problem hiding this comment.
Pull Request Overview
This PR implements new message broadcast features for the p2p network including enhanced direct broadcasting and specialized handling for transaction propagation for validators. Key changes include:
- New atomic flags in the Peer struct for full, direct, and no-tx broadcast modes.
- Updates to enode, config, and handler modules to support broadcast feature configuration.
- Modifications to node configuration and chain command logic to integrate the new broadcast mechanisms.
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| p2p/peer.go | Adds new atomic flags for various broadcast modes |
| p2p/enode/idscheme.go | Introduces V4NodeIDFromPublicKey for V4 public key processing |
| p2p/config_toml.go | Adds new configuration fields for broadcast features |
| p2p/config.go | Updates configuration struct with broadcast node IDs |
| node/config.go | Adds new flag EnableBroadcastFeatures with documentation |
| eth/handler.go | Integrates broadcast features in block propagation logic |
| eth/peerset.go | Updates peer set enabling broadcast features |
| cmd/geth/chaincmd.go | Adjusts node configuration creation to support sentry nodes |
Comments suppressed due to low confidence (1)
p2p/config_toml.go:34
- [nitpick] Consider renaming 'ProxyedValidatorNodeIDs' to 'ProxiedValidatorNodeIDs' for improved clarity and consistency with standard English usage.
ProxyedValidatorNodeIDs []enode.ID `toml:",omitempty"`
| // EnableBroadcastFeatures enable directly broadcast feature + no tx broadcast feature, | ||
| // it mainly used for validators, the validators can be recognized by StakHub contract | ||
| // Notice: validator, sentryNode need to set this flag to true. |
There was a problem hiding this comment.
[nitpick] Consider revising the comment for clarity and correct grammar, e.g., 'Used mainly for validators, which can be recognized by the StakHub contract. Note: Validator and sentry nodes need to set this flag to true.'
| // EnableBroadcastFeatures enable directly broadcast feature + no tx broadcast feature, | |
| // it mainly used for validators, the validators can be recognized by StakHub contract | |
| // Notice: validator, sentryNode need to set this flag to true. | |
| // EnableBroadcastFeatures enables the direct broadcast feature and disables the transaction broadcast feature. | |
| // Used mainly for validators, which can be recognized by the StakHub contract. | |
| // Note: Validator and sentry nodes need to set this flag to true. |
| EnableBroadcastFeatures bool | ||
| DirectBroadcastNodeIDs []enode.ID | ||
| ProxyedValidatorNodeIDs []enode.ID | ||
| } |
There was a problem hiding this comment.
how about rename:
ProxyedValidatorNodeIDs => ValidatorNodeIDs
DirectBroadcastNodeIDs => EVNNodeIdsWhitelist // (EVN = Enhanced Validator Network)
| } | ||
| for _, peer := range ps.peers { | ||
| nodeID := peer.NodeID() | ||
| if slices.Contains(directNodeIDs, nodeID) || slices.Contains(proxyedNodeIDs, nodeID) { |
There was a problem hiding this comment.
direct broadcast only for proxyedNodeIDs?
directNodeIDs is for EVNWhilteList, right?
There was a problem hiding this comment.
It's necessary to EnableDirectBroadcast for proxyedNodeIDs IMO
| EventMux: eth.eventMux, | ||
| RequiredBlocks: config.RequiredBlocks, | ||
| DirectBroadcast: config.DirectBroadcast, | ||
| EnableBroadcastFeatures: stack.Config().EnableBroadcastFeatures, |
There was a problem hiding this comment.
how about rename
EnableBroadcastFeatures --> EnableEVNBroadcastFeatures?
| if !ok { | ||
| return false | ||
| } | ||
| if parlia.ConsensusAddress() == block.Coinbase() { |
There was a problem hiding this comment.
check mining, maybe It's a backup validator.
There was a problem hiding this comment.
It's ok, the backup validator won't produce block. Here only block producer need full broadcast to all other validators.
| active++ | ||
| case <-h.handlerDoneCh: | ||
| active-- | ||
| case <-updateTicker.C: |
There was a problem hiding this comment.
why use a periodical timer here?
| broadcastChecker := func(peer *ethPeer) bool { | ||
| return peer.EnableDirectBroadcast.Load() | ||
| } | ||
| if h.needMoreDirectBroadcastPeers(block) { | ||
| log.Debug("needMoreDirectBroadcastPeers", "number", block.NumberU64(), "hash", block.Hash()) | ||
| broadcastChecker = func(peer *ethPeer) bool { | ||
| return peer.EnableDirectBroadcast.Load() || peer.EnableFullBroadcast.Load() | ||
| } | ||
| } | ||
|
|
||
| var morePeers []*ethPeer | ||
| for i := len(transfer); i < len(peers); i++ { | ||
| if broadcastChecker(peers[i]) { | ||
| log.Debug("add extra direct broadcast peer", "peer", peers[i].ID()) | ||
| morePeers = append(morePeers, peers[i]) | ||
| } | ||
| } | ||
| for _, peer := range morePeers { | ||
| peer.AsyncSendNewBlock(block, td) | ||
| } |
There was a problem hiding this comment.
better to refactor this code to make it more readable.
| } | ||
| for _, peer := range ps.peers { | ||
| nodeID := peer.NodeID() | ||
| if slices.Contains(directNodeIDs, nodeID) || slices.Contains(proxyedNodeIDs, nodeID) { |
There was a problem hiding this comment.
| if slices.Contains(directNodeIDs, nodeID) || slices.Contains(proxyedNodeIDs, nodeID) { | |
| if slices.Contains(proxyedNodeIDs, nodeID) { |
| peer.EnableDirectBroadcast.Store(true) | ||
| } | ||
| _, isValNodeID := valNodeIDMap[nodeID] | ||
| if isValNodeID { |
There was a problem hiding this comment.
| if isValNodeID { | |
| if isValNodeID || slices.Contains(directNodeIDs, nodeID) { |
| } | ||
| // if the peer is in the valNodeIDs and not in the proxyedList, enable the no tx broadcast feature | ||
| // the node also need to forward tx to the proxyedList | ||
| if isValNodeID && !slices.Contains(proxyedNodeIDs, nodeID) { |
There was a problem hiding this comment.
1.Add a warning if validator configure it self as EVN node.
2.In the future: to check itself whether belong to EnhancedValidatorNetwork or not.
| peer.EnableFullBroadcast.Store(true) | ||
| } | ||
| // if the peer is in the valNodeIDs and not in the proxyedList, enable the no tx broadcast feature | ||
| // the node also need to forward tx to the proxyedList |
There was a problem hiding this comment.
| // the node also need to forward tx to the proxyedList | |
| // the node also need to forward tx to the proxyedList | |
| if slices.Contains(proxyedNodeIDs, nodeID) { | |
| log.Warn("validator Nodeid is registerred", "id", nodeID) | |
| } |
Description
This PR aims to implement the msg broadcast mechanism of bnb-chain/BEPs#563.
For Message Propagation
Some connection features will be enabled between validators to optimize network congestion and reduce message latency.
It will make a more stable network between validators. It also allows adding more normal nodes in
DirectBroadcastList.Example
You should set the config as below:
Changes
Notable changes: