diff --git a/consensus/byzantine_test.go b/consensus/byzantine_test.go index 0b869f0da6..b4f6b10193 100644 --- a/consensus/byzantine_test.go +++ b/consensus/byzantine_test.go @@ -34,6 +34,34 @@ import ( "github.com/cometbft/cometbft/types" ) +const ( + minTestRoundTimeout = 500 * time.Millisecond + minTestRoundDelta = 100 * time.Millisecond + minTestCommitTimeout = 2 * time.Second + minTestDelayedTimeout = 500 * time.Millisecond +) + +func applyTestConsensusTimeouts(timeoutInfo *cmtstate.TimeoutInfo) { + timeoutInfo.TimeoutPropose = maxDuration(timeoutInfo.TimeoutPropose, minTestRoundTimeout) + timeoutInfo.TimeoutPrevote = maxDuration(timeoutInfo.TimeoutPrevote, minTestRoundTimeout) + timeoutInfo.TimeoutPrecommit = maxDuration(timeoutInfo.TimeoutPrecommit, minTestRoundTimeout) + + timeoutInfo.TimeoutProposeDelta = maxDuration(timeoutInfo.TimeoutProposeDelta, minTestRoundDelta) + timeoutInfo.TimeoutPrevoteDelta = maxDuration(timeoutInfo.TimeoutPrevoteDelta, minTestRoundDelta) + timeoutInfo.TimeoutPrecommitDelta = maxDuration(timeoutInfo.TimeoutPrecommitDelta, minTestRoundDelta) + + timeoutInfo.TimeoutCommit = maxDuration(timeoutInfo.TimeoutCommit, minTestCommitTimeout) + timeoutInfo.DelayedPrecommitTimeout = maxDuration(timeoutInfo.DelayedPrecommitTimeout, minTestDelayedTimeout) +} + +func maxDuration(current, min time.Duration) time.Duration { + if current < min { + return min + } + + return current +} + //---------------------------------------------- // byzantine failures @@ -80,6 +108,8 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { DelayedPrecommitTimeout: resp.TimeoutInfo.DelayedPrecommitTimeout, } + applyTestConsensusTimeouts(&state.Timeouts) + // Save the updated state back to the store err = stateStore.Save(state) require.NoError(t, err) diff --git a/consensus/common_test.go b/consensus/common_test.go index d3e536ab10..f00495304d 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -303,22 +303,6 @@ func validatePrevote(t *testing.T, cs *State, round int32, privVal *validatorStu } } -func validateLastPrecommit(t *testing.T, cs *State, privVal *validatorStub, blockHash []byte) { - cs.rsMtx.RLock() - votes := cs.rs.LastCommit - cs.rsMtx.RUnlock() - pv, err := privVal.GetPubKey() - require.NoError(t, err) - address := pv.Address() - var vote *types.Vote - if vote = votes.GetByAddress(address); vote == nil { - panic("Failed to find precommit from validator") - } - if !bytes.Equal(vote.BlockID.Hash, blockHash) { - panic(fmt.Sprintf("Expected precommit to be for %X, got %X", blockHash, vote.BlockID.Hash)) - } -} - func validatePrecommit( t *testing.T, cs *State, diff --git a/consensus/state_test.go b/consensus/state_test.go index 126e2c61bd..b9f1eb35ac 100644 --- a/consensus/state_test.go +++ b/consensus/state_test.go @@ -359,7 +359,7 @@ func TestStateOversizedBlock(t *testing.T) { // propose, prevote, and precommit a block func TestStateFullRound1(t *testing.T) { - cs, vss := randState(1) + cs, _ := randState(1) height, round := cs.rs.Height, cs.rs.Round // NOTE: buffer capacity of 0 ensures we can validate prevote and last commit @@ -383,11 +383,15 @@ func TestStateFullRound1(t *testing.T) { propBlockHash := waitForProposal(t, propCh, height, round) ensurePrevoteMatch(t, voteCh, height, round, propBlockHash) - ensurePrecommit(voteCh, height, round) // wait for precommit + ensurePrecommitMatch(t, voteCh, height, round, propBlockHash) // we're going to roll right into new height ensureNewRound(newRoundCh, height+1, 0) - validateLastPrecommit(t, cs, vss[0], propBlockHash) + require.NoError(t, cs.timeoutTicker.Stop()) + commit := cs.blockStore.LoadBlockCommit(height) + require.NotNil(t, commit, "expected commit for height %d", height) + assert.True(t, bytes.Equal(commit.BlockID.Hash, propBlockHash), + "expected commit hash %X, got %X", propBlockHash, commit.BlockID.Hash) } // nil is proposed, so prevote and precommit nil