Application BlockChain Interface eXtension (ABCIx)
Overview
ABCIx is an extension of ABCI that offers:
- greater flexibility in block production: when creating a new block, instead of including the transactions from the mempool in an FIFO manner, ABCIx allows the application to decide which transactions from the mempool will be included and the order; and
- greater security: when creating a block, ABCIx allows the application to detect conflicting transactions and remove them from the mempool. This ensures that all transactions in a block are valid, while ABCI allows invalid transactions in a block and defers to the application to handle such transactions; and
- more applications: for example, one application is to use TendermintX+ABCIx to serve as a finality gadget of another chain (such as PoW chain); and
- backward compatible with ABCI: ABCIx can easily support existing ABCI applications by using ABCI adapter, which is an ABCIx application and provides ABCI to the underly ABCI applications.
Similar to ABCI, ABCIx provides the methods in the following ABCIx connections:
- Consensus connection:
InitChain
,DeliverBlock
,CreateBlock
- Validation connection:
CheckTx
,CheckBlock
- Info connection:
Info
,SetOption
,Query
- Snapshot connection:
ListSnapshots
,LoadSnapshotChunk
,OfferSnapshot
,ApplySnapshotChunk
where
-
CheckTx
will return an extra fieldPriority (int64)
to indicate how to order the tx in mempool. -
CreateBlock
allows the application to iterate the transactions from mempool ordered by priority and select the ones to be included in the block. -
CheckBlock
will be called after a proposed block is received and before the nodes votes for the block.CheckBlock
will returnCode
to determine whether the block is valid or not. For example,- The block contains invalid transactions; or
- The block’s app hash does not match the app hash determined by application;
- The block’s result hash does not match the results emitted by application;
- The block’s gas usage exceeds the gas limit.
If the block is invalid, TendermintX will not vote for the block in the followingpre-vote
phase.
-
DeliverBlock
behaves similar to the combination ofABCI.BeginBlock
, a list ofABCI.DeliverBlock
,ABCI.EndBlock
, andABCI.Commit
methods. Note that a block may be delivered without being checked. - The rest of ABCIx methods should behave the same as those of ABCI.
Methods
CheckTx
-
Input:
- Input of ABCI.CheckTx.
-
Output:
- Output of ABCI.CheckTx.
-
Priority (int64)
: The priority of the tx in mempool.
-
Note
- The priority determines the order the tx that will be fed to CreateBlock.
- If some txs have the same priority in the mempool, they will be ordered in an FIFO manner.
CreateBlock
-
Input
-
Height (int64)
: Height of the block to be created. -
LastCommitInfo (LastCommitInfo)
: Info about the last commit, including the
round, and the list of validators and which ones signed the last block. -
ByzantineValidators ([]Evidence)
: List of evidence of
validators that acted maliciously. -
MempoolIterator (interface{})
: Iterator to iterate all txs in the mempool. It provides a functionNext(maxBytes int64, maxGas int64) []byte
, which returns a tx ordered by priority with size <= maxBytes and GasWanted <= maxGas or nil if no such tx is found.
-
-
Output
-
TxList ([][]byte)
: A list of txs will be included in the block. -
InvalidTxList ([][]byte)
: A list of txs should be removed from mempool. -
AppHash ([]byte)
: App hash after executing the transactions. -
Tags ([]kv.Pair)
: A list of tags (events) emitted by the block.
-
DeliverBlock
-
Input
- Input of ABCI.EndBlock.
- A list of the inputs of ABCI.DeliverTx.
- Input of ABCI.BeginBlock.
- Input of ABCI.Commit.
-
Output
- Output of ABCI.BeginBlock.
- A list of the outputs of ABCI.DeliverTx
- Output of ABCI.EndBlock.
- Output of ABCI.Commit.
-
Note
- ABCIx will compare the hash of the returned
Tags
withLastResultHash
in header (LastResultHash
will be renamed toResultHash
in TendermintX). If the comparison fails, the BFT consensus is broken and TendermintX will stop working.
- ABCIx will compare the hash of the returned
CheckBlock
-
Input
- Input of ABCI.EndBlock.
- A list of the input of ABCI.DeliverTx.
- Input of ABCI.BeginBlock.
- Input of ABCI.Commit.
-
Output
- Code (uint32): Response code.
- Output of ABCI.BeginBlock.
- A list of the output of ABCI.DeliverTx
- Output of ABCI.EndBlock.
- Output of ABCI.Commit.
-
Note
- The method will be called after a proposed block is received and before a vote is sent for the block.
- If
Code
is non-zero, the block is treated as invalid. - ABCIx will compare the hash of the returned
Tags
withLastResultHash
in header (LastResultHash
will be renamed toResultHash
in TendermintX). If the comparison fails, TendermintX will treat the block as invalid.
ABCI Adapter
ABCI adapter implements ABCIx and translates all ABCIx methods to ABCI methods. Basically, ABCI adaptor implements the ABCIx methods as:
- CheckTx: call and return ABCI.CheckTx with Priority 0.
- CreateBlock: iterate and include txs from mempool until maxGas or maxBytes limits is reached without executing any txs. Return AppHash and Tags of the previous block that are stored in the application DB.
- CheckBlock: compare whether header.AppHash equals to the AppHash of the previous block stored in the application. Return the Tags of the previous block stored in the application DB.
- DeliverBlock: call ABCI.DeliverBlock. Store ABCI.DeliverBlock.Data and ABCI.DeliverBlock.Tags in application DB. Return the Tags of the previous block stored in the applicaiton DB.
Wanna Contribute?
Please check out the repo at https://github.com/QuarkChain/tendermintx/blob/master/abcix that we start a few days ago