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.

105 lines
3.2 KiB

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
  1. package core
  2. import (
  3. "bytes"
  4. "time"
  5. tmbytes "github.com/tendermint/tendermint/libs/bytes"
  6. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  7. rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
  8. "github.com/tendermint/tendermint/types"
  9. )
  10. // Status returns Tendermint status including node info, pubkey, latest block
  11. // hash, app hash, block height, current max peer block height, and time.
  12. // More: https://docs.tendermint.com/master/rpc/#/Info/status
  13. func (env *Environment) Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) {
  14. var (
  15. earliestBlockHeight int64
  16. earliestBlockHash tmbytes.HexBytes
  17. earliestAppHash tmbytes.HexBytes
  18. earliestBlockTimeNano int64
  19. )
  20. if earliestBlockMeta := env.BlockStore.LoadBaseMeta(); earliestBlockMeta != nil {
  21. earliestBlockHeight = earliestBlockMeta.Header.Height
  22. earliestAppHash = earliestBlockMeta.Header.AppHash
  23. earliestBlockHash = earliestBlockMeta.BlockID.Hash
  24. earliestBlockTimeNano = earliestBlockMeta.Header.Time.UnixNano()
  25. }
  26. var (
  27. latestBlockHash tmbytes.HexBytes
  28. latestAppHash tmbytes.HexBytes
  29. latestBlockTimeNano int64
  30. latestHeight = env.BlockStore.Height()
  31. )
  32. if latestHeight != 0 {
  33. if latestBlockMeta := env.BlockStore.LoadBlockMeta(latestHeight); latestBlockMeta != nil {
  34. latestBlockHash = latestBlockMeta.BlockID.Hash
  35. latestAppHash = latestBlockMeta.Header.AppHash
  36. latestBlockTimeNano = latestBlockMeta.Header.Time.UnixNano()
  37. }
  38. }
  39. // Return the very last voting power, not the voting power of this validator
  40. // during the last block.
  41. var votingPower int64
  42. if val := env.validatorAtHeight(env.latestUncommittedHeight()); val != nil {
  43. votingPower = val.VotingPower
  44. }
  45. validatorInfo := ctypes.ValidatorInfo{}
  46. if env.PubKey != nil {
  47. validatorInfo = ctypes.ValidatorInfo{
  48. Address: env.PubKey.Address(),
  49. PubKey: env.PubKey,
  50. VotingPower: votingPower,
  51. }
  52. }
  53. result := &ctypes.ResultStatus{
  54. NodeInfo: env.P2PTransport.NodeInfo(),
  55. SyncInfo: ctypes.SyncInfo{
  56. LatestBlockHash: latestBlockHash,
  57. LatestAppHash: latestAppHash,
  58. LatestBlockHeight: latestHeight,
  59. LatestBlockTime: time.Unix(0, latestBlockTimeNano),
  60. EarliestBlockHash: earliestBlockHash,
  61. EarliestAppHash: earliestAppHash,
  62. EarliestBlockHeight: earliestBlockHeight,
  63. EarliestBlockTime: time.Unix(0, earliestBlockTimeNano),
  64. MaxPeerBlockHeight: env.BlockSyncReactor.GetMaxPeerBlockHeight(),
  65. CatchingUp: env.ConsensusReactor.WaitSync(),
  66. TotalSyncedTime: env.BlockSyncReactor.GetTotalSyncedTime(),
  67. RemainingTime: env.BlockSyncReactor.GetRemainingSyncTime(),
  68. },
  69. ValidatorInfo: validatorInfo,
  70. }
  71. return result, nil
  72. }
  73. func (env *Environment) validatorAtHeight(h int64) *types.Validator {
  74. valsWithH, err := env.StateStore.LoadValidators(h)
  75. if err != nil {
  76. return nil
  77. }
  78. if env.PubKey == nil {
  79. return nil
  80. }
  81. privValAddress := env.PubKey.Address()
  82. // If we're still at height h, search in the current validator set.
  83. lastBlockHeight, vals := env.ConsensusState.GetValidators()
  84. if lastBlockHeight == h {
  85. for _, val := range vals {
  86. if bytes.Equal(val.Address, privValAddress) {
  87. return val
  88. }
  89. }
  90. }
  91. _, val := valsWithH.GetByAddress(privValAddress)
  92. return val
  93. }