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.

366 lines
12 KiB

8 years ago
7 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
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
5 years ago
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
5 years ago
8 years ago
  1. syntax = "proto3";
  2. package tendermint.abci;
  3. option go_package = "github.com/tendermint/tendermint/abci/types";
  4. // For more information on gogo.proto, see:
  5. // https://github.com/gogo/protobuf/blob/master/extensions.md
  6. import "tendermint/crypto/proof.proto";
  7. import "tendermint/types/types.proto";
  8. import "tendermint/crypto/keys.proto";
  9. import "tendermint/types/params.proto";
  10. import "google/protobuf/timestamp.proto";
  11. import "gogoproto/gogo.proto";
  12. // This file is copied from http://github.com/tendermint/abci
  13. // NOTE: When using custom types, mind the warnings.
  14. // https://github.com/gogo/protobuf/blob/master/custom_types.md#warnings-and-issues
  15. //----------------------------------------
  16. // Request types
  17. message Request {
  18. oneof value {
  19. RequestEcho echo = 1;
  20. RequestFlush flush = 2;
  21. RequestInfo info = 3;
  22. RequestInitChain init_chain = 4;
  23. RequestQuery query = 5;
  24. RequestBeginBlock begin_block = 6;
  25. RequestCheckTx check_tx = 7;
  26. RequestDeliverTx deliver_tx = 8;
  27. RequestEndBlock end_block = 9;
  28. RequestCommit commit = 10;
  29. RequestListSnapshots list_snapshots = 11;
  30. RequestOfferSnapshot offer_snapshot = 12;
  31. RequestLoadSnapshotChunk load_snapshot_chunk = 13;
  32. RequestApplySnapshotChunk apply_snapshot_chunk = 14;
  33. }
  34. }
  35. message RequestEcho {
  36. string message = 1;
  37. }
  38. message RequestFlush {}
  39. message RequestInfo {
  40. string version = 1;
  41. uint64 block_version = 2;
  42. uint64 p2p_version = 3;
  43. string abci_version = 4;
  44. }
  45. message RequestInitChain {
  46. google.protobuf.Timestamp time = 1 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
  47. string chain_id = 2;
  48. tendermint.types.ConsensusParams consensus_params = 3;
  49. repeated ValidatorUpdate validators = 4 [(gogoproto.nullable) = false];
  50. bytes app_state_bytes = 5;
  51. int64 initial_height = 6;
  52. }
  53. message RequestQuery {
  54. bytes data = 1;
  55. string path = 2;
  56. int64 height = 3;
  57. bool prove = 4;
  58. }
  59. message RequestBeginBlock {
  60. bytes hash = 1;
  61. tendermint.types.Header header = 2 [(gogoproto.nullable) = false];
  62. LastCommitInfo last_commit_info = 3 [(gogoproto.nullable) = false];
  63. repeated Evidence byzantine_validators = 4 [(gogoproto.nullable) = false];
  64. }
  65. enum CheckTxType {
  66. NEW = 0 [(gogoproto.enumvalue_customname) = "New"];
  67. RECHECK = 1 [(gogoproto.enumvalue_customname) = "Recheck"];
  68. }
  69. message RequestCheckTx {
  70. bytes tx = 1;
  71. CheckTxType type = 2;
  72. }
  73. message RequestDeliverTx {
  74. bytes tx = 1;
  75. }
  76. message RequestEndBlock {
  77. int64 height = 1;
  78. }
  79. message RequestCommit {}
  80. // lists available snapshots
  81. message RequestListSnapshots {}
  82. // offers a snapshot to the application
  83. message RequestOfferSnapshot {
  84. Snapshot snapshot = 1; // snapshot offered by peers
  85. bytes app_hash = 2; // light client-verified app hash for snapshot height
  86. }
  87. // loads a snapshot chunk
  88. message RequestLoadSnapshotChunk {
  89. uint64 height = 1;
  90. uint32 format = 2;
  91. uint32 chunk = 3;
  92. }
  93. // Applies a snapshot chunk
  94. message RequestApplySnapshotChunk {
  95. uint32 index = 1;
  96. bytes chunk = 2;
  97. string sender = 3;
  98. }
  99. //----------------------------------------
  100. // Response types
  101. message Response {
  102. oneof value {
  103. ResponseException exception = 1;
  104. ResponseEcho echo = 2;
  105. ResponseFlush flush = 3;
  106. ResponseInfo info = 4;
  107. ResponseInitChain init_chain = 5;
  108. ResponseQuery query = 6;
  109. ResponseBeginBlock begin_block = 7;
  110. ResponseCheckTx check_tx = 8;
  111. ResponseDeliverTx deliver_tx = 9;
  112. ResponseEndBlock end_block = 10;
  113. ResponseCommit commit = 11;
  114. ResponseListSnapshots list_snapshots = 12;
  115. ResponseOfferSnapshot offer_snapshot = 13;
  116. ResponseLoadSnapshotChunk load_snapshot_chunk = 14;
  117. ResponseApplySnapshotChunk apply_snapshot_chunk = 15;
  118. }
  119. }
  120. // nondeterministic
  121. message ResponseException {
  122. string error = 1;
  123. }
  124. message ResponseEcho {
  125. string message = 1;
  126. }
  127. message ResponseFlush {}
  128. message ResponseInfo {
  129. string data = 1;
  130. // this is the software version of the application. TODO: remove?
  131. string version = 2;
  132. uint64 app_version = 3;
  133. int64 last_block_height = 4;
  134. bytes last_block_app_hash = 5;
  135. }
  136. message ResponseInitChain {
  137. tendermint.types.ConsensusParams consensus_params = 1;
  138. repeated ValidatorUpdate validators = 2 [(gogoproto.nullable) = false];
  139. bytes app_hash = 3;
  140. }
  141. message ResponseQuery {
  142. uint32 code = 1;
  143. // bytes data = 2; // use "value" instead.
  144. string log = 3; // nondeterministic
  145. string info = 4; // nondeterministic
  146. int64 index = 5;
  147. bytes key = 6;
  148. bytes value = 7;
  149. tendermint.crypto.ProofOps proof_ops = 8;
  150. int64 height = 9;
  151. string codespace = 10;
  152. }
  153. message ResponseBeginBlock {
  154. repeated Event events = 1 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"];
  155. }
  156. message ResponseCheckTx {
  157. uint32 code = 1;
  158. bytes data = 2;
  159. string log = 3; // nondeterministic
  160. string info = 4; // nondeterministic
  161. int64 gas_wanted = 5 [json_name = "gas_wanted"];
  162. int64 gas_used = 6 [json_name = "gas_used"];
  163. repeated Event events = 7 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"];
  164. string codespace = 8;
  165. string sender = 9;
  166. int64 priority = 10;
  167. string mempool_error = 11;
  168. }
  169. message ResponseDeliverTx {
  170. uint32 code = 1;
  171. bytes data = 2;
  172. string log = 3; // nondeterministic
  173. string info = 4; // nondeterministic
  174. int64 gas_wanted = 5 [json_name = "gas_wanted"];
  175. int64 gas_used = 6 [json_name = "gas_used"];
  176. repeated Event events = 7
  177. [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; // nondeterministic
  178. string codespace = 8;
  179. }
  180. message ResponseEndBlock {
  181. repeated ValidatorUpdate validator_updates = 1 [(gogoproto.nullable) = false];
  182. tendermint.types.ConsensusParams consensus_param_updates = 2;
  183. repeated Event events = 3 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"];
  184. }
  185. message ResponseCommit {
  186. // reserve 1
  187. bytes data = 2;
  188. int64 retain_height = 3;
  189. }
  190. message ResponseListSnapshots {
  191. repeated Snapshot snapshots = 1;
  192. }
  193. message ResponseOfferSnapshot {
  194. Result result = 1;
  195. enum Result {
  196. UNKNOWN = 0; // Unknown result, abort all snapshot restoration
  197. ACCEPT = 1; // Snapshot accepted, apply chunks
  198. ABORT = 2; // Abort all snapshot restoration
  199. REJECT = 3; // Reject this specific snapshot, try others
  200. REJECT_FORMAT = 4; // Reject all snapshots of this format, try others
  201. REJECT_SENDER = 5; // Reject all snapshots from the sender(s), try others
  202. }
  203. }
  204. message ResponseLoadSnapshotChunk {
  205. bytes chunk = 1;
  206. }
  207. message ResponseApplySnapshotChunk {
  208. Result result = 1;
  209. repeated uint32 refetch_chunks = 2; // Chunks to refetch and reapply
  210. repeated string reject_senders = 3; // Chunk senders to reject and ban
  211. enum Result {
  212. UNKNOWN = 0; // Unknown result, abort all snapshot restoration
  213. ACCEPT = 1; // Chunk successfully accepted
  214. ABORT = 2; // Abort all snapshot restoration
  215. RETRY = 3; // Retry chunk (combine with refetch and reject)
  216. RETRY_SNAPSHOT = 4; // Retry snapshot (combine with refetch and reject)
  217. REJECT_SNAPSHOT = 5; // Reject this snapshot, try others
  218. }
  219. }
  220. //----------------------------------------
  221. // Misc.
  222. message LastCommitInfo {
  223. int32 round = 1;
  224. repeated VoteInfo votes = 2 [(gogoproto.nullable) = false];
  225. }
  226. // Event allows application developers to attach additional information to
  227. // ResponseBeginBlock, ResponseEndBlock, ResponseCheckTx and ResponseDeliverTx.
  228. // Later, transactions may be queried using these events.
  229. message Event {
  230. string type = 1;
  231. repeated EventAttribute attributes = 2 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "attributes,omitempty"];
  232. }
  233. // EventAttribute is a single key-value pair, associated with an event.
  234. message EventAttribute {
  235. string key = 1;
  236. string value = 2;
  237. bool index = 3; // nondeterministic
  238. }
  239. // TxResult contains results of executing the transaction.
  240. //
  241. // One usage is indexing transaction results.
  242. message TxResult {
  243. int64 height = 1;
  244. uint32 index = 2;
  245. bytes tx = 3;
  246. ResponseDeliverTx result = 4 [(gogoproto.nullable) = false];
  247. }
  248. //----------------------------------------
  249. // Blockchain Types
  250. // Validator
  251. message Validator {
  252. bytes address = 1; // The first 20 bytes of SHA256(public key)
  253. // PubKey pub_key = 2 [(gogoproto.nullable)=false];
  254. int64 power = 3; // The voting power
  255. }
  256. // ValidatorUpdate
  257. message ValidatorUpdate {
  258. tendermint.crypto.PublicKey pub_key = 1 [(gogoproto.nullable) = false];
  259. int64 power = 2;
  260. }
  261. // VoteInfo
  262. message VoteInfo {
  263. Validator validator = 1 [(gogoproto.nullable) = false];
  264. bool signed_last_block = 2;
  265. }
  266. enum EvidenceType {
  267. UNKNOWN = 0;
  268. DUPLICATE_VOTE = 1;
  269. LIGHT_CLIENT_ATTACK = 2;
  270. }
  271. message Evidence {
  272. EvidenceType type = 1;
  273. // The offending validator
  274. Validator validator = 2 [(gogoproto.nullable) = false];
  275. // The height when the offense occurred
  276. int64 height = 3;
  277. // The corresponding time where the offense occurred
  278. google.protobuf.Timestamp time = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
  279. // Total voting power of the validator set in case the ABCI application does
  280. // not store historical validators.
  281. // https://github.com/tendermint/tendermint/issues/4581
  282. int64 total_voting_power = 5;
  283. }
  284. //----------------------------------------
  285. // State Sync Types
  286. message Snapshot {
  287. uint64 height = 1; // The height at which the snapshot was taken
  288. uint32 format = 2; // The application-specific snapshot format
  289. uint32 chunks = 3; // Number of chunks in the snapshot
  290. bytes hash = 4; // Arbitrary snapshot hash, equal only if identical
  291. bytes metadata = 5; // Arbitrary application metadata
  292. }
  293. //----------------------------------------
  294. // Service Definition
  295. service ABCIApplication {
  296. rpc Echo(RequestEcho) returns (ResponseEcho);
  297. rpc Flush(RequestFlush) returns (ResponseFlush);
  298. rpc Info(RequestInfo) returns (ResponseInfo);
  299. rpc DeliverTx(RequestDeliverTx) returns (ResponseDeliverTx);
  300. rpc CheckTx(RequestCheckTx) returns (ResponseCheckTx);
  301. rpc Query(RequestQuery) returns (ResponseQuery);
  302. rpc Commit(RequestCommit) returns (ResponseCommit);
  303. rpc InitChain(RequestInitChain) returns (ResponseInitChain);
  304. rpc BeginBlock(RequestBeginBlock) returns (ResponseBeginBlock);
  305. rpc EndBlock(RequestEndBlock) returns (ResponseEndBlock);
  306. rpc ListSnapshots(RequestListSnapshots) returns (ResponseListSnapshots);
  307. rpc OfferSnapshot(RequestOfferSnapshot) returns (ResponseOfferSnapshot);
  308. rpc LoadSnapshotChunk(RequestLoadSnapshotChunk) returns (ResponseLoadSnapshotChunk);
  309. rpc ApplySnapshotChunk(RequestApplySnapshotChunk) returns (ResponseApplySnapshotChunk);
  310. }