From 8a9eecce7fd00b8510186aa03290a8c4e252d4c4 Mon Sep 17 00:00:00 2001 From: Anca Zamfir Date: Tue, 12 Feb 2019 06:02:44 +0100 Subject: [PATCH] test blockExec does not panic if all vals removed (#3241) Fix for #3224 Also address #2084 --- blockchain/reactor.go | 4 +--- state/execution_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/blockchain/reactor.go b/blockchain/reactor.go index 847398b7b..4a3f90493 100644 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -8,7 +8,6 @@ import ( amino "github.com/tendermint/go-amino" - cmn "github.com/tendermint/tendermint/libs/common" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/p2p" sm "github.com/tendermint/tendermint/state" @@ -338,8 +337,7 @@ FOR_LOOP: state, err = bcR.blockExec.ApplyBlock(state, firstID, first) if err != nil { // TODO This is bad, are we zombie? - cmn.PanicQ(fmt.Sprintf("Failed to process committed block (%d:%X): %v", - first.Height, first.Hash(), err)) + panic(fmt.Sprintf("Failed to process committed block (%d:%X): %v", first.Height, first.Hash(), err)) } blocksSynced++ diff --git a/state/execution_test.go b/state/execution_test.go index 8cd90f963..143faa1ab 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -354,6 +354,33 @@ func TestEndBlockValidatorUpdates(t *testing.T) { } } +// TestEndBlockValidatorUpdatesResultingInEmptySet checks that processing validator updates that +// would result in empty set causes no panic, an error is raised and NextValidators is not updated +func TestEndBlockValidatorUpdatesResultingInEmptySet(t *testing.T) { + app := &testApp{} + cc := proxy.NewLocalClientCreator(app) + proxyApp := proxy.NewAppConns(cc) + err := proxyApp.Start() + require.Nil(t, err) + defer proxyApp.Stop() + + state, stateDB := state(1, 1) + blockExec := NewBlockExecutor(stateDB, log.TestingLogger(), proxyApp.Consensus(), MockMempool{}, MockEvidencePool{}) + + block := makeBlock(state, 1) + blockID := types.BlockID{block.Hash(), block.MakePartSet(testPartSize).Header()} + + // Remove the only validator + app.ValidatorUpdates = []abci.ValidatorUpdate{ + {PubKey: types.TM2PB.PubKey(state.Validators.Validators[0].PubKey), Power: 0}, + } + + assert.NotPanics(t, func() { state, err = blockExec.ApplyBlock(state, blockID, block) }) + assert.NotNil(t, err) + assert.NotEmpty(t, state.NextValidators.Validators) + +} + //---------------------------------------------------------------------------- // make some bogus txs