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.

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