Fixed TestReactorInvalidPrecommit

This commit is contained in:
Sergio Mena
2022-11-29 01:38:51 +01:00
parent 824a58e5be
commit 5b6831b27a
2 changed files with 14 additions and 6 deletions

View File

@@ -2,7 +2,9 @@ package consensus
import (
"testing"
"time"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/log"
tmrand "github.com/tendermint/tendermint/libs/rand"
@@ -19,10 +21,15 @@ import (
// Ensure a testnet makes blocks
func TestReactorInvalidPrecommit(t *testing.T) {
N := 4
css, cleanup := randConsensusNet(t, N, "consensus_reactor_test", newMockTickerFunc(true), newKVStore)
css, cleanup := randConsensusNet(t, N, "consensus_reactor_test", newMockTickerFunc(true), newKVStore,
func(c *cfg.Config) {
c.Consensus.TimeoutPropose = 3000 * time.Millisecond
c.Consensus.TimeoutPrevote = 1000 * time.Millisecond
c.Consensus.TimeoutPrecommit = 1000 * time.Millisecond
})
defer cleanup()
for i := 0; i < 4; i++ {
for i := 0; i < N; i++ {
ticker := NewTimeoutTicker()
ticker.SetLogger(css[i].Logger)
css[i].SetTimeoutTicker(ticker)
@@ -30,9 +37,10 @@ func TestReactorInvalidPrecommit(t *testing.T) {
}
reactors, blocksSubs, eventBuses := startConsensusNet(t, css, N)
defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses)
// this val sends a random precommit at each height
byzValIdx := 0
byzValIdx := N - 1
byzVal := css[byzValIdx]
byzR := reactors[byzValIdx]
@@ -44,7 +52,6 @@ func TestReactorInvalidPrecommit(t *testing.T) {
invalidDoPrevoteFunc(t, height, round, byzVal, byzR.Switch, pv)
}
byzVal.mtx.Unlock()
defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses)
// wait for a bunch of blocks
// TODO: make this tighter by ensuring the halt happens by block 2
@@ -62,6 +69,7 @@ func invalidDoPrevoteFunc(t *testing.T, height int64, round int32, cs *State, sw
// - disable privValidator (so we don't do normal precommits)
go func() {
cs.mtx.Lock()
defer cs.mtx.Unlock()
cs.privValidator = pv
pubKey, err := cs.privValidator.GetPubKey()
if err != nil {
@@ -89,8 +97,8 @@ func invalidDoPrevoteFunc(t *testing.T, height int64, round int32, cs *State, sw
t.Error(err)
}
precommit.Signature = p.Signature
precommit.ExtensionSignature = p.ExtensionSignature
cs.privValidator = nil // disable priv val so we don't do normal votes
cs.mtx.Unlock()
peers := sw.Peers().List()
for _, peer := range peers {

View File

@@ -233,7 +233,7 @@ func (bs *BlockStore) LoadBlockCommit(height int64) *types.Commit {
}
err = proto.Unmarshal(bz, pbc)
if err != nil {
panic(fmt.Sprintf("error reading block commit: %v", err))
panic(fmt.Errorf("error reading block commit: %w", err))
}
commit, err := types.CommitFromProto(pbc)
if err != nil {