You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

595 lines
17 KiB

7 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * 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>
5 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. package state
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/gogo/protobuf/proto"
  6. dbm "github.com/tendermint/tm-db"
  7. abci "github.com/tendermint/tendermint/abci/types"
  8. tmmath "github.com/tendermint/tendermint/libs/math"
  9. tmos "github.com/tendermint/tendermint/libs/os"
  10. tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
  11. tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
  12. "github.com/tendermint/tendermint/types"
  13. )
  14. const (
  15. // persist validators every valSetCheckpointInterval blocks to avoid
  16. // LoadValidators taking too much time.
  17. // https://github.com/tendermint/tendermint/pull/3438
  18. // 100000 results in ~ 100ms to get 100 validators (see BenchmarkLoadValidators)
  19. valSetCheckpointInterval = 100000
  20. )
  21. //------------------------------------------------------------------------
  22. func calcValidatorsKey(height int64) []byte {
  23. return []byte(fmt.Sprintf("validatorsKey:%v", height))
  24. }
  25. func calcConsensusParamsKey(height int64) []byte {
  26. return []byte(fmt.Sprintf("consensusParamsKey:%v", height))
  27. }
  28. func calcABCIResponsesKey(height int64) []byte {
  29. return []byte(fmt.Sprintf("abciResponsesKey:%v", height))
  30. }
  31. //----------------------
  32. //go:generate mockery --case underscore --name Store
  33. // Store defines the state store interface
  34. //
  35. // It is used to retrieve current state and save and load ABCI responses,
  36. // validators and consensus parameters
  37. type Store interface {
  38. // LoadFromDBOrGenesisFile loads the most recent state.
  39. // If the chain is new it will use the genesis file from the provided genesis file path as the current state.
  40. LoadFromDBOrGenesisFile(string) (State, error)
  41. // LoadFromDBOrGenesisDoc loads the most recent state.
  42. // If the chain is new it will use the genesis doc as the current state.
  43. LoadFromDBOrGenesisDoc(*types.GenesisDoc) (State, error)
  44. // Load loads the current state of the blockchain
  45. Load() (State, error)
  46. // LoadValidators loads the validator set at a given height
  47. LoadValidators(int64) (*types.ValidatorSet, error)
  48. // LoadABCIResponses loads the abciResponse for a given height
  49. LoadABCIResponses(int64) (*tmstate.ABCIResponses, error)
  50. // LoadConsensusParams loads the consensus params for a given height
  51. LoadConsensusParams(int64) (tmproto.ConsensusParams, error)
  52. // Save overwrites the previous state with the updated one
  53. Save(State) error
  54. // SaveABCIResponses saves ABCIResponses for a given height
  55. SaveABCIResponses(int64, *tmstate.ABCIResponses) error
  56. // Bootstrap is used for bootstrapping state when not starting from a initial height.
  57. Bootstrap(State) error
  58. // PruneStates takes the height from which to start prning and which height stop at
  59. PruneStates(int64, int64) error
  60. }
  61. // dbStore wraps a db (github.com/tendermint/tm-db)
  62. type dbStore struct {
  63. db dbm.DB
  64. }
  65. var _ Store = (*dbStore)(nil)
  66. // NewStore creates the dbStore of the state pkg.
  67. func NewStore(db dbm.DB) Store {
  68. return dbStore{db}
  69. }
  70. // LoadStateFromDBOrGenesisFile loads the most recent state from the database,
  71. // or creates a new one from the given genesisFilePath.
  72. func (store dbStore) LoadFromDBOrGenesisFile(genesisFilePath string) (State, error) {
  73. state, err := store.Load()
  74. if err != nil {
  75. return State{}, err
  76. }
  77. if state.IsEmpty() {
  78. var err error
  79. state, err = MakeGenesisStateFromFile(genesisFilePath)
  80. if err != nil {
  81. return state, err
  82. }
  83. }
  84. return state, nil
  85. }
  86. // LoadStateFromDBOrGenesisDoc loads the most recent state from the database,
  87. // or creates a new one from the given genesisDoc.
  88. func (store dbStore) LoadFromDBOrGenesisDoc(genesisDoc *types.GenesisDoc) (State, error) {
  89. state, err := store.Load()
  90. if err != nil {
  91. return State{}, err
  92. }
  93. if state.IsEmpty() {
  94. var err error
  95. state, err = MakeGenesisState(genesisDoc)
  96. if err != nil {
  97. return state, err
  98. }
  99. }
  100. return state, nil
  101. }
  102. // LoadState loads the State from the database.
  103. func (store dbStore) Load() (State, error) {
  104. return store.loadState(stateKey)
  105. }
  106. func (store dbStore) loadState(key []byte) (state State, err error) {
  107. buf, err := store.db.Get(key)
  108. if err != nil {
  109. return state, err
  110. }
  111. if len(buf) == 0 {
  112. return state, nil
  113. }
  114. sp := new(tmstate.State)
  115. err = proto.Unmarshal(buf, sp)
  116. if err != nil {
  117. // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
  118. tmos.Exit(fmt.Sprintf(`LoadState: Data has been corrupted or its spec has changed:
  119. %v\n`, err))
  120. }
  121. sm, err := StateFromProto(sp)
  122. if err != nil {
  123. return state, err
  124. }
  125. return *sm, nil
  126. }
  127. // Save persists the State, the ValidatorsInfo, and the ConsensusParamsInfo to the database.
  128. // This flushes the writes (e.g. calls SetSync).
  129. func (store dbStore) Save(state State) error {
  130. return store.save(state, stateKey)
  131. }
  132. func (store dbStore) save(state State, key []byte) error {
  133. nextHeight := state.LastBlockHeight + 1
  134. // If first block, save validators for the block.
  135. if nextHeight == 1 {
  136. nextHeight = state.InitialHeight
  137. // This extra logic due to Tendermint validator set changes being delayed 1 block.
  138. // It may get overwritten due to InitChain validator updates.
  139. if err := store.saveValidatorsInfo(nextHeight, nextHeight, state.Validators); err != nil {
  140. return err
  141. }
  142. }
  143. // Save next validators.
  144. if err := store.saveValidatorsInfo(nextHeight+1, state.LastHeightValidatorsChanged, state.NextValidators); err != nil {
  145. return err
  146. }
  147. // Save next consensus params.
  148. if err := store.saveConsensusParamsInfo(nextHeight,
  149. state.LastHeightConsensusParamsChanged, state.ConsensusParams); err != nil {
  150. return err
  151. }
  152. err := store.db.SetSync(key, state.Bytes())
  153. if err != nil {
  154. return err
  155. }
  156. return nil
  157. }
  158. // BootstrapState saves a new state, used e.g. by state sync when starting from non-zero height.
  159. func (store dbStore) Bootstrap(state State) error {
  160. height := state.LastBlockHeight + 1
  161. if height == 1 {
  162. height = state.InitialHeight
  163. }
  164. if height > 1 && !state.LastValidators.IsNilOrEmpty() {
  165. if err := store.saveValidatorsInfo(height-1, height-1, state.LastValidators); err != nil {
  166. return err
  167. }
  168. }
  169. if err := store.saveValidatorsInfo(height, height, state.Validators); err != nil {
  170. return err
  171. }
  172. if err := store.saveValidatorsInfo(height+1, height+1, state.NextValidators); err != nil {
  173. return err
  174. }
  175. if err := store.saveConsensusParamsInfo(height,
  176. state.LastHeightConsensusParamsChanged, state.ConsensusParams); err != nil {
  177. return err
  178. }
  179. return store.db.SetSync(stateKey, state.Bytes())
  180. }
  181. // PruneStates deletes states between the given heights (including from, excluding to). It is not
  182. // guaranteed to delete all states, since the last checkpointed state and states being pointed to by
  183. // e.g. `LastHeightChanged` must remain. The state at to must also exist.
  184. //
  185. // The from parameter is necessary since we can't do a key scan in a performant way due to the key
  186. // encoding not preserving ordering: https://github.com/tendermint/tendermint/issues/4567
  187. // This will cause some old states to be left behind when doing incremental partial prunes,
  188. // specifically older checkpoints and LastHeightChanged targets.
  189. func (store dbStore) PruneStates(from int64, to int64) error {
  190. if from <= 0 || to <= 0 {
  191. return fmt.Errorf("from height %v and to height %v must be greater than 0", from, to)
  192. }
  193. if from >= to {
  194. return fmt.Errorf("from height %v must be lower than to height %v", from, to)
  195. }
  196. valInfo, err := loadValidatorsInfo(store.db, to)
  197. if err != nil {
  198. return fmt.Errorf("validators at height %v not found: %w", to, err)
  199. }
  200. paramsInfo, err := store.loadConsensusParamsInfo(to)
  201. if err != nil {
  202. return fmt.Errorf("consensus params at height %v not found: %w", to, err)
  203. }
  204. keepVals := make(map[int64]bool)
  205. if valInfo.ValidatorSet == nil {
  206. keepVals[valInfo.LastHeightChanged] = true
  207. keepVals[lastStoredHeightFor(to, valInfo.LastHeightChanged)] = true // keep last checkpoint too
  208. }
  209. keepParams := make(map[int64]bool)
  210. if paramsInfo.ConsensusParams.Equal(&tmproto.ConsensusParams{}) {
  211. keepParams[paramsInfo.LastHeightChanged] = true
  212. }
  213. batch := store.db.NewBatch()
  214. defer batch.Close()
  215. pruned := uint64(0)
  216. // We have to delete in reverse order, to avoid deleting previous heights that have validator
  217. // sets and consensus params that we may need to retrieve.
  218. for h := to - 1; h >= from; h-- {
  219. // For heights we keep, we must make sure they have the full validator set or consensus
  220. // params, otherwise they will panic if they're retrieved directly (instead of
  221. // indirectly via a LastHeightChanged pointer).
  222. if keepVals[h] {
  223. v, err := loadValidatorsInfo(store.db, h)
  224. if err != nil || v.ValidatorSet == nil {
  225. vip, err := store.LoadValidators(h)
  226. if err != nil {
  227. return err
  228. }
  229. pvi, err := vip.ToProto()
  230. if err != nil {
  231. return err
  232. }
  233. v.ValidatorSet = pvi
  234. v.LastHeightChanged = h
  235. bz, err := v.Marshal()
  236. if err != nil {
  237. return err
  238. }
  239. err = batch.Set(calcValidatorsKey(h), bz)
  240. if err != nil {
  241. return err
  242. }
  243. }
  244. } else {
  245. err = batch.Delete(calcValidatorsKey(h))
  246. if err != nil {
  247. return err
  248. }
  249. }
  250. if keepParams[h] {
  251. p, err := store.loadConsensusParamsInfo(h)
  252. if err != nil {
  253. return err
  254. }
  255. if p.ConsensusParams.Equal(&tmproto.ConsensusParams{}) {
  256. p.ConsensusParams, err = store.LoadConsensusParams(h)
  257. if err != nil {
  258. return err
  259. }
  260. p.LastHeightChanged = h
  261. bz, err := p.Marshal()
  262. if err != nil {
  263. return err
  264. }
  265. err = batch.Set(calcConsensusParamsKey(h), bz)
  266. if err != nil {
  267. return err
  268. }
  269. }
  270. } else {
  271. err = batch.Delete(calcConsensusParamsKey(h))
  272. if err != nil {
  273. return err
  274. }
  275. }
  276. err = batch.Delete(calcABCIResponsesKey(h))
  277. if err != nil {
  278. return err
  279. }
  280. pruned++
  281. // avoid batches growing too large by flushing to database regularly
  282. if pruned%1000 == 0 && pruned > 0 {
  283. err := batch.Write()
  284. if err != nil {
  285. return err
  286. }
  287. batch.Close()
  288. batch = store.db.NewBatch()
  289. defer batch.Close()
  290. }
  291. }
  292. err = batch.WriteSync()
  293. if err != nil {
  294. return err
  295. }
  296. return nil
  297. }
  298. //------------------------------------------------------------------------
  299. // ABCIResponsesResultsHash returns the root hash of a Merkle tree of
  300. // ResponseDeliverTx responses (see ABCIResults.Hash)
  301. //
  302. // See merkle.SimpleHashFromByteSlices
  303. func ABCIResponsesResultsHash(ar *tmstate.ABCIResponses) []byte {
  304. return types.NewResults(ar.DeliverTxs).Hash()
  305. }
  306. // LoadABCIResponses loads the ABCIResponses for the given height from the
  307. // database. If not found, ErrNoABCIResponsesForHeight is returned.
  308. //
  309. // This is useful for recovering from crashes where we called app.Commit and
  310. // before we called s.Save(). It can also be used to produce Merkle proofs of
  311. // the result of txs.
  312. func (store dbStore) LoadABCIResponses(height int64) (*tmstate.ABCIResponses, error) {
  313. buf, err := store.db.Get(calcABCIResponsesKey(height))
  314. if err != nil {
  315. return nil, err
  316. }
  317. if len(buf) == 0 {
  318. return nil, ErrNoABCIResponsesForHeight{height}
  319. }
  320. abciResponses := new(tmstate.ABCIResponses)
  321. err = abciResponses.Unmarshal(buf)
  322. if err != nil {
  323. // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
  324. tmos.Exit(fmt.Sprintf(`LoadABCIResponses: Data has been corrupted or its spec has
  325. changed: %v\n`, err))
  326. }
  327. // TODO: ensure that buf is completely read.
  328. return abciResponses, nil
  329. }
  330. // SaveABCIResponses persists the ABCIResponses to the database.
  331. // This is useful in case we crash after app.Commit and before s.Save().
  332. // Responses are indexed by height so they can also be loaded later to produce
  333. // Merkle proofs.
  334. //
  335. // Exposed for testing.
  336. func (store dbStore) SaveABCIResponses(height int64, abciResponses *tmstate.ABCIResponses) error {
  337. var dtxs []*abci.ResponseDeliverTx
  338. // strip nil values,
  339. for _, tx := range abciResponses.DeliverTxs {
  340. if tx != nil {
  341. dtxs = append(dtxs, tx)
  342. }
  343. }
  344. abciResponses.DeliverTxs = dtxs
  345. bz, err := abciResponses.Marshal()
  346. if err != nil {
  347. return err
  348. }
  349. err = store.db.SetSync(calcABCIResponsesKey(height), bz)
  350. if err != nil {
  351. return err
  352. }
  353. return nil
  354. }
  355. //-----------------------------------------------------------------------------
  356. // LoadValidators loads the ValidatorSet for a given height.
  357. // Returns ErrNoValSetForHeight if the validator set can't be found for this height.
  358. func (store dbStore) LoadValidators(height int64) (*types.ValidatorSet, error) {
  359. valInfo, err := loadValidatorsInfo(store.db, height)
  360. if err != nil {
  361. return nil, ErrNoValSetForHeight{height}
  362. }
  363. if valInfo.ValidatorSet == nil {
  364. lastStoredHeight := lastStoredHeightFor(height, valInfo.LastHeightChanged)
  365. valInfo2, err := loadValidatorsInfo(store.db, lastStoredHeight)
  366. if err != nil || valInfo2.ValidatorSet == nil {
  367. return nil,
  368. fmt.Errorf("couldn't find validators at height %d (height %d was originally requested): %w",
  369. lastStoredHeight,
  370. height,
  371. err,
  372. )
  373. }
  374. vs, err := types.ValidatorSetFromProto(valInfo2.ValidatorSet)
  375. if err != nil {
  376. return nil, err
  377. }
  378. vs.IncrementProposerPriority(tmmath.SafeConvertInt32(height - lastStoredHeight)) // mutate
  379. vi2, err := vs.ToProto()
  380. if err != nil {
  381. return nil, err
  382. }
  383. valInfo2.ValidatorSet = vi2
  384. valInfo = valInfo2
  385. }
  386. vip, err := types.ValidatorSetFromProto(valInfo.ValidatorSet)
  387. if err != nil {
  388. return nil, err
  389. }
  390. return vip, nil
  391. }
  392. func lastStoredHeightFor(height, lastHeightChanged int64) int64 {
  393. checkpointHeight := height - height%valSetCheckpointInterval
  394. return tmmath.MaxInt64(checkpointHeight, lastHeightChanged)
  395. }
  396. // CONTRACT: Returned ValidatorsInfo can be mutated.
  397. func loadValidatorsInfo(db dbm.DB, height int64) (*tmstate.ValidatorsInfo, error) {
  398. buf, err := db.Get(calcValidatorsKey(height))
  399. if err != nil {
  400. return nil, err
  401. }
  402. if len(buf) == 0 {
  403. return nil, errors.New("value retrieved from db is empty")
  404. }
  405. v := new(tmstate.ValidatorsInfo)
  406. err = v.Unmarshal(buf)
  407. if err != nil {
  408. // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
  409. tmos.Exit(fmt.Sprintf(`LoadValidators: Data has been corrupted or its spec has changed:
  410. %v\n`, err))
  411. }
  412. // TODO: ensure that buf is completely read.
  413. return v, nil
  414. }
  415. // saveValidatorsInfo persists the validator set.
  416. //
  417. // `height` is the effective height for which the validator is responsible for
  418. // signing. It should be called from s.Save(), right before the state itself is
  419. // persisted.
  420. func (store dbStore) saveValidatorsInfo(height, lastHeightChanged int64, valSet *types.ValidatorSet) error {
  421. if lastHeightChanged > height {
  422. return errors.New("lastHeightChanged cannot be greater than ValidatorsInfo height")
  423. }
  424. valInfo := &tmstate.ValidatorsInfo{
  425. LastHeightChanged: lastHeightChanged,
  426. }
  427. // Only persist validator set if it was updated or checkpoint height (see
  428. // valSetCheckpointInterval) is reached.
  429. if height == lastHeightChanged || height%valSetCheckpointInterval == 0 {
  430. pv, err := valSet.ToProto()
  431. if err != nil {
  432. return err
  433. }
  434. valInfo.ValidatorSet = pv
  435. }
  436. bz, err := valInfo.Marshal()
  437. if err != nil {
  438. return err
  439. }
  440. err = store.db.Set(calcValidatorsKey(height), bz)
  441. if err != nil {
  442. return err
  443. }
  444. return nil
  445. }
  446. //-----------------------------------------------------------------------------
  447. // ConsensusParamsInfo represents the latest consensus params, or the last height it changed
  448. // LoadConsensusParams loads the ConsensusParams for a given height.
  449. func (store dbStore) LoadConsensusParams(height int64) (tmproto.ConsensusParams, error) {
  450. empty := tmproto.ConsensusParams{}
  451. paramsInfo, err := store.loadConsensusParamsInfo(height)
  452. if err != nil {
  453. return empty, fmt.Errorf("could not find consensus params for height #%d: %w", height, err)
  454. }
  455. if paramsInfo.ConsensusParams.Equal(&empty) {
  456. paramsInfo2, err := store.loadConsensusParamsInfo(paramsInfo.LastHeightChanged)
  457. if err != nil {
  458. return empty, fmt.Errorf(
  459. "couldn't find consensus params at height %d as last changed from height %d: %w",
  460. paramsInfo.LastHeightChanged,
  461. height,
  462. err,
  463. )
  464. }
  465. paramsInfo = paramsInfo2
  466. }
  467. return paramsInfo.ConsensusParams, nil
  468. }
  469. func (store dbStore) loadConsensusParamsInfo(height int64) (*tmstate.ConsensusParamsInfo, error) {
  470. buf, err := store.db.Get(calcConsensusParamsKey(height))
  471. if err != nil {
  472. return nil, err
  473. }
  474. if len(buf) == 0 {
  475. return nil, errors.New("value retrieved from db is empty")
  476. }
  477. paramsInfo := new(tmstate.ConsensusParamsInfo)
  478. if err = paramsInfo.Unmarshal(buf); err != nil {
  479. // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
  480. tmos.Exit(fmt.Sprintf(`LoadConsensusParams: Data has been corrupted or its spec has changed:
  481. %v\n`, err))
  482. }
  483. // TODO: ensure that buf is completely read.
  484. return paramsInfo, nil
  485. }
  486. // saveConsensusParamsInfo persists the consensus params for the next block to disk.
  487. // It should be called from s.Save(), right before the state itself is persisted.
  488. // If the consensus params did not change after processing the latest block,
  489. // only the last height for which they changed is persisted.
  490. func (store dbStore) saveConsensusParamsInfo(nextHeight, changeHeight int64, params tmproto.ConsensusParams) error {
  491. paramsInfo := &tmstate.ConsensusParamsInfo{
  492. LastHeightChanged: changeHeight,
  493. }
  494. if changeHeight == nextHeight {
  495. paramsInfo.ConsensusParams = params
  496. }
  497. bz, err := paramsInfo.Marshal()
  498. if err != nil {
  499. return err
  500. }
  501. err = store.db.Set(calcConsensusParamsKey(nextHeight), bz)
  502. if err != nil {
  503. return err
  504. }
  505. return nil
  506. }