mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-05 11:31:16 +00:00
* Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
package v2
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/tendermint/tendermint/state"
|
|
"github.com/tendermint/tendermint/types"
|
|
)
|
|
|
|
type processorContext interface {
|
|
applyBlock(blockID types.BlockID, block *types.Block) error
|
|
verifyCommit(chainID string, blockID types.BlockID, height int64, commit *types.Commit) error
|
|
saveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)
|
|
tmState() state.State
|
|
}
|
|
|
|
type pContext struct {
|
|
store blockStore
|
|
applier blockApplier
|
|
state state.State
|
|
}
|
|
|
|
func newProcessorContext(st blockStore, ex blockApplier, s state.State) *pContext {
|
|
return &pContext{
|
|
store: st,
|
|
applier: ex,
|
|
state: s,
|
|
}
|
|
}
|
|
|
|
func (pc *pContext) applyBlock(blockID types.BlockID, block *types.Block) error {
|
|
newState, _, err := pc.applier.ApplyBlock(pc.state, blockID, block)
|
|
pc.state = newState
|
|
return err
|
|
}
|
|
|
|
func (pc pContext) tmState() state.State {
|
|
return pc.state
|
|
}
|
|
|
|
func (pc pContext) verifyCommit(chainID string, blockID types.BlockID, height int64, commit *types.Commit) error {
|
|
return pc.state.Validators.VerifyCommit(chainID, blockID, height, commit)
|
|
}
|
|
|
|
func (pc *pContext) saveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) {
|
|
pc.store.SaveBlock(block, blockParts, seenCommit)
|
|
}
|
|
|
|
type mockPContext struct {
|
|
applicationBL []int64
|
|
verificationBL []int64
|
|
state state.State
|
|
}
|
|
|
|
func newMockProcessorContext(
|
|
state state.State,
|
|
verificationBlackList []int64,
|
|
applicationBlackList []int64) *mockPContext {
|
|
return &mockPContext{
|
|
applicationBL: applicationBlackList,
|
|
verificationBL: verificationBlackList,
|
|
state: state,
|
|
}
|
|
}
|
|
|
|
func (mpc *mockPContext) applyBlock(blockID types.BlockID, block *types.Block) error {
|
|
for _, h := range mpc.applicationBL {
|
|
if h == block.Height {
|
|
return fmt.Errorf("generic application error")
|
|
}
|
|
}
|
|
mpc.state.LastBlockHeight = block.Height
|
|
return nil
|
|
}
|
|
|
|
func (mpc *mockPContext) verifyCommit(chainID string, blockID types.BlockID, height int64, commit *types.Commit) error {
|
|
for _, h := range mpc.verificationBL {
|
|
if h == height {
|
|
return fmt.Errorf("generic verification error")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (mpc *mockPContext) saveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) {
|
|
|
|
}
|
|
|
|
func (mpc *mockPContext) tmState() state.State {
|
|
return mpc.state
|
|
}
|