|
| 1 | +# ABCI Specification |
| 2 | + |
| 3 | +## Message Types |
| 4 | + |
| 5 | +ABCI requests/responses are defined as simple Protobuf messages in [this |
| 6 | +schema file](https://github.com/tendermint/abci/blob/master/types/types.proto). |
| 7 | +TendermintCore sends the requests, and the ABCI application sends the |
| 8 | +responses. Here, we provide an overview of the messages types and how |
| 9 | +they are used by Tendermint. Then we describe each request-response pair |
| 10 | +as a function with arguments and return values, and add some notes on |
| 11 | +usage. |
| 12 | + |
| 13 | +Some messages (`Echo, Info, InitChain, BeginBlock, EndBlock, Commit`), |
| 14 | +don't return errors because an error would indicate a critical failure |
| 15 | +in the application and there's nothing Tendermint can do. The problem |
| 16 | +should be addressed and both Tendermint and the application restarted. |
| 17 | +All other messages (`SetOption, Query, CheckTx, DeliverTx`) return an |
| 18 | +application-specific response `Code uint32`, where only `0` is reserved |
| 19 | +for `OK`. |
| 20 | + |
| 21 | +Some messages (`SetOption, Query, CheckTx, DeliverTx`) return |
| 22 | +non-deterministic data in the form of `Info` and `Log`. The `Log` is |
| 23 | +intended for the literal output from the application's logger, while the |
| 24 | +`Info` is any additional info that should be returned. |
| 25 | + |
| 26 | +The first time a new blockchain is started, Tendermint calls |
| 27 | +`InitChain`. From then on, the Block Execution Sequence that causes the |
| 28 | +committed state to be updated is as follows: |
| 29 | + |
| 30 | +`BeginBlock, [DeliverTx], EndBlock, Commit` |
| 31 | + |
| 32 | +where one `DeliverTx` is called for each transaction in the block. |
| 33 | +Cryptographic commitments to the results of DeliverTx, EndBlock, and |
| 34 | +Commit are included in the header of the next block. |
| 35 | + |
| 36 | +Tendermint opens three connections to the application to handle the |
| 37 | +different message types: |
| 38 | + |
| 39 | +- `Consensus Connection - InitChain, BeginBlock, DeliverTx, EndBlock, Commit` |
| 40 | +- `Mempool Connection - CheckTx` |
| 41 | +- `Info Connection - Info, SetOption, Query` |
| 42 | + |
| 43 | +The `Flush` message is used on every connection, and the `Echo` message |
| 44 | +is only used for debugging. |
| 45 | + |
| 46 | +Note that messages may be sent concurrently across all connections -a |
| 47 | +typical application will thus maintain a distinct state for each |
| 48 | +connection. They may be referred to as the `DeliverTx state`, the |
| 49 | +`CheckTx state`, and the `Commit state` respectively. |
| 50 | + |
| 51 | +See below for more details on the message types and how they are used. |
| 52 | + |
| 53 | +### Echo |
| 54 | + |
| 55 | +- **Arguments**: |
| 56 | + - `Message (string)`: A string to echo back |
| 57 | +- **Returns**: |
| 58 | + - `Message (string)`: The input string |
| 59 | +- **Usage**: |
| 60 | + - Echo a string to test an abci client/server implementation |
| 61 | + |
| 62 | +### Flush |
| 63 | + |
| 64 | +- **Usage**: |
| 65 | + - Signals that messages queued on the client should be flushed to |
| 66 | + the server. It is called periodically by the client |
| 67 | + implementation to ensure asynchronous requests are actually |
| 68 | + sent, and is called immediately to make a synchronous request, |
| 69 | + which returns when the Flush response comes back. |
| 70 | + |
| 71 | +### Info |
| 72 | + |
| 73 | +- **Arguments**: |
| 74 | + - `Version (string)`: The Tendermint version |
| 75 | +- **Returns**: |
| 76 | + - `Data (string)`: Some arbitrary information |
| 77 | + - `Version (Version)`: Version information |
| 78 | + - `LastBlockHeight (int64)`: Latest block for which the app has |
| 79 | + called Commit |
| 80 | + - `LastBlockAppHash ([]byte)`: Latest result of Commit |
| 81 | +- **Usage**: |
| 82 | + - Return information about the application state. |
| 83 | + - Used to sync Tendermint with the application during a handshake |
| 84 | + that happens on startup. |
| 85 | + - Tendermint expects `LastBlockAppHash` and `LastBlockHeight` to |
| 86 | + be updated during `Commit`, ensuring that `Commit` is never |
| 87 | + called twice for the same block height. |
| 88 | + |
| 89 | +### SetOption |
| 90 | + |
| 91 | +- **Arguments**: |
| 92 | + - `Key (string)`: Key to set |
| 93 | + - `Value (string)`: Value to set for key |
| 94 | +- **Returns**: |
| 95 | + - `Code (uint32)`: Response code |
| 96 | + - `Log (string)`: The output of the application's logger. May |
| 97 | + be non-deterministic. |
| 98 | + - `Info (string)`: Additional information. May |
| 99 | + be non-deterministic. |
| 100 | +- **Usage**: |
| 101 | + - Set non-consensus critical application specific options. |
| 102 | + - e.g. Key="min-fee", Value="100fermion" could set the minimum fee |
| 103 | + required for CheckTx (but not DeliverTx - that would be |
| 104 | + consensus critical). |
| 105 | + |
| 106 | +### InitChain |
| 107 | + |
| 108 | +- **Arguments**: |
| 109 | + - `Validators ([]Validator)`: Initial genesis validators |
| 110 | + - `AppStateBytes ([]byte)`: Serialized initial application state |
| 111 | +- **Usage**: |
| 112 | + - Called once upon genesis. |
| 113 | + |
| 114 | +### Query |
| 115 | + |
| 116 | +- **Arguments**: |
| 117 | + - `Data ([]byte)`: Raw query bytes. Can be used with or in lieu |
| 118 | + of Path. |
| 119 | + - `Path (string)`: Path of request, like an HTTP GET path. Can be |
| 120 | + used with or in liue of Data. |
| 121 | + - Apps MUST interpret '/store' as a query by key on the |
| 122 | + underlying store. The key SHOULD be specified in the Data field. |
| 123 | + - Apps SHOULD allow queries over specific types like |
| 124 | + '/accounts/...' or '/votes/...' |
| 125 | + - `Height (int64)`: The block height for which you want the query |
| 126 | + (default=0 returns data for the latest committed block). Note |
| 127 | + that this is the height of the block containing the |
| 128 | + application's Merkle root hash, which represents the state as it |
| 129 | + was after committing the block at Height-1 |
| 130 | + - `Prove (bool)`: Return Merkle proof with response if possible |
| 131 | +- **Returns**: |
| 132 | + - `Code (uint32)`: Response code. |
| 133 | + - `Log (string)`: The output of the application's logger. May |
| 134 | + be non-deterministic. |
| 135 | + - `Info (string)`: Additional information. May |
| 136 | + be non-deterministic. |
| 137 | + - `Index (int64)`: The index of the key in the tree. |
| 138 | + - `Key ([]byte)`: The key of the matching data. |
| 139 | + - `Value ([]byte)`: The value of the matching data. |
| 140 | + - `Proof ([]byte)`: Proof for the data, if requested. |
| 141 | + - `Height (int64)`: The block height from which data was derived. |
| 142 | + Note that this is the height of the block containing the |
| 143 | + application's Merkle root hash, which represents the state as it |
| 144 | + was after committing the block at Height-1 |
| 145 | +- **Usage**: |
| 146 | + - Query for data from the application at current or past height. |
| 147 | + - Optionally return Merkle proof. |
| 148 | + |
| 149 | +### BeginBlock |
| 150 | + |
| 151 | +- **Arguments**: |
| 152 | + - `Hash ([]byte)`: The block's hash. This can be derived from the |
| 153 | + block header. |
| 154 | + - `Header (struct{})`: The block header |
| 155 | + - `AbsentValidators ([]int32)`: List of indices of validators not |
| 156 | + included in the LastCommit |
| 157 | + - `ByzantineValidators ([]Evidence)`: List of evidence of |
| 158 | + validators that acted maliciously |
| 159 | +- **Usage**: |
| 160 | + - Signals the beginning of a new block. Called prior to |
| 161 | + any DeliverTxs. |
| 162 | + - The header is expected to at least contain the Height. |
| 163 | + - The `AbsentValidators` and `ByzantineValidators` can be used to |
| 164 | + determine rewards and punishments for the validators. |
| 165 | + |
| 166 | +### CheckTx |
| 167 | + |
| 168 | +- **Arguments**: |
| 169 | + - `Tx ([]byte)`: The request transaction bytes |
| 170 | +- **Returns**: |
| 171 | + - `Code (uint32)`: Response code |
| 172 | + - `Data ([]byte)`: Result bytes, if any. |
| 173 | + - `Log (string)`: The output of the application's logger. May |
| 174 | + be non-deterministic. |
| 175 | + - `Info (string)`: Additional information. May |
| 176 | + be non-deterministic. |
| 177 | + - `GasWanted (int64)`: Amount of gas request for transaction. |
| 178 | + - `GasUsed (int64)`: Amount of gas consumed by transaction. |
| 179 | + - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing |
| 180 | + transactions (eg. by account). |
| 181 | + - `Fee (cmn.KI64Pair)`: Fee paid for the transaction. |
| 182 | +- **Usage**: Validate a mempool transaction, prior to broadcasting |
| 183 | + or proposing. CheckTx should perform stateful but light-weight |
| 184 | + checks of the validity of the transaction (like checking signatures |
| 185 | + and account balances), but need not execute in full (like running a |
| 186 | + smart contract). |
| 187 | + |
| 188 | + Tendermint runs CheckTx and DeliverTx concurrently with eachother, |
| 189 | + though on distinct ABCI connections - the mempool connection and the |
| 190 | + consensus connection, respectively. |
| 191 | + |
| 192 | + The application should maintain a separate state to support CheckTx. |
| 193 | + This state can be reset to the latest committed state during |
| 194 | + `Commit`, where Tendermint ensures the mempool is locked and not |
| 195 | + sending new `CheckTx`. After `Commit`, the mempool will rerun |
| 196 | + CheckTx on all remaining transactions, throwing out any that are no |
| 197 | + longer valid. |
| 198 | + |
| 199 | + Keys and values in Tags must be UTF-8 encoded strings (e.g. |
| 200 | + "account.owner": "Bob", "balance": "100.0", "date": "2018-01-02") |
| 201 | + |
| 202 | +### DeliverTx |
| 203 | + |
| 204 | +- **Arguments**: |
| 205 | + - `Tx ([]byte)`: The request transaction bytes. |
| 206 | +- **Returns**: |
| 207 | + - `Code (uint32)`: Response code. |
| 208 | + - `Data ([]byte)`: Result bytes, if any. |
| 209 | + - `Log (string)`: The output of the application's logger. May |
| 210 | + be non-deterministic. |
| 211 | + - `Info (string)`: Additional information. May |
| 212 | + be non-deterministic. |
| 213 | + - `GasWanted (int64)`: Amount of gas requested for transaction. |
| 214 | + - `GasUsed (int64)`: Amount of gas consumed by transaction. |
| 215 | + - `Tags ([]cmn.KVPair)`: Key-Value tags for filtering and indexing |
| 216 | + transactions (eg. by account). |
| 217 | + - `Fee (cmn.KI64Pair)`: Fee paid for the transaction. |
| 218 | +- **Usage**: |
| 219 | + - Deliver a transaction to be executed in full by the application. |
| 220 | + If the transaction is valid, returns CodeType.OK. |
| 221 | + - Keys and values in Tags must be UTF-8 encoded strings (e.g. |
| 222 | + "account.owner": "Bob", "balance": "100.0", |
| 223 | + "time": "2018-01-02T12:30:00Z") |
| 224 | + |
| 225 | +### EndBlock |
| 226 | + |
| 227 | +- **Arguments**: |
| 228 | + - `Height (int64)`: Height of the block just executed. |
| 229 | +- **Returns**: |
| 230 | + - `ValidatorUpdates ([]Validator)`: Changes to validator set (set |
| 231 | + voting power to 0 to remove). |
| 232 | + - `ConsensusParamUpdates (ConsensusParams)`: Changes to |
| 233 | + consensus-critical time, size, and other parameters. |
| 234 | +- **Usage**: |
| 235 | + - Signals the end of a block. |
| 236 | + - Called prior to each Commit, after all transactions. |
| 237 | + - Validator set and consensus params are updated with the result. |
| 238 | + - Validator pubkeys are expected to be go-wire encoded. |
| 239 | + |
| 240 | +### Commit |
| 241 | + |
| 242 | +- **Returns**: |
| 243 | + - `Data ([]byte)`: The Merkle root hash |
| 244 | +- **Usage**: |
| 245 | + - Persist the application state. |
| 246 | + - Return a Merkle root hash of the application state. |
| 247 | + - It's critical that all application instances return the |
| 248 | + same hash. If not, they will not be able to agree on the next |
| 249 | + block, because the hash is included in the next block! |
0 commit comments