diff --git a/blockchain/reactor.go b/blockchain/reactor.go index e41300d5e..f985e2849 100644 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -272,7 +272,9 @@ FOR_LOOP: // NOTE: we could improve performance if we // didn't make the app commit to disk every block // ... but we would need a way to get the hash without it persisting - err := bcR.state.ApplyBlock(bcR.eventBus, bcR.proxyAppConn, first, firstPartsHeader, types.MockMempool{}) + err := bcR.state.ApplyBlock(bcR.eventBus, bcR.proxyAppConn, + first, firstPartsHeader, + types.MockMempool{}, types.MockEvidencePool{}) // TODO unmock! if err != nil { // TODO This is bad, are we zombie? cmn.PanicQ(cmn.Fmt("Failed to process committed block (%d:%X): %v", first.Height, first.Hash(), err)) diff --git a/consensus/replay.go b/consensus/replay.go index 57a9dd4cc..56f09d129 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -354,11 +354,13 @@ func (h *Handshaker) replayBlocks(proxyApp proxy.AppConns, appBlockHeight, store // ApplyBlock on the proxyApp with the last block. func (h *Handshaker) replayBlock(height int64, proxyApp proxy.AppConnConsensus) ([]byte, error) { mempool := types.MockMempool{} + evpool := types.MockEvidencePool{} block := h.store.LoadBlock(height) meta := h.store.LoadBlockMeta(height) - if err := h.state.ApplyBlock(types.NopEventBus{}, proxyApp, block, meta.BlockID.PartsHeader, mempool); err != nil { + if err := h.state.ApplyBlock(types.NopEventBus{}, proxyApp, + block, meta.BlockID.PartsHeader, mempool, evpool); err != nil { return nil, err } diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 43c2a4699..495fc42cc 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -261,7 +261,9 @@ const ( ) var ( - mempool = types.MockMempool{} + NUM_BLOCKS = 6 // number of blocks in the test_data/many_blocks.cswal + mempool = types.MockMempool{} + evpool = types.MockEvidencePool{} ) //--------------------------------------- @@ -394,7 +396,7 @@ func testHandshakeReplay(t *testing.T, nBlocks int, mode uint) { func applyBlock(st *sm.State, blk *types.Block, proxyApp proxy.AppConns) { testPartSize := st.ConsensusParams.BlockPartSizeBytes - err := st.ApplyBlock(types.NopEventBus{}, proxyApp.Consensus(), blk, blk.MakePartSet(testPartSize).Header(), mempool) + err := st.ApplyBlock(types.NopEventBus{}, proxyApp.Consensus(), blk, blk.MakePartSet(testPartSize).Header(), mempool, evpool) if err != nil { panic(err) } diff --git a/consensus/state.go b/consensus/state.go index 7531f1975..5e83e6a56 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1208,7 +1208,9 @@ func (cs *ConsensusState) finalizeCommit(height int64) { // Execute and commit the block, update and save the state, and update the mempool. // All calls to the proxyAppConn come here. // NOTE: the block.AppHash wont reflect these txs until the next block - err := stateCopy.ApplyBlock(txEventBuffer, cs.proxyAppConn, block, blockParts.Header(), cs.mempool) + err := stateCopy.ApplyBlock(txEventBuffer, cs.proxyAppConn, + block, blockParts.Header(), + cs.mempool, cs.evpool) if err != nil { cs.Logger.Error("Error on ApplyBlock. Did the application crash? Please restart tendermint", "err", err) err := cmn.Kill() @@ -1236,8 +1238,6 @@ func (cs *ConsensusState) finalizeCommit(height int64) { fail.Fail() // XXX - // TODO: cs.evpool.Update() - // NewHeightStep! cs.updateToState(stateCopy) diff --git a/evidence/evidence_pool.go b/evidence/evidence_pool.go index 41f51ee97..daa0f9bef 100644 --- a/evidence/evidence_pool.go +++ b/evidence/evidence_pool.go @@ -73,25 +73,9 @@ func (evpool *EvidencePool) AddEvidence(evidence types.Evidence) (err error) { return nil } -// Update informs the evpool that the given evidence was committed and can be discarded. -// NOTE: this should be called *after* block is committed by consensus. -func (evpool *EvidencePool) Update(height int, evidence []types.Evidence) { - - // First, create a lookup map of new committed evidence - - evMap := make(map[string]struct{}) +// MarkEvidenceAsCommitted marks all the evidence as committed. +func (evpool *EvidencePool) MarkEvidenceAsCommitted(evidence []types.Evidence) { for _, ev := range evidence { evpool.evidenceStore.MarkEvidenceAsCommitted(ev) - evMap[string(ev.Hash())] = struct{}{} } - - // Remove evidence that is already committed . - goodEvidence := evpool.filterEvidence(evMap) - _ = goodEvidence - -} - -func (evpool *EvidencePool) filterEvidence(blockEvidenceMap map[string]struct{}) []types.Evidence { - // TODO: - return nil } diff --git a/state/execution.go b/state/execution.go index 539d1cd31..f6f6a314b 100644 --- a/state/execution.go +++ b/state/execution.go @@ -327,7 +327,8 @@ func (s *State) validateBlock(b *types.Block) error { // commits it, and saves the block and state. It's the only function that needs to be called // from outside this package to process and commit an entire block. func (s *State) ApplyBlock(txEventPublisher types.TxEventPublisher, proxyAppConn proxy.AppConnConsensus, - block *types.Block, partsHeader types.PartSetHeader, mempool types.Mempool) error { + block *types.Block, partsHeader types.PartSetHeader, + mempool types.Mempool, evpool types.EvidencePool) error { abciResponses, err := s.ValExecBlock(txEventPublisher, proxyAppConn, block) if err != nil { @@ -355,6 +356,8 @@ func (s *State) ApplyBlock(txEventPublisher types.TxEventPublisher, proxyAppConn fail.Fail() // XXX + evpool.MarkEvidenceAsCommitted(block.Evidence.Evidence) + // save the state and the validators s.Save() diff --git a/state/execution_test.go b/state/execution_test.go index 25d32cbbc..7cda5c1da 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -93,7 +93,10 @@ func TestApplyBlock(t *testing.T) { block := makeBlock(state, 1) - err = state.ApplyBlock(types.NopEventBus{}, proxyApp.Consensus(), block, block.MakePartSet(testPartSize).Header(), types.MockMempool{}) + err = state.ApplyBlock(types.NopEventBus{}, proxyApp.Consensus(), + block, block.MakePartSet(testPartSize).Header(), + types.MockMempool{}, types.MockEvidencePool{}) + require.Nil(t, err) // TODO check state and mempool diff --git a/types/services.go b/types/services.go index 10014e660..b23ccff44 100644 --- a/types/services.go +++ b/types/services.go @@ -87,6 +87,7 @@ type State interface { type EvidencePool interface { PendingEvidence() []Evidence AddEvidence(Evidence) error + MarkEvidenceAsCommitted([]Evidence) } // MockMempool is an empty implementation of a Mempool, useful for testing. @@ -94,5 +95,6 @@ type EvidencePool interface { type MockEvidencePool struct { } -func (m MockEvidencePool) PendingEvidence() []Evidence { return nil } -func (m MockEvidencePool) AddEvidence(Evidence) error { return nil } +func (m MockEvidencePool) PendingEvidence() []Evidence { return nil } +func (m MockEvidencePool) AddEvidence(Evidence) error { return nil } +func (m MockEvidencePool) MarkEvidenceAsCommitted([]Evidence) {}