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.

203 lines
9.7 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
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 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
7 years ago
7 years ago
9 years ago
7 years ago
9 years ago
7 years ago
9 years ago
7 years ago
9 years ago
7 years ago
9 years ago
8 years ago
7 years ago
8 years ago
8 years ago
9 years ago
9 years ago
7 years ago
8 years ago
7 years ago
7 years ago
8 years ago
7 years ago
7 years ago
7 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 systems 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 background information on ABCI, motivations, and tendermint, please visit [the documentation](http://tendermint.readthedocs.io/en/master/).
  9. The two guides to focus on are the `Application Development Guide` and `Using ABCI-CLI`.
  10. Previously, the ABCI was referred to as TMSP.
  11. The community has provided a number of addtional implementations, see the `Tendermint Ecosystem` in [the documentation](http://tendermint.readthedocs.io/en/master/).
  12. ## Implementation
  13. We provide three implementations of the ABCI in Go:
  14. - Golang in-process
  15. - ABCI-socket
  16. - GRPC
  17. Note the GRPC version is maintained primarily to simplify onboarding and prototyping and is not receiving the same
  18. attention to security and performance as the others.
  19. ### In Process
  20. The simplest implementation just uses function calls within Go.
  21. This means ABCI applications written in Golang can be compiled with TendermintCore and run as a single binary.
  22. ### Socket (TSP)
  23. ABCI is best implemented as a streaming protocol.
  24. The socket implementation provides for asynchronous, ordered message passing over unix or tcp.
  25. Messages are serialized using Protobuf3 and length-prefixed.
  26. 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.
  27. 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...`.
  28. ### GRPC
  29. GRPC is an rpc framework native to Protocol Buffers with support in many languages.
  30. Implementing the ABCI using GRPC can allow for faster prototyping, but is expected to be much slower than
  31. the ordered, asynchronous socket protocol. The implementation has also not received as much testing or review.
  32. Note the length-prefixing used in the socket implementation does not apply for GRPC.
  33. ## Tools
  34. The `abci-cli` tool wraps an ABCI client and can be used for probing/testing an ABCI server.
  35. For instance, `abci-cli test` will run a test sequence against a listening server running the Counter application (see below).
  36. It can also be used to run some example applications.
  37. See [the documentation](http://tendermint.readthedocs.io/en/master/) for more details.
  38. ### Example Apps
  39. Multiple example apps are included:
  40. - the `abci-cli counter` application, which illustrates nonce checking in txs
  41. - the `abci-cli dummy` application, which illustrates a simple key-value Merkle tree
  42. - the `abci-cli dummy --persistent` application, which augments the dummy with persistence and validator set changes
  43. ### Install
  44. ```
  45. go get github.com/tendermint/abci
  46. cd $GOPATH/src/github.com/tendermint/abci
  47. make get_vendor_deps
  48. make install
  49. ```
  50. ## Specification
  51. The [primary specification](https://github.com/tendermint/abci/blob/master/types/types.proto) is made using Protocol Buffers.
  52. To build it, run
  53. ```
  54. make protoc
  55. ```
  56. See `protoc --help` and [the Protocol Buffers site](https://developers.google.com/protocol-buffers/) for details on compiling for other languages.
  57. Note we also include a [GRPC](http://www.grpc.io/docs) service definition.
  58. For the specification as an interface in Go, see the [types/application.go file](https://github.com/tendermint/abci/blob/master/types/application.go).
  59. ### Message Types
  60. ABCI requests/responses are defined as simple Protobuf messages in [this schema file](https://github.com/tendermint/abci/blob/master/types/types.proto).
  61. TendermintCore sends the requests, and the ABCI application sends the responses.
  62. Here, we describe the requests and responses as function arguments and return values, and make some notes about usage:
  63. #### Echo
  64. * __Arguments__:
  65. * `Message (string)`: A string to echo back
  66. * __Returns__:
  67. * `Message (string)`: The input string
  68. * __Usage__:<br/>
  69. * Echo a string to test an abci client/server implementation
  70. #### Flush
  71. * __Usage__:<br/>
  72. * 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.
  73. #### Info
  74. * __Returns__:
  75. * `Data (string)`: Some arbitrary information
  76. * `Version (Version)`: Version information
  77. * `LastBlockHeight (int64)`: 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. * `Code (uint32)`: Response code
  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. #### Query
  97. * __Arguments__:
  98. * `Data ([]byte)`: Raw query bytes. Can be used with or in lieu of Path.
  99. * `Path (string)`: Path of request, like an HTTP GET path. Can be used with or in liue of Data.
  100. * Apps MUST interpret '/store' as a query by key on the underlying store. The key SHOULD be specified in the Data field.
  101. * Apps SHOULD allow queries over specific types like '/accounts/...' or '/votes/...'
  102. * `Height (int64)`: 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
  103. * `Prove (bool)`: Return Merkle proof with response if possible
  104. * __Returns__:
  105. * `Code (uint32)`: Response code
  106. * `Key ([]byte)`: The key of the matching data
  107. * `Value ([]byte)`: The value of the matching data
  108. * `Proof ([]byte)`: Proof for the data, if requested
  109. * `Height (int64)`: 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
  110. * `Log (string)`: Debug or error message
  111. #### BeginBlock
  112. * __Arguments__:
  113. * `Hash ([]byte)`: The block's hash. This can be derived from the block header.
  114. * `Header (struct{})`: The block header
  115. * `AbsentValidators ([]int32)`: List of indices of validators not included in the LastCommit
  116. * `ByzantineValidators ([]Evidence)`: List of evidence of validators that acted maliciously
  117. * __Usage__:<br/>
  118. Signals the beginning of a new block. Called prior to any DeliverTxs. The header is expected to at least contain the Height. The `AbsentValidators` and `ByzantineValidators` can be used to determine rewards and punishments for the validators.
  119. #### CheckTx
  120. * __Arguments__:
  121. * `Data ([]byte)`: The request transaction bytes
  122. * __Returns__:
  123. * `Code (uint32)`: Response code
  124. * `Data ([]byte)`: Result bytes, if any
  125. * `Log (string)`: Debug or error message
  126. * `Gas (int64)`: Amount of gas consumed by transaction
  127. * `Fee (int64)`: Fee paid by transaction
  128. * __Usage__:<br/>
  129. Validate a mempool transaction, prior to broadcasting or proposing. This message should not mutate the main state, but application
  130. developers may want to keep a separate CheckTx state that gets reset upon Commit.
  131. 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.
  132. Transactions are first run through CheckTx before broadcast to peers in the mempool layer.
  133. You can make CheckTx semi-stateful and clear the state upon `Commit` or `BeginBlock`,
  134. to allow for dependent sequences of transactions in the same block.
  135. #### DeliverTx
  136. * __Arguments__:
  137. * `Data ([]byte)`: The request transaction bytes
  138. * __Returns__:
  139. * `Code (uint32)`: Response code
  140. * `Data ([]byte)`: Result bytes, if any
  141. * `Log (string)`: Debug or error message
  142. * `Tags ([]*KVPair)`: Optional tags for indexing
  143. * __Usage__:<br/>
  144. Append and run a transaction. If the transaction is valid, returns CodeType.OK
  145. #### EndBlock
  146. * __Arguments__:
  147. * `Height (int64)`: The block height that ended
  148. * __Returns__:
  149. * `ValidatorUpdates ([]Validator)`: Changes to validator set (set voting power to 0 to remove)
  150. * `ConsensusParamUpdates (ConsensusParams)`: Changes to consensus-critical time/size parameters
  151. * __Usage__:<br/>
  152. Signals the end of a block. Called prior to each Commit after all transactions. Validator set is updated with the result.
  153. #### Commit
  154. * __Returns__:
  155. * `Data ([]byte)`: The Merkle root hash
  156. * `Log (string)`: Debug or error message
  157. * __Usage__:<br/>
  158. Return a Merkle root hash of the application state.