diff --git a/consensus/common_test.go b/consensus/common_test.go index 61ea75389..dd6b33340 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -372,7 +372,6 @@ func newStateWithConfigAndBlockStore( mempool.EnableTxsAvailable() } - // mock the evidence pool evpool := emptyEvidencePool{} // Make State diff --git a/consensus/replay.go b/consensus/replay.go index aefac0794..4dc0eefa8 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -16,7 +16,6 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/tendermint/tendermint/libs/log" - "github.com/tendermint/tendermint/mempool/mock" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" @@ -473,7 +472,9 @@ func (h *Handshaker) replayBlock(state sm.State, height int64, proxyApp proxy.Ap block := h.store.LoadBlock(height) meta := h.store.LoadBlockMeta(height) - blockExec := sm.NewBlockExecutor(h.stateDB, h.logger, proxyApp, mock.Mempool{}, emptyEvidencePool{}) + // Use stubs for both mempool and evidence pool since no transactions nor + // evidence are needed here - block already exists. + blockExec := sm.NewBlockExecutor(h.stateDB, h.logger, proxyApp, emptyMempool{}, emptyEvidencePool{}) blockExec.SetEventBus(h.eventBus) var err error @@ -508,54 +509,3 @@ Did you reset Tendermint without resetting your application's data?`, appHash, state.AppHash, state)) } } - -//-------------------------------------------------------------------------------- -// mockProxyApp uses ABCIResponses to give the right results -// Useful because we don't want to call Commit() twice for the same block on the real app. - -func newMockProxyApp(appHash []byte, abciResponses *sm.ABCIResponses) proxy.AppConnConsensus { - clientCreator := proxy.NewLocalClientCreator(&mockProxyApp{ - appHash: appHash, - abciResponses: abciResponses, - }) - cli, _ := clientCreator.NewABCIClient() - err := cli.Start() - if err != nil { - panic(err) - } - return proxy.NewAppConnConsensus(cli) -} - -type mockProxyApp struct { - abci.BaseApplication - - appHash []byte - txCount int - abciResponses *sm.ABCIResponses -} - -func (mock *mockProxyApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx { - r := mock.abciResponses.DeliverTxs[mock.txCount] - mock.txCount++ - if r == nil { //it could be nil because of amino unMarshall, it will cause an empty ResponseDeliverTx to become nil - return abci.ResponseDeliverTx{} - } - return *r -} - -func (mock *mockProxyApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock { - mock.txCount = 0 - return *mock.abciResponses.EndBlock -} - -func (mock *mockProxyApp) Commit() abci.ResponseCommit { - return abci.ResponseCommit{Data: mock.appHash} -} - -type emptyEvidencePool struct{} - -func (ev emptyEvidencePool) PendingEvidence(int64) []types.Evidence { return nil } -func (ev emptyEvidencePool) AddEvidence(types.Evidence) error { return nil } -func (ev emptyEvidencePool) Update(*types.Block, sm.State) {} -func (ev emptyEvidencePool) IsCommitted(types.Evidence) bool { return false } -func (ev emptyEvidencePool) IsPending(types.Evidence) bool { return true } diff --git a/consensus/replay_file.go b/consensus/replay_file.go index d00e2c6e6..df1758291 100644 --- a/consensus/replay_file.go +++ b/consensus/replay_file.go @@ -15,7 +15,6 @@ import ( cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" - "github.com/tendermint/tendermint/mempool/mock" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/store" @@ -311,7 +310,7 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo tmos.Exit(fmt.Sprintf("Error on handshake: %v", err)) } - mempool, evpool := mock.Mempool{}, emptyEvidencePool{} + mempool, evpool := emptyMempool{}, emptyEvidencePool{} blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool) consensusState := NewState(csConfig, state.Copy(), blockExec, diff --git a/consensus/replay_stubs.go b/consensus/replay_stubs.go new file mode 100644 index 000000000..0ad311614 --- /dev/null +++ b/consensus/replay_stubs.go @@ -0,0 +1,102 @@ +package consensus + +import ( + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/clist" + mempl "github.com/tendermint/tendermint/mempool" + "github.com/tendermint/tendermint/proxy" + sm "github.com/tendermint/tendermint/state" + "github.com/tendermint/tendermint/types" +) + +//----------------------------------------------------------------------------- + +type emptyMempool struct{} + +var _ mempl.Mempool = emptyMempool{} + +func (emptyMempool) Lock() {} +func (emptyMempool) Unlock() {} +func (emptyMempool) Size() int { return 0 } +func (emptyMempool) CheckTx(_ types.Tx, _ func(*abci.Response), _ mempl.TxInfo) error { + return nil +} +func (emptyMempool) ReapMaxBytesMaxGas(_, _ int64) types.Txs { return types.Txs{} } +func (emptyMempool) ReapMaxTxs(n int) types.Txs { return types.Txs{} } +func (emptyMempool) Update( + _ int64, + _ types.Txs, + _ []*abci.ResponseDeliverTx, + _ mempl.PreCheckFunc, + _ mempl.PostCheckFunc, +) error { + return nil +} +func (emptyMempool) Flush() {} +func (emptyMempool) FlushAppConn() error { return nil } +func (emptyMempool) TxsAvailable() <-chan struct{} { return make(chan struct{}) } +func (emptyMempool) EnableTxsAvailable() {} +func (emptyMempool) TxsBytes() int64 { return 0 } + +func (emptyMempool) TxsFront() *clist.CElement { return nil } +func (emptyMempool) TxsWaitChan() <-chan struct{} { return nil } + +func (emptyMempool) InitWAL() {} +func (emptyMempool) CloseWAL() {} + +//----------------------------------------------------------------------------- + +type emptyEvidencePool struct{} + +var _ sm.EvidencePool = emptyEvidencePool{} + +func (emptyEvidencePool) PendingEvidence(int64) []types.Evidence { return nil } +func (emptyEvidencePool) AddEvidence(types.Evidence) error { return nil } +func (emptyEvidencePool) Update(*types.Block, sm.State) {} +func (emptyEvidencePool) IsCommitted(types.Evidence) bool { return false } +func (emptyEvidencePool) IsPending(types.Evidence) bool { return false } + +//----------------------------------------------------------------------------- +// mockProxyApp uses ABCIResponses to give the right results. +// +// Useful because we don't want to call Commit() twice for the same block on +// the real app. + +func newMockProxyApp(appHash []byte, abciResponses *sm.ABCIResponses) proxy.AppConnConsensus { + clientCreator := proxy.NewLocalClientCreator(&mockProxyApp{ + appHash: appHash, + abciResponses: abciResponses, + }) + cli, _ := clientCreator.NewABCIClient() + err := cli.Start() + if err != nil { + panic(err) + } + return proxy.NewAppConnConsensus(cli) +} + +type mockProxyApp struct { + abci.BaseApplication + + appHash []byte + txCount int + abciResponses *sm.ABCIResponses +} + +func (mock *mockProxyApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx { + r := mock.abciResponses.DeliverTxs[mock.txCount] + mock.txCount++ + if r == nil { //it could be nil because of amino unMarshall, it will cause an empty ResponseDeliverTx to become nil + return abci.ResponseDeliverTx{} + } + return *r +} + +func (mock *mockProxyApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock { + mock.txCount = 0 + return *mock.abciResponses.EndBlock +} + +func (mock *mockProxyApp) Commit() abci.ResponseCommit { + return abci.ResponseCommit{Data: mock.appHash} +} diff --git a/consensus/replay_test.go b/consensus/replay_test.go index e8ff3da64..999678097 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -26,7 +26,6 @@ import ( "github.com/tendermint/tendermint/libs/log" tmrand "github.com/tendermint/tendermint/libs/rand" mempl "github.com/tendermint/tendermint/mempool" - "github.com/tendermint/tendermint/mempool/mock" "github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" @@ -295,7 +294,7 @@ const ( ) var ( - mempool = mock.Mempool{} + mempool = emptyMempool{} evpool = emptyEvidencePool{} sim testSim diff --git a/consensus/wal_generator.go b/consensus/wal_generator.go index 1cd61aa3e..3584ade3b 100644 --- a/consensus/wal_generator.go +++ b/consensus/wal_generator.go @@ -17,7 +17,6 @@ import ( cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/log" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/tendermint/tendermint/mempool/mock" "github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" @@ -72,7 +71,7 @@ func WALGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) { return errors.Wrap(err, "failed to start event bus") } defer eventBus.Stop() - mempool := mock.Mempool{} + mempool := emptyMempool{} evpool := emptyEvidencePool{} blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool) consensusState := NewState(config.Consensus, state.Copy(), blockExec, blockStore, mempool, evpool)