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.

187 lines
8.9 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
7 years ago
8 years ago
8 years ago
7 years ago
8 years ago
7 years ago
7 years ago
8 years ago
9 years ago
7 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
7 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
7 years ago
8 years ago
7 years ago
8 years ago
7 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
7 years ago
8 years ago
8 years ago
7 years ago
9 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/abci-the-application-blockchain-interface),
  9. and the more detailed [application developer's guide](https://tendermint.com/docs/guides/app-development).
  10. Previously, the ABCI was referred to as TMSP.
  11. Other implementations:
  12. * C++ [cpp-tmsp](https://github.com/mdyring/cpp-tmsp) by Martin Dyring-Andersen
  13. * JavaScript [js-abci](https://github.com/tendermint/js-abci)
  14. * Java [jABCI](https://github.com/jTendermint/jabci)
  15. * Erlang [abci_server](https://github.com/KrzysiekJ/abci_server) by Krzysztof Jurewicz
  16. # Specification
  17. The [primary specification](https://github.com/tendermint/abci/blob/master/types/types.proto) is made using Protocol Buffers.
  18. To build it, run
  19. ```
  20. make protoc
  21. ```
  22. See `protoc --help` and [the Protocol Buffers site](https://developers.google.com/protocol-buffers/) for details on compiling for other languages.
  23. Note we also include a [GRPC](http://www.grpc.io/docs) service definition.
  24. For the specification as an interface in Go, see the [types/application.go file](https://github.com/tendermint/abci/blob/master/types/application.go).
  25. ## Message Types
  26. ABCI requests/responses are defined as simple Protobuf messages in [this schema file](https://github.com/tendermint/abci/blob/master/types/types.proto).
  27. TendermintCore sends the requests, and the ABCI application sends the responses.
  28. Here, we describe the requests and responses as function arguments and return values, and make some notes about usage:
  29. #### DeliverTx
  30. * __Arguments__:
  31. * `Data ([]byte)`: The request transaction bytes
  32. * __Returns__:
  33. * `Code (uint32)`: Response code
  34. * `Data ([]byte)`: Result bytes, if any
  35. * `Log (string)`: Debug or error message
  36. * __Usage__:<br/>
  37. Append and run a transaction. If the transaction is valid, returns CodeType.OK
  38. #### CheckTx
  39. * __Arguments__:
  40. * `Data ([]byte)`: The request transaction bytes
  41. * __Returns__:
  42. * `Code (uint32)`: Response code
  43. * `Data ([]byte)`: Result bytes, if any
  44. * `Log (string)`: Debug or error message
  45. * __Usage__:<br/>
  46. Validate a mempool transaction, prior to broadcasting or proposing. This message should not mutate the main state, but application
  47. developers may want to keep a separate CheckTx state that gets reset upon Commit.
  48. CheckTx can happen interspersed with DeliverTx, but they happen on different ABCI 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 state.
  49. Transactions are first run through CheckTx before broadcast to peers in the mempool layer.
  50. You can make CheckTx semi-stateful and clear the state upon `Commit` or `BeginBlock`,
  51. to allow for dependent sequences of transactions in the same block.
  52. #### Commit
  53. * __Returns__:
  54. * `Data ([]byte)`: The Merkle root hash
  55. * `Log (string)`: Debug or error message
  56. * __Usage__:<br/>
  57. Return a Merkle root hash of the application state.
  58. #### Query
  59. * __Arguments__:
  60. * `Data ([]byte)`: Raw query bytes. Can be used with or in lieu of Path.
  61. * `Path (string)`: Path of request, like an HTTP GET path. Can be used with or in liue of Data.
  62. * Apps MUST interpret '/store' as a query by key on the underlying store. The key SHOULD be specified in the Data field.
  63. * Apps SHOULD allow queries over specific types like '/accounts/...' or '/votes/...'
  64. * `Height (uint64)`: The block height for which you want the query (default=0 returns data for the latest committed block). Note that this is the height of the block containing the application's Merkle root hash, which represents the state as it was after committing the block at Height-1
  65. * `Prove (bool)`: Return Merkle proof with response if possible
  66. * __Returns__:
  67. * `Code (uint32)`: Response code
  68. * `Key ([]byte)`: The key of the matching data
  69. * `Value ([]byte)`: The value of the matching data
  70. * `Proof ([]byte)`: Proof for the data, if requested
  71. * `Height (uint64)`: The block height from which data was derived. Note that this is the height of the block containing the application's Merkle root hash, which represents the state as it was after committing the block at Height-1
  72. * `Log (string)`: Debug or error message
  73. *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)
  74. #### Info
  75. * __Returns__:
  76. * `Data (string)`: Some arbitrary information
  77. * `Version (Version)`: Version information
  78. * `LastBlockHeight (uint64)`: Latest block for which the app has called Commit
  79. * `LastBlockAppHash ([]byte)`: Latest result of Commit
  80. * __Usage__:<br/>
  81. Return information about the application state. Used to sync the app with Tendermint on crash/restart.
  82. #### SetOption
  83. * __Arguments__:
  84. * `Key (string)`: Key to set
  85. * `Value (string)`: Value to set for key
  86. * __Returns__:
  87. * `Log (string)`: Debug or error message
  88. * __Usage__:<br/>
  89. Set application options. E.g. Key="mode", Value="mempool" for a mempool connection, or Key="mode", Value="consensus" for a consensus connection.
  90. Other options are application specific.
  91. #### InitChain
  92. * __Arguments__:
  93. * `Validators ([]Validator)`: Initial genesis validators
  94. * __Usage__:<br/>
  95. Called once upon genesis
  96. #### BeginBlock
  97. * __Arguments__:
  98. * `Hash ([]byte)`: The block's hash. This can be derived from the block header.
  99. * `Header (struct{})`: The block header
  100. * __Usage__:<br/>
  101. Signals the beginning of a new block. Called prior to any DeliverTxs. The header is expected to at least contain the Height.
  102. #### EndBlock
  103. * __Arguments__:
  104. * `Height (uint64)`: The block height that ended
  105. * __Returns__:
  106. * `Diffs ([]Validator)`: Changed validators with new voting powers (0 to remove)
  107. * __Usage__:<br/>
  108. Signals the end of a block. Called prior to each Commit after all transactions. Validator set is updated with the result.
  109. #### Echo
  110. * __Arguments__:
  111. * `Message (string)`: A string to echo back
  112. * __Returns__:
  113. * `Message (string)`: The input string
  114. * __Usage__:<br/>
  115. * Echo a string to test an abci client/server implementation
  116. #### Flush
  117. * __Usage__:<br/>
  118. * Signals that messages queued on the client should be flushed to the server. It is called periodically by the client implementation to ensure asynchronous requests are actually sent, and is called immediately to make a synchronous request, which returns when the Flush response comes back.
  119. # Implementation
  120. We provide three implementations of the ABCI in Go:
  121. 1. ABCI-socket
  122. 2. GRPC
  123. 3. Golang in-process
  124. ## Socket
  125. ABCI is best implemented as a streaming protocol.
  126. The socket implementation provides for asynchronous, ordered message passing over unix or tcp.
  127. Messages are serialized using Protobuf3 and length-prefixed.
  128. 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.
  129. 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...`.
  130. ## GRPC
  131. GRPC is an rpc framework native to Protocol Buffers with support in many languages.
  132. Implementing the ABCI using GRPC can allow for faster prototyping, but is expected to be much slower than
  133. the ordered, asynchronous socket protocol.
  134. Note the length-prefixing used in the socket implementation does not apply for GRPC.
  135. ## In Process
  136. The simplest implementation just uses function calls within Go.
  137. This means ABCI applications written in Golang can be compiled with TendermintCore and run as a single binary.
  138. # Tools and Apps
  139. The `abci-cli` tool wraps any ABCI client and can be used for probing/testing an ABCI application.
  140. See the [guide](https://tendermint.com/docs/guides/abci-cli) for more details.
  141. Multiple example apps are included:
  142. - the `counter` application, which illustrates nonce checking in txs
  143. - the `dummy` application, which illustrates a simple key-value merkle tree
  144. - the `dummy --persistent` application, which augments the dummy with persistence and validator set changes