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.

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