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.

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