mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-05 13:05:09 +00:00
evidence: adr56 form amnesia evidence (#4821)
Creates Amnesia Evidence which is formed from Potential Amnesia Evidence with either a matching proof or after a period of time denoted as the Amnesia Trial Period. This also adds the code necessary so that Amnesia Evidence can be validated and committed on a block
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
cstypes "github.com/tendermint/tendermint/consensus/types"
|
||||
"github.com/tendermint/tendermint/evidence"
|
||||
tmbytes "github.com/tendermint/tendermint/libs/bytes"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmos "github.com/tendermint/tendermint/libs/os"
|
||||
@@ -422,6 +423,47 @@ func randState(nValidators int) (*State, []*validatorStub) {
|
||||
return cs, vss
|
||||
}
|
||||
|
||||
func randStateWithEvpool(nValidators int) (*State, []*validatorStub, *evidence.Pool) {
|
||||
state, privVals := randGenesisState(nValidators, false, 10)
|
||||
|
||||
vss := make([]*validatorStub, nValidators)
|
||||
|
||||
app := counter.NewApplication(true)
|
||||
config := cfg.ResetTestRoot("consensus_state_test")
|
||||
|
||||
blockStore := store.NewBlockStore(dbm.NewMemDB())
|
||||
evidenceDB := dbm.NewMemDB()
|
||||
|
||||
mtx := new(sync.Mutex)
|
||||
proxyAppConnMem := abcicli.NewLocalClient(mtx, app)
|
||||
proxyAppConnCon := abcicli.NewLocalClient(mtx, app)
|
||||
|
||||
mempool := mempl.NewCListMempool(config.Mempool, proxyAppConnMem, 0)
|
||||
mempool.SetLogger(log.TestingLogger().With("module", "mempool"))
|
||||
if config.Consensus.WaitForTxs() {
|
||||
mempool.EnableTxsAvailable()
|
||||
}
|
||||
stateDB := dbm.NewMemDB()
|
||||
evpool, _ := evidence.NewPool(stateDB, evidenceDB, blockStore)
|
||||
blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyAppConnCon, mempool, evpool)
|
||||
cs := NewState(config.Consensus, state, blockExec, blockStore, mempool, evpool)
|
||||
cs.SetLogger(log.TestingLogger().With("module", "consensus"))
|
||||
cs.SetPrivValidator(privVals[0])
|
||||
|
||||
eventBus := types.NewEventBus()
|
||||
eventBus.SetLogger(log.TestingLogger().With("module", "events"))
|
||||
eventBus.Start()
|
||||
cs.SetEventBus(eventBus)
|
||||
|
||||
for i := 0; i < nValidators; i++ {
|
||||
vss[i] = newValidatorStub(privVals[i], int32(i))
|
||||
}
|
||||
// since cs1 starts at 1
|
||||
incrementHeight(vss[1:]...)
|
||||
|
||||
return cs, vss, evpool
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
|
||||
func ensureNoNewEvent(ch <-chan tmpubsub.Message, timeout time.Duration,
|
||||
|
||||
@@ -616,7 +616,7 @@ func TestStateLockPOLRelockThenChangeLock(t *testing.T) {
|
||||
|
||||
// 4 vals, one precommits, other 3 polka at next round, so we unlock and precomit the polka
|
||||
func TestStateLockPOLUnlock(t *testing.T) {
|
||||
cs1, vss := randState(4)
|
||||
cs1, vss, evpool := randStateWithEvpool(4)
|
||||
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
||||
height, round := cs1.Height, cs1.Round
|
||||
|
||||
@@ -703,6 +703,16 @@ func TestStateLockPOLUnlock(t *testing.T) {
|
||||
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3)
|
||||
ensureNewRound(newRoundCh, height, round+1)
|
||||
// polc should be in the evpool for round 1
|
||||
polc, err := evpool.RetrievePOLC(height, round)
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, polc.IsAbsent())
|
||||
t.Log(polc.Address())
|
||||
// but not for round 0
|
||||
polc, err = evpool.RetrievePOLC(height, round-1)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, polc.IsAbsent())
|
||||
|
||||
}
|
||||
|
||||
// 4 vals, v1 locks on proposed block in the first round but the other validators only prevote
|
||||
@@ -710,7 +720,7 @@ func TestStateLockPOLUnlock(t *testing.T) {
|
||||
// v1 should unlock and precommit nil. In the third round another block is proposed, all vals
|
||||
// prevote and now v1 can lock onto the third block and precommit that
|
||||
func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) {
|
||||
cs1, vss := randState(4)
|
||||
cs1, vss, evpool := randStateWithEvpool(4)
|
||||
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
||||
height, round := cs1.Height, cs1.Round
|
||||
|
||||
@@ -803,6 +813,11 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) {
|
||||
thirdPropBlockHash := propBlock.Hash()
|
||||
require.NotEqual(t, secondBlockHash, thirdPropBlockHash)
|
||||
|
||||
// polc should be in the evpool for round 1
|
||||
polc, err := evpool.RetrievePOLC(height, round)
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, polc.IsAbsent())
|
||||
|
||||
incrementRound(vs2, vs3, vs4)
|
||||
|
||||
// timeout to new round
|
||||
|
||||
Reference in New Issue
Block a user