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.

267 lines
7.7 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. 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. }
  86. // Info about the node's validator
  87. type ValidatorInfo struct {
  88. Address bytes.HexBytes `json:"address"`
  89. PubKey crypto.PubKey `json:"pub_key"`
  90. VotingPower int64 `json:"voting_power"`
  91. }
  92. // Node Status
  93. type ResultStatus struct {
  94. NodeInfo types.NodeInfo `json:"node_info"`
  95. SyncInfo SyncInfo `json:"sync_info"`
  96. ValidatorInfo ValidatorInfo `json:"validator_info"`
  97. }
  98. // Is TxIndexing enabled
  99. func (s *ResultStatus) TxIndexEnabled() bool {
  100. if s == nil {
  101. return false
  102. }
  103. return s.NodeInfo.Other.TxIndex == "on"
  104. }
  105. // Info about peer connections
  106. type ResultNetInfo struct {
  107. Listening bool `json:"listening"`
  108. Listeners []string `json:"listeners"`
  109. NPeers int `json:"n_peers"`
  110. Peers []Peer `json:"peers"`
  111. }
  112. // Log from dialing seeds
  113. type ResultDialSeeds struct {
  114. Log string `json:"log"`
  115. }
  116. // Log from dialing peers
  117. type ResultDialPeers struct {
  118. Log string `json:"log"`
  119. }
  120. // A peer
  121. type Peer struct {
  122. NodeInfo types.NodeInfo `json:"node_info"`
  123. IsOutbound bool `json:"is_outbound"`
  124. ConnectionStatus p2p.ConnectionStatus `json:"connection_status"`
  125. RemoteIP string `json:"remote_ip"`
  126. }
  127. // Validators for a height.
  128. type ResultValidators struct {
  129. BlockHeight int64 `json:"block_height"`
  130. Validators []*types.Validator `json:"validators"`
  131. // Count of actual validators in this result
  132. Count int `json:"count"`
  133. // Total number of validators
  134. Total int `json:"total"`
  135. }
  136. // ConsensusParams for given height
  137. type ResultConsensusParams struct {
  138. BlockHeight int64 `json:"block_height"`
  139. ConsensusParams types.ConsensusParams `json:"consensus_params"`
  140. }
  141. // Info about the consensus state.
  142. // UNSTABLE
  143. type ResultDumpConsensusState struct {
  144. RoundState json.RawMessage `json:"round_state"`
  145. Peers []PeerStateInfo `json:"peers"`
  146. }
  147. // UNSTABLE
  148. type PeerStateInfo struct {
  149. NodeAddress string `json:"node_address"`
  150. PeerState json.RawMessage `json:"peer_state"`
  151. }
  152. // UNSTABLE
  153. type ResultConsensusState struct {
  154. RoundState json.RawMessage `json:"round_state"`
  155. }
  156. // CheckTx result
  157. type ResultBroadcastTx struct {
  158. Code uint32 `json:"code"`
  159. Data bytes.HexBytes `json:"data"`
  160. Log string `json:"log"`
  161. Codespace string `json:"codespace"`
  162. Hash bytes.HexBytes `json:"hash"`
  163. }
  164. // CheckTx and DeliverTx results
  165. type ResultBroadcastTxCommit struct {
  166. CheckTx abci.ResponseCheckTx `json:"check_tx"`
  167. DeliverTx abci.ResponseDeliverTx `json:"deliver_tx"`
  168. Hash bytes.HexBytes `json:"hash"`
  169. Height int64 `json:"height"`
  170. }
  171. // ResultCheckTx wraps abci.ResponseCheckTx.
  172. type ResultCheckTx struct {
  173. abci.ResponseCheckTx
  174. }
  175. // Result of querying for a tx
  176. type ResultTx struct {
  177. Hash bytes.HexBytes `json:"hash"`
  178. Height int64 `json:"height"`
  179. Index uint32 `json:"index"`
  180. TxResult abci.ResponseDeliverTx `json:"tx_result"`
  181. Tx types.Tx `json:"tx"`
  182. Proof types.TxProof `json:"proof,omitempty"`
  183. }
  184. // Result of searching for txs
  185. type ResultTxSearch struct {
  186. Txs []*ResultTx `json:"txs"`
  187. TotalCount int `json:"total_count"`
  188. }
  189. // ResultBlockSearch defines the RPC response type for a block search by events.
  190. type ResultBlockSearch struct {
  191. Blocks []*ResultBlock `json:"blocks"`
  192. TotalCount int `json:"total_count"`
  193. }
  194. // List of mempool txs
  195. type ResultUnconfirmedTxs struct {
  196. Count int `json:"n_txs"`
  197. Total int `json:"total"`
  198. TotalBytes int64 `json:"total_bytes"`
  199. Txs []types.Tx `json:"txs"`
  200. }
  201. // Info abci msg
  202. type ResultABCIInfo struct {
  203. Response abci.ResponseInfo `json:"response"`
  204. }
  205. // Query abci msg
  206. type ResultABCIQuery struct {
  207. Response abci.ResponseQuery `json:"response"`
  208. }
  209. // Result of broadcasting evidence
  210. type ResultBroadcastEvidence struct {
  211. Hash []byte `json:"hash"`
  212. }
  213. // empty results
  214. type (
  215. ResultUnsafeFlushMempool struct{}
  216. ResultUnsafeProfile struct{}
  217. ResultSubscribe struct{}
  218. ResultUnsubscribe struct{}
  219. ResultHealth struct{}
  220. )
  221. // Event data from a subscription
  222. type ResultEvent struct {
  223. SubscriptionID string `json:"subscription_id"`
  224. Query string `json:"query"`
  225. Data types.TMEventData `json:"data"`
  226. Events map[string][]string `json:"events"`
  227. }