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.

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