-
Notifications
You must be signed in to change notification settings - Fork 197
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
Fix invalid signers message broadcast on multikey #5817
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3ffb1df
send invalid signers from leader
sstanculeanu aaa62e1
redundancy node should not send invalid signers
sstanculeanu 53ad9b3
fixed tests
sstanculeanu 2b34ce7
fix after review
sstanculeanu 3121214
fixes after review
sstanculeanu 624cbd5
Merge branch 'rc/sirius-patch-2' into fix_multikey_invalid_signers
sstanculeanu d5d23aa
Merge branch 'rc/sirius-patch-2' into fix_multikey_invalid_signers
sstanculeanu File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1322,7 +1322,7 @@ func TestSubroundEndRound_ReceivedInvalidSignersInfo(t *testing.T) { | |
assert.False(t, res) | ||
}) | ||
|
||
t.Run("received message for self leader", func(t *testing.T) { | ||
t.Run("received message from self leader should return false", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
container := mock.InitConsensusCore() | ||
|
@@ -1339,6 +1339,53 @@ func TestSubroundEndRound_ReceivedInvalidSignersInfo(t *testing.T) { | |
assert.False(t, res) | ||
}) | ||
|
||
t.Run("received message from self multikey leader should return false", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
container := mock.InitConsensusCore() | ||
keysHandler := &testscommon.KeysHandlerStub{ | ||
IsKeyManagedByCurrentNodeCalled: func(pkBytes []byte) bool { | ||
return string(pkBytes) == "A" | ||
}, | ||
} | ||
ch := make(chan bool, 1) | ||
consensusState := initConsensusStateWithKeysHandler(keysHandler) | ||
sr, _ := spos.NewSubround( | ||
bls.SrSignature, | ||
bls.SrEndRound, | ||
-1, | ||
int64(85*roundTimeDuration/100), | ||
int64(95*roundTimeDuration/100), | ||
"(END_ROUND)", | ||
consensusState, | ||
ch, | ||
executeStoredMessages, | ||
container, | ||
chainID, | ||
currentPid, | ||
&statusHandler.AppStatusHandlerStub{}, | ||
) | ||
|
||
srEndRound, _ := bls.NewSubroundEndRound( | ||
sr, | ||
extend, | ||
bls.ProcessingThresholdPercent, | ||
displayStatistics, | ||
&statusHandler.AppStatusHandlerStub{}, | ||
&mock.SentSignatureTrackerStub{}, | ||
) | ||
|
||
srEndRound.SetSelfPubKey("A") | ||
|
||
cnsData := consensus.Message{ | ||
BlockHeaderHash: []byte("X"), | ||
PubKey: []byte("A"), | ||
} | ||
|
||
res := srEndRound.ReceivedInvalidSignersInfo(&cnsData) | ||
assert.False(t, res) | ||
}) | ||
|
||
t.Run("received hash does not match the hash from current consensus state", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
|
@@ -1556,29 +1603,56 @@ func TestVerifyInvalidSigners(t *testing.T) { | |
func TestSubroundEndRound_CreateAndBroadcastInvalidSigners(t *testing.T) { | ||
t.Parallel() | ||
|
||
wg := &sync.WaitGroup{} | ||
wg.Add(1) | ||
t.Run("redundancy node should not send", func(t *testing.T) { | ||
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. "redundancy node should not send while the main is active" |
||
t.Parallel() | ||
|
||
expectedInvalidSigners := []byte("invalid signers") | ||
expectedInvalidSigners := []byte("invalid signers") | ||
|
||
wasCalled := false | ||
container := mock.InitConsensusCore() | ||
messenger := &mock.BroadcastMessengerMock{ | ||
BroadcastConsensusMessageCalled: func(message *consensus.Message) error { | ||
wg.Done() | ||
assert.Equal(t, expectedInvalidSigners, message.InvalidSigners) | ||
wasCalled = true | ||
return nil | ||
}, | ||
} | ||
container.SetBroadcastMessenger(messenger) | ||
sr := *initSubroundEndRoundWithContainer(container, &statusHandler.AppStatusHandlerStub{}) | ||
container := mock.InitConsensusCore() | ||
nodeRedundancy := &mock.NodeRedundancyHandlerStub{ | ||
IsRedundancyNodeCalled: func() bool { | ||
return true | ||
}, | ||
} | ||
container.SetNodeRedundancyHandler(nodeRedundancy) | ||
messenger := &mock.BroadcastMessengerMock{ | ||
BroadcastConsensusMessageCalled: func(message *consensus.Message) error { | ||
assert.Fail(t, "should have not been called") | ||
return nil | ||
}, | ||
} | ||
container.SetBroadcastMessenger(messenger) | ||
sr := *initSubroundEndRoundWithContainer(container, &statusHandler.AppStatusHandlerStub{}) | ||
|
||
sr.CreateAndBroadcastInvalidSigners(expectedInvalidSigners) | ||
}) | ||
t.Run("should work", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
wg := &sync.WaitGroup{} | ||
wg.Add(1) | ||
|
||
expectedInvalidSigners := []byte("invalid signers") | ||
|
||
wasCalled := false | ||
container := mock.InitConsensusCore() | ||
messenger := &mock.BroadcastMessengerMock{ | ||
BroadcastConsensusMessageCalled: func(message *consensus.Message) error { | ||
wg.Done() | ||
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. can you do the wg.Done after the wasCalled = true? |
||
assert.Equal(t, expectedInvalidSigners, message.InvalidSigners) | ||
wasCalled = true | ||
return nil | ||
}, | ||
} | ||
container.SetBroadcastMessenger(messenger) | ||
sr := *initSubroundEndRoundWithContainer(container, &statusHandler.AppStatusHandlerStub{}) | ||
|
||
sr.CreateAndBroadcastInvalidSigners(expectedInvalidSigners) | ||
sr.CreateAndBroadcastInvalidSigners(expectedInvalidSigners) | ||
|
||
wg.Wait() | ||
wg.Wait() | ||
|
||
require.True(t, wasCalled) | ||
require.True(t, wasCalled) | ||
}) | ||
} | ||
|
||
func TestGetFullMessagesForInvalidSigners(t *testing.T) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can we change the condition to
would be easier to read