-
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
Equivalent messages filter on consensus topic #5666
Conversation
consensus/spos/interface.go
Outdated
|
|
||
| // EquivalentMessagesDebugger defines the specific debugger for equivalent messages | ||
| type EquivalentMessagesDebugger interface { | ||
| DisplayEquivalentMessagesStatistics(getDataHandler func() map[string]uint64) |
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.
let's make the signature more straightforward. Why not declare the function like
DisplayEquivalentMessagesStatistics(messages map[string]uint64)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.
I tried to avoid copying the map when we don't need the log.. with the function pointer approach, it is copied only when the debugger is active
consensus/spos/worker.go
Outdated
| wrk.mutEquivalentMessages.Lock() | ||
| defer wrk.mutEquivalentMessages.Unlock() | ||
|
|
||
| // if an equivalent message was seen before, return error to stop further broadcasts |
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.
slightly optimization for L743 - L49
numMessages := wrk.equivalentMessages[hdrHash]
wrk.equivalentMessages[hdrHash] = numMessages+1
if numMessages > 0 {
return ErrEquivalentMessageAlreadyReceived
}as this one does one read & one write on the map. The original code does 2 reads & one write
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.
applied
consensus/spos/worker.go
Outdated
| wrk.mutEquivalentMessages.RLock() | ||
| defer wrk.mutEquivalentMessages.RUnlock() | ||
|
|
||
| equivalentMessagesCopy := make(map[string]uint64, len(wrk.equivalentMessages)) |
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.
👍
| equivMsgFrom, | ||
| &p2pmocks.MessengerStub{}, | ||
| ) | ||
| assert.Equal(t, spos.ErrEquivalentMessageAlreadyReceived, err) |
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.
test also the inner counter? Or a special unit test for the reset & read of the counters?
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.
improved the test
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## feat/equivalent-messages #5666 +/- ##
===========================================================
Coverage ? 80.37%
===========================================================
Files ? 712
Lines ? 94410
Branches ? 0
===========================================================
Hits ? 75879
Misses ? 13223
Partials ? 5308 ☔ View full report in Codecov by Sentry. |
| wrk.mutEquivalentMessages.Lock() | ||
| defer wrk.mutEquivalentMessages.Unlock() | ||
|
|
||
| delete(wrk.equivalentMessages, hdrHash) |
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.
I do not think this is the proper way to do this.
Reason: what happens in this scenario?
- receive the correct message
- receive the same block final info but for some reason
checkConsensusMessageValidityreturns an error. We delete the equivalent message for the hdrHash - we receive the correct message again and we re-broadcast it
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.
pushed
consensus/spos/worker.go
Outdated
| msgType := consensus.MessageType(cnsMsg.MsgType) | ||
|
|
||
| err = wrk.processEquivalentMessage(msgType, cnsMsg.BlockHeaderHash) | ||
| wrk.mutEquivalentMessages.Lock() |
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 checkConsensusMessageValidity per 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: checkValidityAndProcessEquivalentMessages and use the defer mechanism for the mutex unlocking
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.
updated as suggested
…nly when necessary + added equivalent message signature verification
…rsx/mx-chain-go into equivalent_messages_filter # Conflicts: # cmd/node/config/enableEpochs.toml # common/enablers/enableEpochsHandler.go # common/enablers/enableEpochsHandler_test.go # common/enablers/epochFlags.go # common/interface.go # config/epochConfig.go # config/tomlConfig_test.go # consensus/spos/bls/blsSubroundsFactory.go # consensus/spos/bls/subroundStartRound.go # consensus/spos/bls/subroundStartRound_test.go # consensus/spos/errors.go # consensus/spos/interface.go # testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go
| line := []string{ | ||
| hash, | ||
| fmt.Sprintf("%d", cnt), | ||
| fmt.Sprintf("%d", info.NumMessages), |
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 will need to display new fields, most importantly if any equivalent proof was validated, can be done on the next PR.
| } | ||
|
|
||
| return nil | ||
| // TODO[Sorin]: after flag enabled, VerifySignature on previous hash, with the signature and bitmap from the proof on cnsMsg |
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.
verify on current header with the signature and bitmap from cnsMsg, but anyway would be removed in next PR.
Reasoning behind the pull request
Proposed changes
Testing procedure
Pre-requisites
Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:
featbranch created?featbranch merging, do all satellite projects have a proper tag insidego.mod?