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.

282 lines
8.3 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. // ResultHeader represents the response for a Header RPC Client query
  47. type ResultHeader struct {
  48. Header *types.Header `json:"header"`
  49. }
  50. // Commit and Header
  51. type ResultCommit struct {
  52. types.SignedHeader `json:"signed_header"`
  53. CanonicalCommit bool `json:"canonical"`
  54. }
  55. // ABCI results from a block
  56. type ResultBlockResults struct {
  57. Height int64 `json:"height"`
  58. TxsResults []*abci.ResponseDeliverTx `json:"txs_results"`
  59. TotalGasUsed int64 `json:"total_gas_used"`
  60. BeginBlockEvents []abci.Event `json:"begin_block_events"`
  61. EndBlockEvents []abci.Event `json:"end_block_events"`
  62. ValidatorUpdates []abci.ValidatorUpdate `json:"validator_updates"`
  63. ConsensusParamUpdates *tmproto.ConsensusParams `json:"consensus_param_updates"`
  64. }
  65. // NewResultCommit is a helper to initialize the ResultCommit with
  66. // the embedded struct
  67. func NewResultCommit(header *types.Header, commit *types.Commit,
  68. canonical bool) *ResultCommit {
  69. return &ResultCommit{
  70. SignedHeader: types.SignedHeader{
  71. Header: header,
  72. Commit: commit,
  73. },
  74. CanonicalCommit: canonical,
  75. }
  76. }
  77. // Info about the node's syncing state
  78. type SyncInfo struct {
  79. LatestBlockHash bytes.HexBytes `json:"latest_block_hash"`
  80. LatestAppHash bytes.HexBytes `json:"latest_app_hash"`
  81. LatestBlockHeight int64 `json:"latest_block_height"`
  82. LatestBlockTime time.Time `json:"latest_block_time"`
  83. EarliestBlockHash bytes.HexBytes `json:"earliest_block_hash"`
  84. EarliestAppHash bytes.HexBytes `json:"earliest_app_hash"`
  85. EarliestBlockHeight int64 `json:"earliest_block_height"`
  86. EarliestBlockTime time.Time `json:"earliest_block_time"`
  87. MaxPeerBlockHeight int64 `json:"max_peer_block_height"`
  88. CatchingUp bool `json:"catching_up"`
  89. TotalSyncedTime time.Duration `json:"total_synced_time"`
  90. RemainingTime time.Duration `json:"remaining_time"`
  91. TotalSnapshots int64 `json:"total_snapshots"`
  92. ChunkProcessAvgTime time.Duration `json:"chunk_process_avg_time"`
  93. SnapshotHeight int64 `json:"snapshot_height"`
  94. SnapshotChunksCount int64 `json:"snapshot_chunks_count"`
  95. SnapshotChunksTotal int64 `json:"snapshot_chunks_total"`
  96. BackFilledBlocks int64 `json:"backfilled_blocks"`
  97. BackFillBlocksTotal int64 `json:"backfill_blocks_total"`
  98. }
  99. // Info about the node's validator
  100. type ValidatorInfo struct {
  101. Address bytes.HexBytes `json:"address"`
  102. PubKey crypto.PubKey `json:"pub_key"`
  103. VotingPower int64 `json:"voting_power"`
  104. }
  105. // Node Status
  106. type ResultStatus struct {
  107. NodeInfo types.NodeInfo `json:"node_info"`
  108. SyncInfo SyncInfo `json:"sync_info"`
  109. ValidatorInfo ValidatorInfo `json:"validator_info"`
  110. }
  111. // Is TxIndexing enabled
  112. func (s *ResultStatus) TxIndexEnabled() bool {
  113. if s == nil {
  114. return false
  115. }
  116. return s.NodeInfo.Other.TxIndex == "on"
  117. }
  118. // Info about peer connections
  119. type ResultNetInfo struct {
  120. Listening bool `json:"listening"`
  121. Listeners []string `json:"listeners"`
  122. NPeers int `json:"n_peers"`
  123. Peers []Peer `json:"peers"`
  124. }
  125. // Log from dialing seeds
  126. type ResultDialSeeds struct {
  127. Log string `json:"log"`
  128. }
  129. // Log from dialing peers
  130. type ResultDialPeers struct {
  131. Log string `json:"log"`
  132. }
  133. // A peer
  134. type Peer struct {
  135. ID types.NodeID `json:"node_id"`
  136. URL string `json:"url"`
  137. }
  138. // Validators for a height.
  139. type ResultValidators struct {
  140. BlockHeight int64 `json:"block_height"`
  141. Validators []*types.Validator `json:"validators"`
  142. // Count of actual validators in this result
  143. Count int `json:"count"`
  144. // Total number of validators
  145. Total int `json:"total"`
  146. }
  147. // ConsensusParams for given height
  148. type ResultConsensusParams struct {
  149. BlockHeight int64 `json:"block_height"`
  150. ConsensusParams types.ConsensusParams `json:"consensus_params"`
  151. }
  152. // Info about the consensus state.
  153. // UNSTABLE
  154. type ResultDumpConsensusState struct {
  155. RoundState json.RawMessage `json:"round_state"`
  156. Peers []PeerStateInfo `json:"peers"`
  157. }
  158. // UNSTABLE
  159. type PeerStateInfo struct {
  160. NodeAddress string `json:"node_address"`
  161. PeerState json.RawMessage `json:"peer_state"`
  162. }
  163. // UNSTABLE
  164. type ResultConsensusState struct {
  165. RoundState json.RawMessage `json:"round_state"`
  166. }
  167. // CheckTx result
  168. type ResultBroadcastTx struct {
  169. Code uint32 `json:"code"`
  170. Data bytes.HexBytes `json:"data"`
  171. Log string `json:"log"`
  172. Codespace string `json:"codespace"`
  173. MempoolError string `json:"mempool_error"`
  174. Hash bytes.HexBytes `json:"hash"`
  175. }
  176. // CheckTx and DeliverTx results
  177. type ResultBroadcastTxCommit struct {
  178. CheckTx abci.ResponseCheckTx `json:"check_tx"`
  179. DeliverTx abci.ResponseDeliverTx `json:"deliver_tx"`
  180. Hash bytes.HexBytes `json:"hash"`
  181. Height int64 `json:"height"`
  182. }
  183. // ResultCheckTx wraps abci.ResponseCheckTx.
  184. type ResultCheckTx struct {
  185. abci.ResponseCheckTx
  186. }
  187. // Result of querying for a tx
  188. type ResultTx struct {
  189. Hash bytes.HexBytes `json:"hash"`
  190. Height int64 `json:"height"`
  191. Index uint32 `json:"index"`
  192. TxResult abci.ResponseDeliverTx `json:"tx_result"`
  193. Tx types.Tx `json:"tx"`
  194. Proof types.TxProof `json:"proof,omitempty"`
  195. }
  196. // Result of searching for txs
  197. type ResultTxSearch struct {
  198. Txs []*ResultTx `json:"txs"`
  199. TotalCount int `json:"total_count"`
  200. }
  201. // ResultBlockSearch defines the RPC response type for a block search by events.
  202. type ResultBlockSearch struct {
  203. Blocks []*ResultBlock `json:"blocks"`
  204. TotalCount int `json:"total_count"`
  205. }
  206. // List of mempool txs
  207. type ResultUnconfirmedTxs struct {
  208. Count int `json:"n_txs"`
  209. Total int `json:"total"`
  210. TotalBytes int64 `json:"total_bytes"`
  211. Txs []types.Tx `json:"txs"`
  212. }
  213. // Info abci msg
  214. type ResultABCIInfo struct {
  215. Response abci.ResponseInfo `json:"response"`
  216. }
  217. // Query abci msg
  218. type ResultABCIQuery struct {
  219. Response abci.ResponseQuery `json:"response"`
  220. }
  221. // Result of broadcasting evidence
  222. type ResultBroadcastEvidence struct {
  223. Hash []byte `json:"hash"`
  224. }
  225. // empty results
  226. type (
  227. ResultUnsafeFlushMempool struct{}
  228. ResultUnsafeProfile struct{}
  229. ResultSubscribe struct{}
  230. ResultUnsubscribe struct{}
  231. ResultHealth struct{}
  232. )
  233. // Event data from a subscription
  234. type ResultEvent struct {
  235. SubscriptionID string `json:"subscription_id"`
  236. Query string `json:"query"`
  237. Data types.TMEventData `json:"data"`
  238. Events []abci.Event `json:"events"`
  239. }