Skip to content

Commit

Permalink
fix: ensure no new event is send on vote
Browse files Browse the repository at this point in the history
Signed-off-by: gfanton <[email protected]>
  • Loading branch information
gfanton committed Nov 20, 2023
1 parent a96cdc6 commit da521cd
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions tm2/pkg/bft/consensus/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ func TestStateFullRound2(t *testing.T) {
ensurePrevote(voteCh, height, round) // prevote

// we should be stuck in limbo waiting for more prevotes
ensureNoNewEventOnChannel(voteCh)
rs := cs1.GetRoundState()
propBlockHash, propPartsHeader := rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header()

Expand Down Expand Up @@ -442,7 +443,7 @@ func TestStateLockNoPOL(t *testing.T) {

// now we're on a new round and not the proposer, so wait for timeout
ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds())

ensureNoNewEventOnChannel(voteCh)
rs := cs1.GetRoundState()

if rs.ProposalBlock != nil {
Expand All @@ -451,6 +452,7 @@ func TestStateLockNoPOL(t *testing.T) {

// wait to finish prevote
ensurePrevote(voteCh, height, round)

// we should have prevoted our locked block
validatePrevote(cs1, round, vss[0], rs.LockedBlock.Hash())

Expand Down Expand Up @@ -584,6 +586,7 @@ func TestStateLockPOLRelock(t *testing.T) {

ensureNewRound(newRoundCh, height, round)
ensureNewProposal(proposalCh, height, round)
ensureNoNewEventOnChannel(voteCh)
rs := cs1.GetRoundState()
theBlockHash := rs.ProposalBlock.Hash()
theBlockParts := rs.ProposalBlockParts.Header()
Expand Down Expand Up @@ -681,6 +684,7 @@ func TestStateLockPOLUnlock(t *testing.T) {

ensureNewRound(newRoundCh, height, round)
ensureNewProposal(proposalCh, height, round)
ensureNoNewEventOnChannel(voteCh)
rs := cs1.GetRoundState()
theBlockHash := rs.ProposalBlock.Hash()
theBlockParts := rs.ProposalBlockParts.Header()
Expand Down Expand Up @@ -814,7 +818,7 @@ func TestStateLockPOLSafety1(t *testing.T) {
*/

ensureNewProposal(proposalCh, height, round)

ensureNoNewEventOnChannel(voteCh)
rs = cs1.GetRoundState()

if rs.LockedBlock != nil {
Expand Down Expand Up @@ -996,6 +1000,7 @@ func TestProposeValidBlock(t *testing.T) {

ensureNewRound(newRoundCh, height, round)
ensureNewProposal(proposalCh, height, round)
ensureNoNewEventOnChannel(voteCh)
rs := cs1.GetRoundState()
propBlock := rs.ProposalBlock
propBlockHash := propBlock.Hash()
Expand Down Expand Up @@ -1058,6 +1063,7 @@ func TestProposeValidBlock(t *testing.T) {

ensureNewProposal(proposalCh, height, round)

ensureNoNewEventOnChannel(voteCh)
rs = cs1.GetRoundState()
assert.True(t, bytes.Equal(rs.ProposalBlock.Hash(), propBlockHash))
assert.True(t, bytes.Equal(rs.ProposalBlock.Hash(), rs.ValidBlock.Hash()))
Expand Down Expand Up @@ -1092,6 +1098,7 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) {

ensureNewRound(newRoundCh, height, round)
ensureNewProposal(proposalCh, height, round)
ensureNoNewEventOnChannel(voteCh)
rs := cs1.GetRoundState()
propBlock := rs.ProposalBlock
propBlockHash := propBlock.Hash()
Expand All @@ -1112,6 +1119,7 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) {
// we should have precommitted
validatePrecommit(t, cs1, round, -1, vss[0], nil, nil)

ensureNoNewEventOnChannel(voteCh)
rs = cs1.GetRoundState()

assert.True(t, rs.ValidBlock == nil)
Expand All @@ -1123,6 +1131,7 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) {

ensureNewValidBlock(validBlockCh, height, round)

ensureNoNewEventOnChannel(voteCh)
rs = cs1.GetRoundState()

assert.True(t, bytes.Equal(rs.ValidBlock.Hash(), propBlockHash))
Expand Down Expand Up @@ -1183,6 +1192,8 @@ func TestSetValidBlockOnDelayedProposal(t *testing.T) {
}

ensureNewProposal(proposalCh, height, round)

ensureNoNewEventOnChannel(voteCh)
rs := cs1.GetRoundState()

assert.True(t, bytes.Equal(rs.ValidBlock.Hash(), propBlockHash))
Expand Down Expand Up @@ -1248,11 +1259,11 @@ func TestWaitingTimeoutProposeOnNewRound(t *testing.T) {
round++ // moving to the next round
ensureNewRound(newRoundCh, height, round)

ensureNoNewEventOnChannel(voteCh)
rs := cs1.GetRoundState()
assert.True(t, rs.Step == cstypes.RoundStepPropose) // P0 does not prevote before timeoutPropose expires

ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Propose(round).Nanoseconds())

ensurePrevote(voteCh, height, round)
validatePrevote(cs1, round, vss[0], nil)
}
Expand Down Expand Up @@ -1451,6 +1462,7 @@ func TestStartNextHeightCorrectly(t *testing.T) {

ensureNewRound(newRoundCh, height, round)
ensureNewProposal(proposalCh, height, round)
ensureNoNewEventOnChannel(voteCh)
rs := cs1.GetRoundState()
theBlockHash := rs.ProposalBlock.Hash()
theBlockParts := rs.ProposalBlockParts.Header()
Expand All @@ -1470,6 +1482,7 @@ func TestStartNextHeightCorrectly(t *testing.T) {
time.Sleep(5 * time.Millisecond)
signAddVotes(cs1, types.PrecommitType, theBlockHash, theBlockParts, vs4)

ensureNoNewEventOnChannel(voteCh)
rs = cs1.GetRoundState()
assert.True(t, rs.TriggeredTimeoutPrecommit)

Expand All @@ -1480,6 +1493,8 @@ func TestStartNextHeightCorrectly(t *testing.T) {
height, round = height+1, 0
ensureNewRound(newRoundCh, height, round)
ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds())

ensureNoNewEventOnChannel(voteCh)
rs = cs1.GetRoundState()
assert.False(t, rs.TriggeredTimeoutPrecommit, "triggeredTimeoutPrecommit should be false at the beginning of each round")
}
Expand Down Expand Up @@ -1512,6 +1527,7 @@ func TestFlappyResetTimeoutPrecommitUponNewHeight(t *testing.T) {

ensureNewRound(newRoundCh, height, round)
ensureNewProposal(proposalCh, height, round)
ensureNoNewEventOnChannel(voteCh)
rs := cs1.GetRoundState()
theBlockHash := rs.ProposalBlock.Hash()
theBlockParts := rs.ProposalBlockParts.Header()
Expand Down Expand Up @@ -1540,6 +1556,7 @@ func TestFlappyResetTimeoutPrecommitUponNewHeight(t *testing.T) {
ensureNewRound(newRoundCh, height+1, 0)
ensureNewProposal(proposalCh, height+1, 0)

ensureNoNewEventOnChannel(voteCh)
rs = cs1.GetRoundState()
assert.False(t, rs.TriggeredTimeoutPrecommit, "triggeredTimeoutPrecommit should be false at the beginning of each height")
}
Expand Down Expand Up @@ -1658,6 +1675,7 @@ func TestFlappyStateHalt1(t *testing.T) {

ensureNewRound(newRoundCh, height, round)
ensureNewProposal(proposalCh, height, round)
ensureNoNewEventOnChannel(voteCh)
rs := cs1.GetRoundState()
propBlock := rs.ProposalBlock
propBlockParts := propBlock.MakePartSet(partSize)
Expand All @@ -1684,6 +1702,7 @@ func TestFlappyStateHalt1(t *testing.T) {
round++ // moving to the next round

ensureNewRound(newRoundCh, height, round)
ensureNoNewEventOnChannel(voteCh)
rs = cs1.GetRoundState()

t.Log("### ONTO ROUND 1")
Expand Down

0 comments on commit da521cd

Please sign in to comment.