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.

177 lines
8.4 KiB

8 years ago
9 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 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
8 years ago
8 years ago
9 years ago
9 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 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
8 years ago
8 years ago
8 years ago
  1. # Application BlockChain Interface (ABCI)
  2. [![CircleCI](https://circleci.com/gh/tendermint/abci.svg?style=svg)](https://circleci.com/gh/tendermint/abci)
  3. Blockchains are a system for multi-master state machine replication.
  4. **ABCI** is an interface that defines the boundary between the replication engine (the blockchain),
  5. and the state machine (the application).
  6. By using a socket protocol, we enable a consensus engine running in one process
  7. to manage an application state running in another.
  8. For more information on ABCI, motivations, and tutorials, please visit [our blog post](https://tendermint.com/blog/tmsp-the-tendermint-socket-protocol).
  9. Previously, the ABCI was just referred to as TMSP.
  10. Other implementations:
  11. * [cpp-tmsp](https://github.com/mdyring/cpp-tmsp) by Martin Dyring-Andersen
  12. * [js-tmsp](https://github.com/tendermint/js-tmsp)
  13. * [jTMSP](https://github.com/jTMSP/) for Java
  14. # Specification
  15. The [primary specification](https://github.com/tendermint/abci/blob/master/types/types.proto) is made using Protocol Buffers.
  16. - The Protobuf file defining ABCI message types, and the optional GRPC interface. To build, run `make protoc`
  17. - See `protoc --help` and [the GRPC docs](https://www.grpc.io/docs) for examples and details of other languages.
  18. TendermintCore runs a client, and the ABCI application runs a server. There are three Golang implementation of ABCI client and server.
  19. 1. ABCI-socket: Asynchronous, ordered message passing over Unix or TCP sockets. Messages are serialized using Protobuf and length prefixed.
  20. 2. GRPC: Synchronous (slow) implementation using GRPC.
  21. 3. Golang in-process: If the ABCI appliation is written in Golang, it is possible to compile both TendermintCore and the application as one binary.
  22. _TODO: merge information from https://tendermint.com/blog/tendermint-0-8-release_
  23. ## Message Types
  24. ABCI requests/responses are simple Protobuf messages. Check out the [schema file](https://github.com/tendermint/abci/blob/master/types/types.proto).
  25. #### DeliverTx
  26. * __Arguments__:
  27. * `Data ([]byte)`: The request transaction bytes
  28. * __Returns__:
  29. * `Code (uint32)`: Response code
  30. * `Data ([]byte)`: Result bytes, if any
  31. * `Log (string)`: Debug or error message
  32. * __Usage__:<br/>
  33. Append and run a transaction. If the transaction is valid, returns CodeType.OK
  34. #### CheckTx
  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. Validate a mempool transaction, prior to broadcasting or proposing. This message should not mutate the main state, but application
  43. developers may want to keep a separate CheckTx state that gets reset upon Commit.
  44. 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
  45. Transactions are first run through CheckTx before broadcast to peers in the mempool layer.
  46. You can make CheckTx semi-stateful and clear the state upon `Commit` or `BeginBlock`,
  47. to allow for dependent sequences of transactions in the same block.
  48. #### Commit
  49. * __Returns__:
  50. * `Data ([]byte)`: The Merkle root hash
  51. * `Log (string)`: Debug or error message
  52. * __Usage__:<br/>
  53. Return a Merkle root hash of the application state.
  54. #### Query
  55. * __Arguments__:
  56. * `Data ([]byte)`: Raw query bytes. Can be used with or in lieu of Path.
  57. * `Path (string)`: Path of request, like an HTTP GET path. Can be used with or in liue of Data.
  58. * Apps MUST interpret '/store' as a query by key on the underlying store. The key SHOULD be specified in the Data field.
  59. * Apps SHOULD allow queries over specific types like '/accounts/...' or '/votes/...'
  60. * `LastHeight (uint64)`: The block height for which you want the query (default=0 returns data for the latest committed block). Note that the corresponding Merkle root hash will only be included in the header of the next block (ie. `LastHeight + 1`)
  61. * `Prove (bool)`: Return Merkle proof with response if possible
  62. * __Returns__:
  63. * `Code (uint32)`: Response code
  64. * `Key ([]byte)`: The key of the matching data
  65. * `Value ([]byte)`: The value of the matching data
  66. * `Proof ([]byte)`: Proof for the data, if requested
  67. * `LastHeight (uint64)`: The block height from which data was derived. The Merkle root for the proof is included in block `LastHeight + 1`
  68. * `Log (string)`: Debug or error message
  69. *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 (recall height=0 defaults to latest block). Hopefully this will be improved soon(ish)
  70. #### Info
  71. * __Returns__:
  72. * `Data (string)`: Some arbitrary information
  73. * `Version (Version)`: Version information
  74. * `LastBlockHeight (uint64)`: Latest block for which the app has called Commit
  75. * `LastBlockAppHash ([]byte)`: Latest result of Commit
  76. * __Usage__:<br/>
  77. Return information about the application state. Used to sync the app with Tendermint on crash/restart.
  78. #### SetOption
  79. * __Arguments__:
  80. * `Key (string)`: Key to set
  81. * `Value (string)`: Value to set for key
  82. * __Returns__:
  83. * `Log (string)`: Debug or error message
  84. * __Usage__:<br/>
  85. Set application options. E.g. Key="mode", Value="mempool" for a mempool connection, or Key="mode", Value="consensus" for a consensus connection.
  86. Other options are application specific.
  87. #### InitChain
  88. * __Arguments__:
  89. * `Validators ([]Validator)`: Initial genesis validators
  90. * __Usage__:<br/>
  91. Called once upon genesis
  92. #### BeginBlock
  93. * __Arguments__:
  94. * `Hash ([]byte)`: The block height that is starting
  95. * `Header (struct{})`: The block header
  96. * __Usage__:<br/>
  97. Signals the beginning of a new block. Called prior to any DeliverTxs. The header is expected to at least contain the Height.
  98. #### EndBlock
  99. * __Arguments__:
  100. * `Height (uint64)`: The block height that ended
  101. * __Returns__:
  102. * `Diffs ([]Validator)`: Changed validators with new voting powers (0 to remove)
  103. * __Usage__:<br/>
  104. Signals the end of a block. Called prior to each Commit after all transactions. Validator set is updated with the result.
  105. # Implementations
  106. The ABCI is a client/server interface where the replication engine (blockchain) forms the client
  107. and the state machine (application) forms the server.
  108. As blocks are committed in the blockchain, they are forwarded to the application.
  109. This repository provides two implementations of an ABCI client & server: via socket and via GRPC.
  110. ## Socket
  111. ABCI is best implemented as a streaming protocol.
  112. The socket implementation provides for asynchronous, ordered message passing over unix or tcp.
  113. Messages are serialized using Protobuf3 and length-prefixed.
  114. 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.
  115. 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...`.
  116. ## GRPC
  117. GRPC is an rpc framework native to Protocol Buffers with support in many languages.
  118. Implementing the ABCI using GRPC can allow for faster prototyping, but is expected to be much slower than
  119. the ordered, asynchronous socket protocol.
  120. Note the length-prefixing used in the socket implementation does not apply for GRPC.
  121. # Tools and Apps
  122. The `abci-cli` tool wraps any ABCI client and can be used for probing/testing an ABCI application.
  123. See the [tutorial](https://tendermint.com/intro/getting-started/first-tmsp) for more details.
  124. Multiple example apps are included:
  125. - the `counter` application, which illustrates nonce checking in txs
  126. - the `dummy` application, which illustrates a simple key-value merkle tree
  127. - the `dummy --persistent` application, which augments the dummy with persistence and validator set changes
  128. # Build
  129. To build the protobuf code:
  130. ```
  131. make protoc
  132. ```
  133. See `protoc --help` and [the grpc docs](https://www.grpc.io/docs) for examples and details of other languages