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.

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