-
Notifications
You must be signed in to change notification settings - Fork 215
Equivalent messages filter on consensus topic #5666
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
Changes from 1 commit
0e51612
b18146b
901309d
0f793fe
0babda5
d4e7634
cba26d3
1ba03ab
71ce841
7bf2591
57072fa
918f099
c9fe2aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -398,8 +398,10 @@ func (wrk *Worker) ProcessReceivedMessage(message p2p.MessageP2P, fromConnectedP | |
|
|
||
| msgType := consensus.MessageType(cnsMsg.MsgType) | ||
|
|
||
| err = wrk.processEquivalentMessage(msgType, cnsMsg.BlockHeaderHash) | ||
| wrk.mutEquivalentMessages.Lock() | ||
| err = wrk.processEquivalentMessageUnprotected(msgType, cnsMsg.BlockHeaderHash) | ||
| if err != nil { | ||
| wrk.mutEquivalentMessages.Unlock() | ||
| return err | ||
| } | ||
|
|
||
|
|
@@ -413,9 +415,11 @@ func (wrk *Worker) ProcessReceivedMessage(message p2p.MessageP2P, fromConnectedP | |
|
|
||
| err = wrk.consensusMessageValidator.checkConsensusMessageValidity(cnsMsg, message.Peer()) | ||
| if err != nil { | ||
| wrk.processInvalidEquivalentMessage(msgType, cnsMsg.BlockHeaderHash) | ||
| wrk.processInvalidEquivalentMessageUnprotected(msgType, cnsMsg.BlockHeaderHash) | ||
| wrk.mutEquivalentMessages.Unlock() | ||
| return err | ||
| } | ||
| wrk.mutEquivalentMessages.Unlock() | ||
|
|
||
| wrk.networkShardingCollector.UpdatePeerIDInfo(message.Peer(), cnsMsg.PubKey, wrk.shardCoordinator.SelfId()) | ||
|
|
||
|
|
@@ -729,17 +733,14 @@ func (wrk *Worker) ResetConsensusMessages() { | |
| wrk.consensusMessageValidator.resetConsensusMessages() | ||
| } | ||
|
|
||
| func (wrk *Worker) processEquivalentMessage(msgType consensus.MessageType, blockHeaderHash []byte) error { | ||
| func (wrk *Worker) processEquivalentMessageUnprotected(msgType consensus.MessageType, blockHeaderHash []byte) error { | ||
| // early exit if the message is not with final info | ||
| if !wrk.consensusService.IsMessageWithFinalInfo(msgType) { | ||
| return nil | ||
| } | ||
|
|
||
| hdrHash := string(blockHeaderHash) | ||
|
|
||
| wrk.mutEquivalentMessages.Lock() | ||
| defer wrk.mutEquivalentMessages.Unlock() | ||
|
|
||
| // if an equivalent message was seen before, return error to stop further broadcasts | ||
|
||
| numMessages := wrk.equivalentMessages[hdrHash] | ||
AdoAdoAdo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| wrk.equivalentMessages[hdrHash] = numMessages + 1 | ||
|
|
@@ -750,16 +751,13 @@ func (wrk *Worker) processEquivalentMessage(msgType consensus.MessageType, block | |
| return nil | ||
| } | ||
|
|
||
| func (wrk *Worker) processInvalidEquivalentMessage(msgType consensus.MessageType, blockHeaderHash []byte) { | ||
| func (wrk *Worker) processInvalidEquivalentMessageUnprotected(msgType consensus.MessageType, blockHeaderHash []byte) { | ||
| if !wrk.consensusService.IsMessageWithFinalInfo(msgType) { | ||
| return | ||
| } | ||
|
|
||
| hdrHash := string(blockHeaderHash) | ||
|
|
||
| wrk.mutEquivalentMessages.Lock() | ||
| defer wrk.mutEquivalentMessages.Unlock() | ||
|
|
||
| delete(wrk.equivalentMessages, hdrHash) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think this is the proper way to do this.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pushed |
||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this solves the problem, hopefully, as it will only call once
checkConsensusMessageValidityper round if the messages are correct and there are no edge cases of multiple broadcasts or message misses I've talked about.However, I would extract L401-L422 in a new function:
checkValidityAndProcessEquivalentMessagesand use the defer mechanism for the mutex unlockingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated as suggested