pub trait Consensus {
    fn init_chain(
        &self,
        init_chain_request: RequestInitChain
    ) -> ResponseInitChain; fn begin_block(
        &self,
        begin_block_request: RequestBeginBlock
    ) -> ResponseBeginBlock; fn deliver_tx(
        &self,
        deliver_tx_request: RequestDeliverTx
    ) -> ResponseDeliverTx; fn end_block(&self, end_block_request: RequestEndBlock) -> ResponseEndBlock; fn commit(&self, commit_request: RequestCommit) -> ResponseCommit; fn echo(&self, echo_request: RequestEcho) -> ResponseEcho { ... } fn flush(&self, _flush_request: RequestFlush) -> ResponseFlush { ... } }
Available on crate feature sync-api only.
Expand description

Trait for managing consensus of blockchain.

Details

Consensus should maintain a consensus_state - the working state for block execution. It should be updated by the calls to begin_block, deliver_tx, and end_block during block execution and committed to disk as the latest committed state during commit.

Updates made to the consensus_state by each method call must be readable by each subsequent method - ie. the updates are linearizable.

Required Methods

Called once upon genesis. Usually used to establish initial (genesis) state.

Signals the beginning of a new block. Called prior to any deliver_txs.

Execute the transaction in full. The workhorse of the application.

Signals the end of a block. Called after all transactions, prior to each commit.

Persist the application state.

Details

Application state should only be persisted to disk during commit.

Before commit is called, Tendermint locks and flushes the mempool so that no new messages will be received on the mempool connection. This provides an opportunity to safely update all three states (Consensus, Mempool and Info) to the latest committed state at once.

When commit completes, it unlocks the mempool.

Warning

If the ABCI application logic processing the commit message sends a /broadcast_tx_sync or /broadcast_tx_commit and waits for the response before proceeding, it will deadlock. Executing those broadcast_tx calls involves acquiring a lock that is held during the commit call, so it’s not possible. If you make the call to the broadcast_tx endpoints concurrently, that’s no problem, it just can’t be part of the sequential logic of the commit function.

Provided Methods

Echo a string to test abci client/server implementation.

Signals that messages queued on the client should be flushed to the server.

Implementors