Skip to content

Comments

p2p: support new msg broadcast features;#3043

Merged
zzzckck merged 9 commits intobnb-chain:developfrom
galaio:new-broadcast
Apr 30, 2025
Merged

p2p: support new msg broadcast features;#3043
zzzckck merged 9 commits intobnb-chain:developfrom
galaio:new-broadcast

Conversation

@galaio
Copy link
Contributor

@galaio galaio commented Apr 22, 2025

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.

  • Transaction: it will not be propagated between validators.
  • Block: it will directly broadcast to all other connected validators in this network.
  • Vote: same as block.

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:

[Node]
EnableBroadcastFeature = true

[Node.P2P]
DirectBroadcastList =["nodeid1", "nodeid2"]

Changes

Notable changes:

  • p2p: support new msg broadcast features;
  • ...

@buddh0
Copy link
Contributor

buddh0 commented Apr 23, 2025

need a better var name than EnableBroadcastFeature,
‘EnableEnhancedBroadcast’ ?

@galaio galaio force-pushed the new-broadcast branch 6 times, most recently from 29675a6 to 683cc58 Compare April 28, 2025 07:15
@MatusKysel MatusKysel requested a review from Copilot April 28, 2025 09:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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"`

Copy link
Contributor

@MatusKysel MatusKysel left a comment

Choose a reason for hiding this comment

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

except inefficiencies with slices it's all good

MatusKysel
MatusKysel previously approved these changes Apr 29, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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"`

Comment on lines +96 to +98
// 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.
Copy link

Copilot AI Apr 29, 2025

Choose a reason for hiding this comment

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

[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.'

Suggested change
// 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.

Copilot uses AI. Check for mistakes.
EnableBroadcastFeatures bool
DirectBroadcastNodeIDs []enode.ID
ProxyedValidatorNodeIDs []enode.ID
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

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) {
Copy link
Collaborator

@zzzckck zzzckck Apr 29, 2025

Choose a reason for hiding this comment

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

direct broadcast only for proxyedNodeIDs?
directNodeIDs is for EVNWhilteList, right?

Copy link
Contributor

@buddh0 buddh0 Apr 30, 2025

Choose a reason for hiding this comment

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

It's necessary to EnableDirectBroadcast for proxyedNodeIDs IMO

EventMux: eth.eventMux,
RequiredBlocks: config.RequiredBlocks,
DirectBroadcast: config.DirectBroadcast,
EnableBroadcastFeatures: stack.Config().EnableBroadcastFeatures,
Copy link
Contributor

Choose a reason for hiding this comment

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

how about rename
EnableBroadcastFeatures --> EnableEVNBroadcastFeatures?

if !ok {
return false
}
if parlia.ConsensusAddress() == block.Coinbase() {
Copy link
Contributor

Choose a reason for hiding this comment

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

check mining, maybe It's a backup validator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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:
Copy link
Collaborator

Choose a reason for hiding this comment

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

why use a periodical timer here?

Comment on lines +829 to +848
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)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if slices.Contains(directNodeIDs, nodeID) || slices.Contains(proxyedNodeIDs, nodeID) {
if slices.Contains(proxyedNodeIDs, nodeID) {

peer.EnableDirectBroadcast.Store(true)
}
_, isValNodeID := valNodeIDMap[nodeID]
if isValNodeID {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// 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)
}

@zzzckck zzzckck merged commit 21f6888 into bnb-chain:develop Apr 30, 2025
7 checks passed
galaio added a commit to galaio/bsc that referenced this pull request May 29, 2025
galaio added a commit to galaio/bsc that referenced this pull request May 29, 2025
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.

4 participants