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.

277 lines
8.1 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>
4 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>
4 years ago
  1. package coretypes
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "time"
  6. abci "github.com/tendermint/tendermint/abci/types"
  7. "github.com/tendermint/tendermint/crypto"
  8. "github.com/tendermint/tendermint/libs/bytes"
  9. tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
  10. "github.com/tendermint/tendermint/types"
  11. )
  12. // List of standardized errors used across RPC
  13. var (
  14. ErrZeroOrNegativePerPage = errors.New("zero or negative per_page")
  15. ErrPageOutOfRange = errors.New("page should be within range")
  16. ErrZeroOrNegativeHeight = errors.New("height must be greater than zero")
  17. ErrHeightExceedsChainHead = errors.New("height must be less than or equal to the head of the node's blockchain")
  18. ErrHeightNotAvailable = errors.New("height is not available")
  19. // ErrInvalidRequest is used as a wrapper to cover more specific cases where the user has
  20. // made an invalid request
  21. ErrInvalidRequest = errors.New("invalid request")
  22. )
  23. // List of blocks
  24. type ResultBlockchainInfo struct {
  25. LastHeight int64 `json:"last_height"`
  26. BlockMetas []*types.BlockMeta `json:"block_metas"`
  27. }
  28. // Genesis file
  29. type ResultGenesis struct {
  30. Genesis *types.GenesisDoc `json:"genesis"`
  31. }
  32. // ResultGenesisChunk is the output format for the chunked/paginated
  33. // interface. These chunks are produced by converting the genesis
  34. // document to JSON and then splitting the resulting payload into
  35. // 16 megabyte blocks and then base64 encoding each block.
  36. type ResultGenesisChunk struct {
  37. ChunkNumber int `json:"chunk"`
  38. TotalChunks int `json:"total"`
  39. Data string `json:"data"`
  40. }
  41. // Single block (with meta)
  42. type ResultBlock struct {
  43. BlockID types.BlockID `json:"block_id"`
  44. Block *types.Block `json:"block"`
  45. }
  46. // Commit and Header
  47. type ResultCommit struct {
  48. types.SignedHeader `json:"signed_header"`
  49. CanonicalCommit bool `json:"canonical"`
  50. }
  51. // ABCI results from a block
  52. type ResultBlockResults struct {
  53. Height int64 `json:"height"`
  54. TxsResults []*abci.ResponseDeliverTx `json:"txs_results"`
  55. TotalGasUsed int64 `json:"total_gas_used"`
  56. BeginBlockEvents []abci.Event `json:"begin_block_events"`
  57. EndBlockEvents []abci.Event `json:"end_block_events"`
  58. ValidatorUpdates []abci.ValidatorUpdate `json:"validator_updates"`
  59. ConsensusParamUpdates *tmproto.ConsensusParams `json:"consensus_param_updates"`
  60. }
  61. // NewResultCommit is a helper to initialize the ResultCommit with
  62. // the embedded struct
  63. func NewResultCommit(header *types.Header, commit *types.Commit,
  64. canonical bool) *ResultCommit {
  65. return &ResultCommit{
  66. SignedHeader: types.SignedHeader{
  67. Header: header,
  68. Commit: commit,
  69. },
  70. CanonicalCommit: canonical,
  71. }
  72. }
  73. // Info about the node's syncing state
  74. type SyncInfo struct {
  75. LatestBlockHash bytes.HexBytes `json:"latest_block_hash"`
  76. LatestAppHash bytes.HexBytes `json:"latest_app_hash"`
  77. LatestBlockHeight int64 `json:"latest_block_height"`
  78. LatestBlockTime time.Time `json:"latest_block_time"`
  79. EarliestBlockHash bytes.HexBytes `json:"earliest_block_hash"`
  80. EarliestAppHash bytes.HexBytes `json:"earliest_app_hash"`
  81. EarliestBlockHeight int64 `json:"earliest_block_height"`
  82. EarliestBlockTime time.Time `json:"earliest_block_time"`
  83. MaxPeerBlockHeight int64 `json:"max_peer_block_height"`
  84. CatchingUp bool `json:"catching_up"`
  85. TotalSyncedTime time.Duration `json:"total_synced_time"`
  86. RemainingTime time.Duration `json:"remaining_time"`
  87. TotalSnapshots int64 `json:"total_snapshots"`
  88. ChunkProcessAvgTime time.Duration `json:"chunk_process_avg_time"`
  89. SnapshotHeight int64 `json:"snapshot_height"`
  90. SnapshotChunksCount int64 `json:"snapshot_chunks_count"`
  91. SnapshotChunksTotal int64 `json:"snapshot_chunks_total"`
  92. BackFilledBlocks int64 `json:"backfilled_blocks"`
  93. BackFillBlocksTotal int64 `json:"backfill_blocks_total"`
  94. }
  95. // Info about the node's validator
  96. type ValidatorInfo struct {
  97. Address bytes.HexBytes `json:"address"`
  98. PubKey crypto.PubKey `json:"pub_key"`
  99. VotingPower int64 `json:"voting_power"`
  100. }
  101. // Node Status
  102. type ResultStatus struct {
  103. NodeInfo types.NodeInfo `json:"node_info"`
  104. SyncInfo SyncInfo `json:"sync_info"`
  105. ValidatorInfo ValidatorInfo `json:"validator_info"`
  106. }
  107. // Is TxIndexing enabled
  108. func (s *ResultStatus) TxIndexEnabled() bool {
  109. if s == nil {
  110. return false
  111. }
  112. return s.NodeInfo.Other.TxIndex == "on"
  113. }
  114. // Info about peer connections
  115. type ResultNetInfo struct {
  116. Listening bool `json:"listening"`
  117. Listeners []string `json:"listeners"`
  118. NPeers int `json:"n_peers"`
  119. Peers []Peer `json:"peers"`
  120. }
  121. // Log from dialing seeds
  122. type ResultDialSeeds struct {
  123. Log string `json:"log"`
  124. }
  125. // Log from dialing peers
  126. type ResultDialPeers struct {
  127. Log string `json:"log"`
  128. }
  129. // A peer
  130. type Peer struct {
  131. ID types.NodeID `json:"node_id"`
  132. URL string `json:"url"`
  133. }
  134. // Validators for a height.
  135. type ResultValidators struct {
  136. BlockHeight int64 `json:"block_height"`
  137. Validators []*types.Validator `json:"validators"`
  138. // Count of actual validators in this result
  139. Count int `json:"count"`
  140. // Total number of validators
  141. Total int `json:"total"`
  142. }
  143. // ConsensusParams for given height
  144. type ResultConsensusParams struct {
  145. BlockHeight int64 `json:"block_height"`
  146. ConsensusParams types.ConsensusParams `json:"consensus_params"`
  147. }
  148. // Info about the consensus state.
  149. // UNSTABLE
  150. type ResultDumpConsensusState struct {
  151. RoundState json.RawMessage `json:"round_state"`
  152. Peers []PeerStateInfo `json:"peers"`
  153. }
  154. // UNSTABLE
  155. type PeerStateInfo struct {
  156. NodeAddress string `json:"node_address"`
  157. PeerState json.RawMessage `json:"peer_state"`
  158. }
  159. // UNSTABLE
  160. type ResultConsensusState struct {
  161. RoundState json.RawMessage `json:"round_state"`
  162. }
  163. // CheckTx result
  164. type ResultBroadcastTx struct {
  165. Code uint32 `json:"code"`
  166. Data bytes.HexBytes `json:"data"`
  167. Log string `json:"log"`
  168. Codespace string `json:"codespace"`
  169. MempoolError string `json:"mempool_error"`
  170. Hash bytes.HexBytes `json:"hash"`
  171. }
  172. // CheckTx and DeliverTx results
  173. type ResultBroadcastTxCommit struct {
  174. CheckTx abci.ResponseCheckTx `json:"check_tx"`
  175. DeliverTx abci.ResponseDeliverTx `json:"deliver_tx"`
  176. Hash bytes.HexBytes `json:"hash"`
  177. Height int64 `json:"height"`
  178. }
  179. // ResultCheckTx wraps abci.ResponseCheckTx.
  180. type ResultCheckTx struct {
  181. abci.ResponseCheckTx
  182. }
  183. // Result of querying for a tx
  184. type ResultTx struct {
  185. Hash bytes.HexBytes `json:"hash"`
  186. Height int64 `json:"height"`
  187. Index uint32 `json:"index"`
  188. TxResult abci.ResponseDeliverTx `json:"tx_result"`
  189. Tx types.Tx `json:"tx"`
  190. Proof types.TxProof `json:"proof,omitempty"`
  191. }
  192. // Result of searching for txs
  193. type ResultTxSearch struct {
  194. Txs []*ResultTx `json:"txs"`
  195. TotalCount int `json:"total_count"`
  196. }
  197. // ResultBlockSearch defines the RPC response type for a block search by events.
  198. type ResultBlockSearch struct {
  199. Blocks []*ResultBlock `json:"blocks"`
  200. TotalCount int `json:"total_count"`
  201. }
  202. // List of mempool txs
  203. type ResultUnconfirmedTxs struct {
  204. Count int `json:"n_txs"`
  205. Total int `json:"total"`
  206. TotalBytes int64 `json:"total_bytes"`
  207. Txs []types.Tx `json:"txs"`
  208. }
  209. // Info abci msg
  210. type ResultABCIInfo struct {
  211. Response abci.ResponseInfo `json:"response"`
  212. }
  213. // Query abci msg
  214. type ResultABCIQuery struct {
  215. Response abci.ResponseQuery `json:"response"`
  216. }
  217. // Result of broadcasting evidence
  218. type ResultBroadcastEvidence struct {
  219. Hash []byte `json:"hash"`
  220. }
  221. // empty results
  222. type (
  223. ResultUnsafeFlushMempool struct{}
  224. ResultUnsafeProfile struct{}
  225. ResultSubscribe struct{}
  226. ResultUnsubscribe struct{}
  227. ResultHealth struct{}
  228. )
  229. // Event data from a subscription
  230. type ResultEvent struct {
  231. SubscriptionID string `json:"subscription_id"`
  232. Query string `json:"query"`
  233. Data types.TMEventData `json:"data"`
  234. Events []abci.Event `json:"events"`
  235. }