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

Fix invalid signers message broadcast on multikey #5817

Merged
merged 7 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions consensus/spos/bls/subroundEndRound.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
return false
}

if sr.IsSelfLeaderInCurrentRound() {
if sr.IsSelfLeaderInCurrentRound() || sr.IsMultiKeyLeaderInCurrentRound() {
return false
}

Expand Down Expand Up @@ -589,20 +589,26 @@
}

func (sr *subroundEndRound) createAndBroadcastInvalidSigners(invalidSigners []byte) {
leader, errGetLeader := sr.GetLeader()
AdoAdoAdo marked this conversation as resolved.
Show resolved Hide resolved
if errGetLeader != nil {
log.Debug("createAndBroadcastInvalidSigners.GetLeader", "error", errGetLeader)
return

Check warning on line 595 in consensus/spos/bls/subroundEndRound.go

View check run for this annotation

Codecov / codecov/patch

consensus/spos/bls/subroundEndRound.go#L594-L595

Added lines #L594 - L595 were not covered by tests
}

cnsMsg := consensus.NewConsensusMessage(
sr.GetData(),
nil,
nil,
nil,
[]byte(sr.SelfPubKey()),
[]byte(leader),
nil,
int(MtInvalidSigners),
sr.RoundHandler().Index(),
sr.ChainID(),
nil,
nil,
nil,
sr.CurrentPid(),
sr.GetAssociatedPid([]byte(leader)),
invalidSigners,
)

Expand Down
49 changes: 48 additions & 1 deletion consensus/spos/bls/subroundEndRound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()

Expand Down