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.

594 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, height, state.ConsensusParams); err != nil {
  176. return err
  177. }
  178. return store.db.SetSync(stateKey, state.Bytes())
  179. }
  180. // PruneStates deletes states between the given heights (including from, excluding to). It is not
  181. // guaranteed to delete all states, since the last checkpointed state and states being pointed to by
  182. // e.g. `LastHeightChanged` must remain. The state at to must also exist.
  183. //
  184. // The from parameter is necessary since we can't do a key scan in a performant way due to the key
  185. // encoding not preserving ordering: https://github.com/tendermint/tendermint/issues/4567
  186. // This will cause some old states to be left behind when doing incremental partial prunes,
  187. // specifically older checkpoints and LastHeightChanged targets.
  188. func (store dbStore) PruneStates(from int64, to int64) error {
  189. if from <= 0 || to <= 0 {
  190. return fmt.Errorf("from height %v and to height %v must be greater than 0", from, to)
  191. }
  192. if from >= to {
  193. return fmt.Errorf("from height %v must be lower than to height %v", from, to)
  194. }
  195. valInfo, err := loadValidatorsInfo(store.db, to)
  196. if err != nil {
  197. return fmt.Errorf("validators at height %v not found: %w", to, err)
  198. }
  199. paramsInfo, err := store.loadConsensusParamsInfo(to)
  200. if err != nil {
  201. return fmt.Errorf("consensus params at height %v not found: %w", to, err)
  202. }
  203. keepVals := make(map[int64]bool)
  204. if valInfo.ValidatorSet == nil {
  205. keepVals[valInfo.LastHeightChanged] = true
  206. keepVals[lastStoredHeightFor(to, valInfo.LastHeightChanged)] = true // keep last checkpoint too
  207. }
  208. keepParams := make(map[int64]bool)
  209. if paramsInfo.ConsensusParams.Equal(&tmproto.ConsensusParams{}) {
  210. keepParams[paramsInfo.LastHeightChanged] = true
  211. }
  212. batch := store.db.NewBatch()
  213. defer batch.Close()
  214. pruned := uint64(0)
  215. // We have to delete in reverse order, to avoid deleting previous heights that have validator
  216. // sets and consensus params that we may need to retrieve.
  217. for h := to - 1; h >= from; h-- {
  218. // For heights we keep, we must make sure they have the full validator set or consensus
  219. // params, otherwise they will panic if they're retrieved directly (instead of
  220. // indirectly via a LastHeightChanged pointer).
  221. if keepVals[h] {
  222. v, err := loadValidatorsInfo(store.db, h)
  223. if err != nil || v.ValidatorSet == nil {
  224. vip, err := store.LoadValidators(h)
  225. if err != nil {
  226. return err
  227. }
  228. pvi, err := vip.ToProto()
  229. if err != nil {
  230. return err
  231. }
  232. v.ValidatorSet = pvi
  233. v.LastHeightChanged = h
  234. bz, err := v.Marshal()
  235. if err != nil {
  236. return err
  237. }
  238. err = batch.Set(calcValidatorsKey(h), bz)
  239. if err != nil {
  240. return err
  241. }
  242. }
  243. } else {
  244. err = batch.Delete(calcValidatorsKey(h))
  245. if err != nil {
  246. return err
  247. }
  248. }
  249. if keepParams[h] {
  250. p, err := store.loadConsensusParamsInfo(h)
  251. if err != nil {
  252. return err
  253. }
  254. if p.ConsensusParams.Equal(&tmproto.ConsensusParams{}) {
  255. p.ConsensusParams, err = store.LoadConsensusParams(h)
  256. if err != nil {
  257. return err
  258. }
  259. p.LastHeightChanged = h
  260. bz, err := p.Marshal()
  261. if err != nil {
  262. return err
  263. }
  264. err = batch.Set(calcConsensusParamsKey(h), bz)
  265. if err != nil {
  266. return err
  267. }
  268. }
  269. } else {
  270. err = batch.Delete(calcConsensusParamsKey(h))
  271. if err != nil {
  272. return err
  273. }
  274. }
  275. err = batch.Delete(calcABCIResponsesKey(h))
  276. if err != nil {
  277. return err
  278. }
  279. pruned++
  280. // avoid batches growing too large by flushing to database regularly
  281. if pruned%1000 == 0 && pruned > 0 {
  282. err := batch.Write()
  283. if err != nil {
  284. return err
  285. }
  286. batch.Close()
  287. batch = store.db.NewBatch()
  288. defer batch.Close()
  289. }
  290. }
  291. err = batch.WriteSync()
  292. if err != nil {
  293. return err
  294. }
  295. return nil
  296. }
  297. //------------------------------------------------------------------------
  298. // ABCIResponsesResultsHash returns the root hash of a Merkle tree of
  299. // ResponseDeliverTx responses (see ABCIResults.Hash)
  300. //
  301. // See merkle.SimpleHashFromByteSlices
  302. func ABCIResponsesResultsHash(ar *tmstate.ABCIResponses) []byte {
  303. return types.NewResults(ar.DeliverTxs).Hash()
  304. }
  305. // LoadABCIResponses loads the ABCIResponses for the given height from the
  306. // database. If not found, ErrNoABCIResponsesForHeight is returned.
  307. //
  308. // This is useful for recovering from crashes where we called app.Commit and
  309. // before we called s.Save(). It can also be used to produce Merkle proofs of
  310. // the result of txs.
  311. func (store dbStore) LoadABCIResponses(height int64) (*tmstate.ABCIResponses, error) {
  312. buf, err := store.db.Get(calcABCIResponsesKey(height))
  313. if err != nil {
  314. return nil, err
  315. }
  316. if len(buf) == 0 {
  317. return nil, ErrNoABCIResponsesForHeight{height}
  318. }
  319. abciResponses := new(tmstate.ABCIResponses)
  320. err = abciResponses.Unmarshal(buf)
  321. if err != nil {
  322. // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
  323. tmos.Exit(fmt.Sprintf(`LoadABCIResponses: Data has been corrupted or its spec has
  324. changed: %v\n`, err))
  325. }
  326. // TODO: ensure that buf is completely read.
  327. return abciResponses, nil
  328. }
  329. // SaveABCIResponses persists the ABCIResponses to the database.
  330. // This is useful in case we crash after app.Commit and before s.Save().
  331. // Responses are indexed by height so they can also be loaded later to produce
  332. // Merkle proofs.
  333. //
  334. // Exposed for testing.
  335. func (store dbStore) SaveABCIResponses(height int64, abciResponses *tmstate.ABCIResponses) error {
  336. var dtxs []*abci.ResponseDeliverTx
  337. // strip nil values,
  338. for _, tx := range abciResponses.DeliverTxs {
  339. if tx != nil {
  340. dtxs = append(dtxs, tx)
  341. }
  342. }
  343. abciResponses.DeliverTxs = dtxs
  344. bz, err := abciResponses.Marshal()
  345. if err != nil {
  346. return err
  347. }
  348. err = store.db.SetSync(calcABCIResponsesKey(height), bz)
  349. if err != nil {
  350. return err
  351. }
  352. return nil
  353. }
  354. //-----------------------------------------------------------------------------
  355. // LoadValidators loads the ValidatorSet for a given height.
  356. // Returns ErrNoValSetForHeight if the validator set can't be found for this height.
  357. func (store dbStore) LoadValidators(height int64) (*types.ValidatorSet, error) {
  358. valInfo, err := loadValidatorsInfo(store.db, height)
  359. if err != nil {
  360. return nil, ErrNoValSetForHeight{height}
  361. }
  362. if valInfo.ValidatorSet == nil {
  363. lastStoredHeight := lastStoredHeightFor(height, valInfo.LastHeightChanged)
  364. valInfo2, err := loadValidatorsInfo(store.db, lastStoredHeight)
  365. if err != nil || valInfo2.ValidatorSet == nil {
  366. return nil,
  367. fmt.Errorf("couldn't find validators at height %d (height %d was originally requested): %w",
  368. lastStoredHeight,
  369. height,
  370. err,
  371. )
  372. }
  373. vs, err := types.ValidatorSetFromProto(valInfo2.ValidatorSet)
  374. if err != nil {
  375. return nil, err
  376. }
  377. vs.IncrementProposerPriority(tmmath.SafeConvertInt32(height - lastStoredHeight)) // mutate
  378. vi2, err := vs.ToProto()
  379. if err != nil {
  380. return nil, err
  381. }
  382. valInfo2.ValidatorSet = vi2
  383. valInfo = valInfo2
  384. }
  385. vip, err := types.ValidatorSetFromProto(valInfo.ValidatorSet)
  386. if err != nil {
  387. return nil, err
  388. }
  389. return vip, nil
  390. }
  391. func lastStoredHeightFor(height, lastHeightChanged int64) int64 {
  392. checkpointHeight := height - height%valSetCheckpointInterval
  393. return tmmath.MaxInt64(checkpointHeight, lastHeightChanged)
  394. }
  395. // CONTRACT: Returned ValidatorsInfo can be mutated.
  396. func loadValidatorsInfo(db dbm.DB, height int64) (*tmstate.ValidatorsInfo, error) {
  397. buf, err := db.Get(calcValidatorsKey(height))
  398. if err != nil {
  399. return nil, err
  400. }
  401. if len(buf) == 0 {
  402. return nil, errors.New("value retrieved from db is empty")
  403. }
  404. v := new(tmstate.ValidatorsInfo)
  405. err = v.Unmarshal(buf)
  406. if err != nil {
  407. // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
  408. tmos.Exit(fmt.Sprintf(`LoadValidators: Data has been corrupted or its spec has changed:
  409. %v\n`, err))
  410. }
  411. // TODO: ensure that buf is completely read.
  412. return v, nil
  413. }
  414. // saveValidatorsInfo persists the validator set.
  415. //
  416. // `height` is the effective height for which the validator is responsible for
  417. // signing. It should be called from s.Save(), right before the state itself is
  418. // persisted.
  419. func (store dbStore) saveValidatorsInfo(height, lastHeightChanged int64, valSet *types.ValidatorSet) error {
  420. if lastHeightChanged > height {
  421. return errors.New("lastHeightChanged cannot be greater than ValidatorsInfo height")
  422. }
  423. valInfo := &tmstate.ValidatorsInfo{
  424. LastHeightChanged: lastHeightChanged,
  425. }
  426. // Only persist validator set if it was updated or checkpoint height (see
  427. // valSetCheckpointInterval) is reached.
  428. if height == lastHeightChanged || height%valSetCheckpointInterval == 0 {
  429. pv, err := valSet.ToProto()
  430. if err != nil {
  431. return err
  432. }
  433. valInfo.ValidatorSet = pv
  434. }
  435. bz, err := valInfo.Marshal()
  436. if err != nil {
  437. return err
  438. }
  439. err = store.db.Set(calcValidatorsKey(height), bz)
  440. if err != nil {
  441. return err
  442. }
  443. return nil
  444. }
  445. //-----------------------------------------------------------------------------
  446. // ConsensusParamsInfo represents the latest consensus params, or the last height it changed
  447. // LoadConsensusParams loads the ConsensusParams for a given height.
  448. func (store dbStore) LoadConsensusParams(height int64) (tmproto.ConsensusParams, error) {
  449. empty := tmproto.ConsensusParams{}
  450. paramsInfo, err := store.loadConsensusParamsInfo(height)
  451. if err != nil {
  452. return empty, fmt.Errorf("could not find consensus params for height #%d: %w", height, err)
  453. }
  454. if paramsInfo.ConsensusParams.Equal(&empty) {
  455. paramsInfo2, err := store.loadConsensusParamsInfo(paramsInfo.LastHeightChanged)
  456. if err != nil {
  457. return empty, fmt.Errorf(
  458. "couldn't find consensus params at height %d as last changed from height %d: %w",
  459. paramsInfo.LastHeightChanged,
  460. height,
  461. err,
  462. )
  463. }
  464. paramsInfo = paramsInfo2
  465. }
  466. return paramsInfo.ConsensusParams, nil
  467. }
  468. func (store dbStore) loadConsensusParamsInfo(height int64) (*tmstate.ConsensusParamsInfo, error) {
  469. buf, err := store.db.Get(calcConsensusParamsKey(height))
  470. if err != nil {
  471. return nil, err
  472. }
  473. if len(buf) == 0 {
  474. return nil, errors.New("value retrieved from db is empty")
  475. }
  476. paramsInfo := new(tmstate.ConsensusParamsInfo)
  477. if err = paramsInfo.Unmarshal(buf); err != nil {
  478. // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
  479. tmos.Exit(fmt.Sprintf(`LoadConsensusParams: Data has been corrupted or its spec has changed:
  480. %v\n`, err))
  481. }
  482. // TODO: ensure that buf is completely read.
  483. return paramsInfo, nil
  484. }
  485. // saveConsensusParamsInfo persists the consensus params for the next block to disk.
  486. // It should be called from s.Save(), right before the state itself is persisted.
  487. // If the consensus params did not change after processing the latest block,
  488. // only the last height for which they changed is persisted.
  489. func (store dbStore) saveConsensusParamsInfo(nextHeight, changeHeight int64, params tmproto.ConsensusParams) error {
  490. paramsInfo := &tmstate.ConsensusParamsInfo{
  491. LastHeightChanged: changeHeight,
  492. }
  493. if changeHeight == nextHeight {
  494. paramsInfo.ConsensusParams = params
  495. }
  496. bz, err := paramsInfo.Marshal()
  497. if err != nil {
  498. return err
  499. }
  500. err = store.db.Set(calcConsensusParamsKey(nextHeight), bz)
  501. if err != nil {
  502. return err
  503. }
  504. return nil
  505. }