Skip to content
Draft
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
44 changes: 37 additions & 7 deletions consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,27 @@
}

func validatePrevote(t *testing.T, cs *State, round int32, privVal *validatorStub, blockHash []byte) {
cs.rsMtx.RLock()
prevotes := cs.rs.Votes.Prevotes(round)
cs.rsMtx.RUnlock()
pubKey, err := privVal.GetPubKey()
require.NoError(t, err)
address := pubKey.Address()

Check failure on line 280 in consensus/common_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gofmt)

Check failure on line 280 in consensus/common_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gofmt)
// Simple retry logic to handle race condition
var vote *types.Vote
if vote = prevotes.GetByAddress(address); vote == nil {
for i := 0; i < 30; i++ {
rs := cs.GetRoundState()
prevotes := rs.Votes.Prevotes(round)
vote = prevotes.GetByAddress(address)

if vote != nil {
break
}

if i < 29 {
time.Sleep(2 * time.Millisecond)
}
}

if vote == nil {
panic("Failed to find prevote from validator")
}
if blockHash == nil {
Expand All @@ -295,6 +308,8 @@
}
}



Comment on lines +311 to +312
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these don't seem intentional

Suggested change

func validateLastPrecommit(t *testing.T, cs *State, privVal *validatorStub, blockHash []byte) {
cs.rsMtx.RLock()
votes := cs.rs.LastCommit
Expand All @@ -320,12 +335,28 @@
votedBlockHash,
lockedBlockHash []byte,
) {
precommits := cs.rs.Votes.Precommits(thisRound)
pv, err := privVal.GetPubKey()
require.NoError(t, err)
address := pv.Address()

// Simple retry logic to handle race condition
var vote *types.Vote
if vote = precommits.GetByAddress(address); vote == nil {
var rs *cstypes.RoundState
for i := 0; i < 30; i++ {
rs = cs.GetRoundState()
precommits := rs.Votes.Precommits(thisRound)
vote = precommits.GetByAddress(address)

if vote != nil {
break
}

if i < 29 {
time.Sleep(2 * time.Millisecond)
}
}

if vote == nil {
panic("Failed to find precommit from validator")
}

Expand All @@ -339,7 +370,6 @@
}
}

rs := cs.GetRoundState()
if lockedBlockHash == nil {
if rs.LockedRound != lockRound || rs.LockedBlock != nil {
panic(fmt.Sprintf(
Expand Down
Loading