Browse Source

state.ApplyBlock takes evpool and calls MarkEvidenceAsCommitted

pull/592/head
Ethan Buchman 7 years ago
parent
commit
869d873d5c
8 changed files with 27 additions and 29 deletions
  1. +3
    -1
      blockchain/reactor.go
  2. +3
    -1
      consensus/replay.go
  3. +4
    -2
      consensus/replay_test.go
  4. +3
    -3
      consensus/state.go
  5. +2
    -18
      evidence/evidence_pool.go
  6. +4
    -1
      state/execution.go
  7. +4
    -1
      state/execution_test.go
  8. +4
    -2
      types/services.go

+ 3
- 1
blockchain/reactor.go View File

@ -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))


+ 3
- 1
consensus/replay.go View File

@ -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
}


+ 4
- 2
consensus/replay_test.go View File

@ -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)
}


+ 3
- 3
consensus/state.go View File

@ -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)


+ 2
- 18
evidence/evidence_pool.go View File

@ -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
}

+ 4
- 1
state/execution.go View File

@ -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()


+ 4
- 1
state/execution_test.go View File

@ -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


+ 4
- 2
types/services.go View File

@ -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) {}

Loading…
Cancel
Save