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.

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