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.

171 lines
7.0 KiB

8 years ago
9 years ago
8 years ago
8 years ago
9 years ago
8 years ago
8 years ago
8 years ago
9 years ago
8 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
  1. # Tendermint Socket Protocol (ABCI)
  2. [![CircleCI](https://circleci.com/gh/tendermint/abci.svg?style=svg)](https://circleci.com/gh/tendermint/abci)
  3. Blockchains are a system for creating shared multi-master application state.
  4. **ABCI** is a socket protocol enabling a blockchain consensus engine, running in one process,
  5. For more information on ABCI, motivations, and tutorials, please visit [our blog post](https://tendermint.com/blog/abci-the-tendermint-socket-protocol).
  6. Other implementations:
  7. * [cpp-abci](https://github.com/mdyring/cpp-abci) by Martin Dyring-Andersen
  8. * [js-abci](https://github.com/tendermint/js-abci)
  9. * [jABCI](https://github.com/jABCI/) for Java
  10. ## Contents
  11. This repository holds a number of important pieces:
  12. - `types/types.proto`
  13. - the protobuf file defining ABCI message types, and the optional grpc interface.
  14. - to build, run `make protoc`
  15. - see `protoc --help` and [the grpc docs](https://www.grpc.io/docs) for examples and details of other languages
  16. - golang implementation of ABCI client and server
  17. - two implementations:
  18. - asynchronous, ordered message passing over unix or tcp;
  19. - messages are serialized using protobuf and length prefixed
  20. - grpc
  21. - TendermintCore runs a client, and the application runs a server
  22. - `cmd/abci-cli`
  23. - command line tool wrapping the client for probing/testing a ABCI application
  24. - use `abci-cli --version` to get the ABCI version
  25. - examples:
  26. - the `cmd/counter` application, which illustrates nonce checking in txs
  27. - the `cmd/dummy` application, which illustrates a simple key-value merkle tree
  28. ## Message format
  29. Since this is a streaming protocol, all messages are encoded with a length-prefix followed by the message encoded in Protobuf3. Protobuf3 doesn't have an official length-prefix standard, so we use our own. The first byte represents the length of the big-endian encoded length.
  30. For example, if the Protobuf3 encoded ABCI message is `0xDEADBEEF` (4 bytes), the length-prefixed message is `0x0104DEADBEEF`. If the Protobuf3 encoded ABCI message is 65535 bytes long, the length-prefixed message would be like `0x02FFFF...`.
  31. Note this prefixing does not apply for grpc.
  32. ## Message types
  33. ABCI requests/responses are simple Protobuf messages. Check out the [schema file](https://github.com/tendermint/abci/blob/master/types/types.proto).
  34. #### DeliverTx
  35. * __Arguments__:
  36. * `Data ([]byte)`: The request transaction bytes
  37. * __Returns__:
  38. * `Code (uint32)`: Response code
  39. * `Data ([]byte)`: Result bytes, if any
  40. * `Log (string)`: Debug or error message
  41. * __Usage__:<br/>
  42. Append and run a transaction. If the transaction is valid, returns CodeType.OK
  43. #### CheckTx
  44. * __Arguments__:
  45. * `Data ([]byte)`: The request transaction bytes
  46. * __Returns__:
  47. * `Code (uint32)`: Response code
  48. * `Data ([]byte)`: Result bytes, if any
  49. * `Log (string)`: Debug or error message
  50. * __Usage__:<br/>
  51. Validate a mempool transaction, prior to broadcasting or proposing. This message should not mutate the main state, but application
  52. developers may want to keep a separate CheckTx state that gets reset upon Commit.
  53. CheckTx can happen interspersed with DeliverTx, but they happen on different connections - CheckTx from the mempool connection, and DeliverTx from the consensus connection. During Commit, the mempool is locked, so you can reset the mempool state to the latest state after running all those delivertxs, and then the mempool will re run whatever txs it has against that latest mempool stte
  54. Transactions are first run through CheckTx before broadcast to peers in the mempool layer.
  55. You can make CheckTx semi-stateful and clear the state upon `Commit` or `BeginBlock`,
  56. to allow for dependent sequences of transactions in the same block.
  57. #### Commit
  58. * __Returns__:
  59. * `Data ([]byte)`: The Merkle root hash
  60. * `Log (string)`: Debug or error message
  61. * __Usage__:<br/>
  62. Return a Merkle root hash of the application state.
  63. #### Query
  64. * __Arguments__:
  65. * `Data ([]byte)`: Raw query bytes. Can be used with or in lieu of Path.
  66. * `Path (string)`: Path of request, like an HTTP GET path. Can be used with or in liue of Data.
  67. * Apps MUST interpret '/store' as a query by key on the underlying store. The key SHOULD be specified in the Data field.
  68. * Apps SHOULD allow queries over specific types like '/accounts/...' or '/votes/...'
  69. * `Height (uint64)`: The block height for which you want the query (default=0 returns data for the latest committed block)
  70. * `Prove (bool)`: Return Merkle proof with response if possible
  71. * __Returns__:
  72. * `Code (uint32)`: Response code
  73. * `Key ([]byte)`: The key of the matching data
  74. * `Value ([]byte)`: The value of the matching data
  75. * `Proof ([]byte)`: Proof for the data, if requested
  76. * `Height (uint64)`: The block height from which data was derived
  77. * `Log (string)`: Debug or error message
  78. *Please note* The current implementation of go-merkle doesn't support querying proofs from past blocks, so for the present moment, any height other than 0 will return an error. Hopefully this will be improved soon(ish)
  79. #### Flush
  80. * __Usage__:<br/>
  81. Flush the response queue. Applications that implement `types.Application` need not implement this message -- it's handled by the project.
  82. #### Info
  83. * __Returns__:
  84. * `Data ([]byte)`: The info bytes
  85. * __Usage__:<br/>
  86. Return information about the application state. Application specific.
  87. #### SetOption
  88. * __Arguments__:
  89. * `Key (string)`: Key to set
  90. * `Value (string)`: Value to set for key
  91. * __Returns__:
  92. * `Log (string)`: Debug or error message
  93. * __Usage__:<br/>
  94. Set application options. E.g. Key="mode", Value="mempool" for a mempool connection, or Key="mode", Value="consensus" for a consensus connection.
  95. Other options are application specific.
  96. #### InitChain
  97. * __Arguments__:
  98. * `Validators ([]Validator)`: Initial genesis validators
  99. * __Usage__:<br/>
  100. Called once upon genesis
  101. #### BeginBlock
  102. * __Arguments__:
  103. * `Height (uint64)`: The block height that is starting
  104. * __Usage__:<br/>
  105. Signals the beginning of a new block. Called prior to any DeliverTxs.
  106. #### EndBlock
  107. * __Arguments__:
  108. * `Height (uint64)`: The block height that ended
  109. * __Returns__:
  110. * `Validators ([]Validator)`: Changed validators with new voting powers (0 to remove)
  111. * __Usage__:<br/>
  112. Signals the end of a block. Called prior to each Commit after all transactions
  113. ## Changelog
  114. ##### Mar 26h, 2016
  115. * Introduce BeginBlock
  116. ##### Mar 6th, 2016
  117. * Added InitChain, EndBlock
  118. ##### Feb 14th, 2016
  119. * s/GetHash/Commit/g
  120. * Document Protobuf request/response fields
  121. ##### Jan 23th, 2016
  122. * Added CheckTx/Query ABCI message types
  123. * Added Result/Log fields to DeliverTx/CheckTx/SetOption
  124. * Removed Listener messages
  125. * Removed Code from ResponseSetOption and ResponseGetHash
  126. * Made examples BigEndian
  127. ##### Jan 12th, 2016
  128. * Added "RetCodeBadNonce = 0x06" return code
  129. ##### Jan 8th, 2016
  130. * Tendermint/ABCI now comes to consensus on the order first before DeliverTx.