mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-20 08:26:31 +00:00
state.ApplyBlock takes evpool and calls MarkEvidenceAsCommitted
This commit is contained in:
@ -272,7 +272,9 @@ FOR_LOOP:
|
|||||||
// NOTE: we could improve performance if we
|
// NOTE: we could improve performance if we
|
||||||
// didn't make the app commit to disk every block
|
// didn't make the app commit to disk every block
|
||||||
// ... but we would need a way to get the hash without it persisting
|
// ... 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 {
|
if err != nil {
|
||||||
// TODO This is bad, are we zombie?
|
// TODO This is bad, are we zombie?
|
||||||
cmn.PanicQ(cmn.Fmt("Failed to process committed block (%d:%X): %v", first.Height, first.Hash(), err))
|
cmn.PanicQ(cmn.Fmt("Failed to process committed block (%d:%X): %v", first.Height, first.Hash(), err))
|
||||||
|
@ -354,11 +354,13 @@ func (h *Handshaker) replayBlocks(proxyApp proxy.AppConns, appBlockHeight, store
|
|||||||
// ApplyBlock on the proxyApp with the last block.
|
// ApplyBlock on the proxyApp with the last block.
|
||||||
func (h *Handshaker) replayBlock(height int64, proxyApp proxy.AppConnConsensus) ([]byte, error) {
|
func (h *Handshaker) replayBlock(height int64, proxyApp proxy.AppConnConsensus) ([]byte, error) {
|
||||||
mempool := types.MockMempool{}
|
mempool := types.MockMempool{}
|
||||||
|
evpool := types.MockEvidencePool{}
|
||||||
|
|
||||||
block := h.store.LoadBlock(height)
|
block := h.store.LoadBlock(height)
|
||||||
meta := h.store.LoadBlockMeta(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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +261,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
NUM_BLOCKS = 6 // number of blocks in the test_data/many_blocks.cswal
|
||||||
mempool = types.MockMempool{}
|
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) {
|
func applyBlock(st *sm.State, blk *types.Block, proxyApp proxy.AppConns) {
|
||||||
testPartSize := st.ConsensusParams.BlockPartSizeBytes
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -1208,7 +1208,9 @@ func (cs *ConsensusState) finalizeCommit(height int64) {
|
|||||||
// Execute and commit the block, update and save the state, and update the mempool.
|
// Execute and commit the block, update and save the state, and update the mempool.
|
||||||
// All calls to the proxyAppConn come here.
|
// All calls to the proxyAppConn come here.
|
||||||
// NOTE: the block.AppHash wont reflect these txs until the next block
|
// 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 {
|
if err != nil {
|
||||||
cs.Logger.Error("Error on ApplyBlock. Did the application crash? Please restart tendermint", "err", err)
|
cs.Logger.Error("Error on ApplyBlock. Did the application crash? Please restart tendermint", "err", err)
|
||||||
err := cmn.Kill()
|
err := cmn.Kill()
|
||||||
@ -1236,8 +1238,6 @@ func (cs *ConsensusState) finalizeCommit(height int64) {
|
|||||||
|
|
||||||
fail.Fail() // XXX
|
fail.Fail() // XXX
|
||||||
|
|
||||||
// TODO: cs.evpool.Update()
|
|
||||||
|
|
||||||
// NewHeightStep!
|
// NewHeightStep!
|
||||||
cs.updateToState(stateCopy)
|
cs.updateToState(stateCopy)
|
||||||
|
|
||||||
|
@ -73,25 +73,9 @@ func (evpool *EvidencePool) AddEvidence(evidence types.Evidence) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update informs the evpool that the given evidence was committed and can be discarded.
|
// MarkEvidenceAsCommitted marks all the evidence as committed.
|
||||||
// NOTE: this should be called *after* block is committed by consensus.
|
func (evpool *EvidencePool) MarkEvidenceAsCommitted(evidence []types.Evidence) {
|
||||||
func (evpool *EvidencePool) Update(height int, evidence []types.Evidence) {
|
|
||||||
|
|
||||||
// First, create a lookup map of new committed evidence
|
|
||||||
|
|
||||||
evMap := make(map[string]struct{})
|
|
||||||
for _, ev := range evidence {
|
for _, ev := range evidence {
|
||||||
evpool.evidenceStore.MarkEvidenceAsCommitted(ev)
|
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
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
// 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.
|
// from outside this package to process and commit an entire block.
|
||||||
func (s *State) ApplyBlock(txEventPublisher types.TxEventPublisher, proxyAppConn proxy.AppConnConsensus,
|
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)
|
abciResponses, err := s.ValExecBlock(txEventPublisher, proxyAppConn, block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -355,6 +356,8 @@ func (s *State) ApplyBlock(txEventPublisher types.TxEventPublisher, proxyAppConn
|
|||||||
|
|
||||||
fail.Fail() // XXX
|
fail.Fail() // XXX
|
||||||
|
|
||||||
|
evpool.MarkEvidenceAsCommitted(block.Evidence.Evidence)
|
||||||
|
|
||||||
// save the state and the validators
|
// save the state and the validators
|
||||||
s.Save()
|
s.Save()
|
||||||
|
|
||||||
|
@ -93,7 +93,10 @@ func TestApplyBlock(t *testing.T) {
|
|||||||
|
|
||||||
block := makeBlock(state, 1)
|
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)
|
require.Nil(t, err)
|
||||||
|
|
||||||
// TODO check state and mempool
|
// TODO check state and mempool
|
||||||
|
@ -87,6 +87,7 @@ type State interface {
|
|||||||
type EvidencePool interface {
|
type EvidencePool interface {
|
||||||
PendingEvidence() []Evidence
|
PendingEvidence() []Evidence
|
||||||
AddEvidence(Evidence) error
|
AddEvidence(Evidence) error
|
||||||
|
MarkEvidenceAsCommitted([]Evidence)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MockMempool is an empty implementation of a Mempool, useful for testing.
|
// MockMempool is an empty implementation of a Mempool, useful for testing.
|
||||||
@ -96,3 +97,4 @@ type MockEvidencePool struct {
|
|||||||
|
|
||||||
func (m MockEvidencePool) PendingEvidence() []Evidence { return nil }
|
func (m MockEvidencePool) PendingEvidence() []Evidence { return nil }
|
||||||
func (m MockEvidencePool) AddEvidence(Evidence) error { return nil }
|
func (m MockEvidencePool) AddEvidence(Evidence) error { return nil }
|
||||||
|
func (m MockEvidencePool) MarkEvidenceAsCommitted([]Evidence) {}
|
||||||
|
Reference in New Issue
Block a user