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.

396 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>
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
6 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
6 years ago
8 years ago
  1. syntax = "proto3";
  2. package tendermint.abci.types;
  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 "proto/crypto/merkle/types.proto";
  7. import "proto/types/types.proto";
  8. import "proto/crypto/keys/types.proto";
  9. import "proto/types/params.proto";
  10. import "google/protobuf/timestamp.proto";
  11. import "third_party/proto/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 = 2;
  20. RequestFlush flush = 3;
  21. RequestInfo info = 4;
  22. RequestSetOption set_option = 5;
  23. RequestInitChain init_chain = 6;
  24. RequestQuery query = 7;
  25. RequestBeginBlock begin_block = 8;
  26. RequestCheckTx check_tx = 9;
  27. RequestDeliverTx deliver_tx = 19;
  28. RequestEndBlock end_block = 11;
  29. RequestCommit commit = 12;
  30. RequestListSnapshots list_snapshots = 13;
  31. RequestOfferSnapshot offer_snapshot = 14;
  32. RequestLoadSnapshotChunk load_snapshot_chunk = 15;
  33. RequestApplySnapshotChunk apply_snapshot_chunk = 16;
  34. }
  35. }
  36. message RequestEcho {
  37. string message = 1;
  38. }
  39. message RequestFlush {}
  40. message RequestInfo {
  41. string version = 1;
  42. uint64 block_version = 2;
  43. uint64 p2p_version = 3;
  44. }
  45. // nondeterministic
  46. message RequestSetOption {
  47. string key = 1;
  48. string value = 2;
  49. }
  50. message RequestInitChain {
  51. google.protobuf.Timestamp time = 1
  52. [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
  53. string chain_id = 2;
  54. ConsensusParams consensus_params = 3;
  55. repeated ValidatorUpdate validators = 4 [(gogoproto.nullable) = false];
  56. bytes app_state_bytes = 5;
  57. }
  58. message RequestQuery {
  59. bytes data = 1;
  60. string path = 2;
  61. int64 height = 3;
  62. bool prove = 4;
  63. }
  64. message RequestBeginBlock {
  65. bytes hash = 1;
  66. tendermint.proto.types.Header header = 2 [(gogoproto.nullable) = false];
  67. LastCommitInfo last_commit_info = 3 [(gogoproto.nullable) = false];
  68. repeated Evidence byzantine_validators = 4 [(gogoproto.nullable) = false];
  69. }
  70. enum CheckTxType {
  71. New = 0;
  72. Recheck = 1;
  73. }
  74. message RequestCheckTx {
  75. bytes tx = 1;
  76. CheckTxType type = 2;
  77. }
  78. message RequestDeliverTx {
  79. bytes tx = 1;
  80. }
  81. message RequestEndBlock {
  82. int64 height = 1;
  83. }
  84. message RequestCommit {}
  85. // lists available snapshots
  86. message RequestListSnapshots {
  87. }
  88. // offers a snapshot to the application
  89. message RequestOfferSnapshot {
  90. Snapshot snapshot = 1; // snapshot offered by peers
  91. bytes app_hash = 2; // light client-verified app hash for snapshot height
  92. }
  93. // loads a snapshot chunk
  94. message RequestLoadSnapshotChunk {
  95. uint64 height = 1;
  96. uint32 format = 2;
  97. uint32 chunk = 3;
  98. }
  99. // Applies a snapshot chunk
  100. message RequestApplySnapshotChunk {
  101. uint32 index = 1;
  102. bytes chunk = 2;
  103. string sender = 3;
  104. }
  105. //----------------------------------------
  106. // Response types
  107. message Response {
  108. oneof value {
  109. ResponseException exception = 1;
  110. ResponseEcho echo = 2;
  111. ResponseFlush flush = 3;
  112. ResponseInfo info = 4;
  113. ResponseSetOption set_option = 5;
  114. ResponseInitChain init_chain = 6;
  115. ResponseQuery query = 7;
  116. ResponseBeginBlock begin_block = 8;
  117. ResponseCheckTx check_tx = 9;
  118. ResponseDeliverTx deliver_tx = 10;
  119. ResponseEndBlock end_block = 11;
  120. ResponseCommit commit = 12;
  121. ResponseListSnapshots list_snapshots = 13;
  122. ResponseOfferSnapshot offer_snapshot = 14;
  123. ResponseLoadSnapshotChunk load_snapshot_chunk = 15;
  124. ResponseApplySnapshotChunk apply_snapshot_chunk = 16;
  125. }
  126. }
  127. // nondeterministic
  128. message ResponseException {
  129. string error = 1;
  130. }
  131. message ResponseEcho {
  132. string message = 1;
  133. }
  134. message ResponseFlush {}
  135. message ResponseInfo {
  136. string data = 1;
  137. string version = 2;
  138. uint64 app_version = 3;
  139. int64 last_block_height = 4;
  140. bytes last_block_app_hash = 5;
  141. }
  142. // nondeterministic
  143. message ResponseSetOption {
  144. uint32 code = 1;
  145. // bytes data = 2;
  146. string log = 3;
  147. string info = 4;
  148. }
  149. message ResponseInitChain {
  150. ConsensusParams consensus_params = 1;
  151. repeated ValidatorUpdate validators = 2 [(gogoproto.nullable) = false];
  152. }
  153. message ResponseQuery {
  154. uint32 code = 1;
  155. // bytes data = 2; // use "value" instead.
  156. string log = 3; // nondeterministic
  157. string info = 4; // nondeterministic
  158. int64 index = 5;
  159. bytes key = 6;
  160. bytes value = 7;
  161. tendermint.proto.crypto.merkle.ProofOps proof_ops = 8;
  162. int64 height = 9;
  163. string codespace = 10;
  164. }
  165. message ResponseBeginBlock {
  166. repeated Event events = 1
  167. [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"];
  168. }
  169. message ResponseCheckTx {
  170. uint32 code = 1;
  171. bytes data = 2;
  172. string log = 3; // nondeterministic
  173. string info = 4; // nondeterministic
  174. int64 gas_wanted = 5;
  175. int64 gas_used = 6;
  176. repeated Event events = 7
  177. [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"];
  178. string codespace = 8;
  179. }
  180. message ResponseDeliverTx {
  181. uint32 code = 1;
  182. bytes data = 2;
  183. string log = 3; // nondeterministic
  184. string info = 4; // nondeterministic
  185. int64 gas_wanted = 5;
  186. int64 gas_used = 6;
  187. repeated Event events = 7
  188. [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"];
  189. string codespace = 8;
  190. }
  191. message ResponseEndBlock {
  192. repeated ValidatorUpdate validator_updates = 1
  193. [(gogoproto.nullable) = false];
  194. ConsensusParams consensus_param_updates = 2;
  195. repeated Event events = 3
  196. [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"];
  197. }
  198. message ResponseCommit {
  199. // reserve 1
  200. bytes data = 2;
  201. int64 retain_height = 3;
  202. }
  203. message ResponseListSnapshots {
  204. repeated Snapshot snapshots = 1;
  205. }
  206. message ResponseOfferSnapshot {
  207. Result result = 1;
  208. enum Result {
  209. ACCEPT = 0; // Snapshot accepted, apply chunks
  210. ABORT = 1; // Abort all snapshot restoration
  211. REJECT = 2; // Reject this specific snapshot, try others
  212. REJECT_FORMAT = 3; // Reject all snapshots of this format, try others
  213. REJECT_SENDER = 4; // Reject all snapshots from the sender(s), try others
  214. }
  215. }
  216. message ResponseLoadSnapshotChunk {
  217. bytes chunk = 1;
  218. }
  219. message ResponseApplySnapshotChunk {
  220. Result result = 1;
  221. repeated uint32 refetch_chunks = 2; // Chunks to refetch and reapply
  222. repeated string reject_senders = 3; // Chunk senders to reject and ban
  223. enum Result {
  224. ACCEPT = 0; // Chunk successfully accepted
  225. ABORT = 1; // Abort all snapshot restoration
  226. RETRY = 2; // Retry chunk (combine with refetch and reject)
  227. RETRY_SNAPSHOT = 3; // Retry snapshot (combine with refetch and reject)
  228. REJECT_SNAPSHOT = 4; // Reject this snapshot, try others
  229. }
  230. }
  231. //----------------------------------------
  232. // Misc.
  233. // ConsensusParams contains all consensus-relevant parameters
  234. // that can be adjusted by the abci app
  235. message ConsensusParams {
  236. BlockParams block = 1;
  237. tendermint.proto.types.EvidenceParams evidence = 2;
  238. tendermint.proto.types.ValidatorParams validator = 3;
  239. }
  240. // BlockParams contains limits on the block size.
  241. message BlockParams {
  242. // Note: must be greater than 0
  243. int64 max_bytes = 1;
  244. // Note: must be greater or equal to -1
  245. int64 max_gas = 2;
  246. }
  247. message LastCommitInfo {
  248. int32 round = 1;
  249. repeated VoteInfo votes = 2 [(gogoproto.nullable) = false];
  250. }
  251. // EventAttribute represents an event to the indexing service.
  252. message EventAttribute {
  253. bytes key = 1;
  254. bytes value = 2;
  255. bool index = 3;
  256. }
  257. message Event {
  258. string type = 1;
  259. repeated EventAttribute attributes = 2 [
  260. (gogoproto.nullable) = false,
  261. (gogoproto.jsontag) = "attributes,omitempty"
  262. ];
  263. }
  264. // TxResult contains results of executing the transaction.
  265. //
  266. // One usage is indexing transaction results.
  267. message TxResult {
  268. int64 height = 1;
  269. uint32 Index = 2;
  270. bytes tx = 3;
  271. ResponseDeliverTx result = 4 [(gogoproto.nullable) = false];
  272. }
  273. //----------------------------------------
  274. // Blockchain Types
  275. message BlockID {
  276. bytes hash = 1;
  277. PartSetHeader parts_header = 2 [(gogoproto.nullable) = false];
  278. }
  279. message PartSetHeader {
  280. int32 total = 1;
  281. bytes hash = 2;
  282. }
  283. // Validator
  284. message Validator {
  285. bytes address = 1;
  286. // PubKey pub_key = 2 [(gogoproto.nullable)=false];
  287. int64 power = 3;
  288. }
  289. // ValidatorUpdate
  290. message ValidatorUpdate {
  291. tendermint.proto.crypto.keys.PublicKey pub_key = 1 [(gogoproto.nullable) = false];
  292. int64 power = 2;
  293. }
  294. // VoteInfo
  295. message VoteInfo {
  296. Validator validator = 1 [(gogoproto.nullable) = false];
  297. bool signed_last_block = 2;
  298. }
  299. message Evidence {
  300. string type = 1;
  301. Validator validator = 2 [(gogoproto.nullable) = false];
  302. int64 height = 3;
  303. google.protobuf.Timestamp time = 4 [
  304. (gogoproto.nullable) = false,
  305. (gogoproto.stdtime) = true
  306. ];
  307. int64 total_voting_power = 5;
  308. }
  309. //----------------------------------------
  310. // State Sync Types
  311. message Snapshot {
  312. uint64 height = 1; // The height at which the snapshot was taken
  313. uint32 format = 2; // The application-specific snapshot format
  314. uint32 chunks = 3; // Number of chunks in the snapshot
  315. bytes hash = 4; // Arbitrary snapshot hash, equal only if identical
  316. bytes metadata = 5; // Arbitrary application metadata
  317. }
  318. //----------------------------------------
  319. // Service Definition
  320. service ABCIApplication {
  321. rpc Echo(RequestEcho) returns (ResponseEcho);
  322. rpc Flush(RequestFlush) returns (ResponseFlush);
  323. rpc Info(RequestInfo) returns (ResponseInfo);
  324. rpc SetOption(RequestSetOption) returns (ResponseSetOption);
  325. rpc DeliverTx(RequestDeliverTx) returns (ResponseDeliverTx);
  326. rpc CheckTx(RequestCheckTx) returns (ResponseCheckTx);
  327. rpc Query(RequestQuery) returns (ResponseQuery);
  328. rpc Commit(RequestCommit) returns (ResponseCommit);
  329. rpc InitChain(RequestInitChain) returns (ResponseInitChain);
  330. rpc BeginBlock(RequestBeginBlock) returns (ResponseBeginBlock);
  331. rpc EndBlock(RequestEndBlock) returns (ResponseEndBlock);
  332. rpc ListSnapshots(RequestListSnapshots) returns (ResponseListSnapshots);
  333. rpc OfferSnapshot(RequestOfferSnapshot) returns (ResponseOfferSnapshot);
  334. rpc LoadSnapshotChunk(RequestLoadSnapshotChunk) returns (ResponseLoadSnapshotChunk);
  335. rpc ApplySnapshotChunk(RequestApplySnapshotChunk) returns (ResponseApplySnapshotChunk);
  336. }