Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[p2p] higher weight to process node messages #3227

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ const (
GlobalRxWorkers = 32
// MsgChanBuffer is the buffer of consensus message handlers.
MsgChanBuffer = 1024
// WeightConsensus is the weight of semaphore for consensus messages
WeightConsensus = 1
// WeightNode is the weight of semaphore for node messages (tx)
WeightNode = 64
)

const (
Expand Down Expand Up @@ -511,6 +515,7 @@ func (node *Node) Start() error {
handleE p2pHandlerElse
handleEArg []byte
senderPubKey *bls.SerializedPublicKey
msgWeight int64
}

isThisNodeAnExplorerNode := node.NodeConfig.Role() == nodeconfig.ExplorerNode
Expand Down Expand Up @@ -575,6 +580,7 @@ func (node *Node) Start() error {
handleC: node.Consensus.HandleMessageUpdate,
handleCArg: validMsg,
senderPubKey: senderPubKey,
msgWeight: int64(WeightConsensus),
}
return libp2p_pubsub.ValidationAccept

Expand All @@ -584,6 +590,7 @@ func (node *Node) Start() error {
consensusBound: false,
handleE: node.HandleNodeMessage,
handleEArg: openBox,
msgWeight: int64(WeightNode),
}
default:
return libp2p_pubsub.ValidationIgnore
Expand Down Expand Up @@ -625,8 +632,8 @@ func (node *Node) Start() error {
go func() {
defer cancel()

if sem.TryAcquire(1) {
defer sem.Release(1)
if sem.TryAcquire(msg.msgWeight) {
defer sem.Release(msg.msgWeight)

if msg.consensusBound {
if isThisNodeAnExplorerNode {
Expand Down