Skip to main content

Application

Trait Application 

Source
pub trait Application: Send + Sync {
    // Required method
    fn on_commit(&self, block: &Block, ctx: &BlockContext<'_>) -> Result<()>;

    // Provided methods
    fn create_payload(&self, _ctx: &BlockContext<'_>) -> Vec<u8>  { ... }
    fn validate_block(&self, _block: &Block, _ctx: &BlockContext<'_>) -> bool { ... }
    fn validate_tx(&self, _tx: &[u8]) -> bool { ... }
    fn begin_block(&self, _ctx: &BlockContext<'_>) -> Result<()> { ... }
    fn deliver_tx(&self, _tx: &[u8]) -> Result<()> { ... }
    fn end_block(&self, _ctx: &BlockContext<'_>) -> Result<EndBlockResponse> { ... }
    fn on_evidence(&self, _proof: &EquivocationProof) -> Result<()> { ... }
    fn query(&self, _path: &str, _data: &[u8]) -> Result<Vec<u8>> { ... }
}
Expand description

ABCI-like application interface for the consensus engine.

The lifecycle for each committed block:

  1. begin_block — called at the start of block execution
  2. deliver_tx — called for each transaction in the payload
  3. end_block — called after all transactions; may return validator updates
  4. on_commit — called when the block is finalized

For block validation (before voting, not yet committed):

  • validate_block — full block validation
  • validate_tx — individual transaction validation for mempool

For evidence:

  • on_evidence — called when equivocation (double-voting) is detected

Required Methods§

Source

fn on_commit(&self, block: &Block, ctx: &BlockContext<'_>) -> Result<()>

Called when a block is committed to the chain.

Provided Methods§

Source

fn create_payload(&self, _ctx: &BlockContext<'_>) -> Vec<u8>

Create a payload for a new block proposal. Typically pulls transactions from the mempool.

Source

fn validate_block(&self, _block: &Block, _ctx: &BlockContext<'_>) -> bool

Validate a proposed block before voting.

Source

fn validate_tx(&self, _tx: &[u8]) -> bool

Validate a single transaction for mempool admission.

Source

fn begin_block(&self, _ctx: &BlockContext<'_>) -> Result<()>

Called at the beginning of block execution (during commit).

Source

fn deliver_tx(&self, _tx: &[u8]) -> Result<()>

Called for each transaction in the block payload (during commit).

Source

fn end_block(&self, _ctx: &BlockContext<'_>) -> Result<EndBlockResponse>

Called after all transactions in the block are delivered (during commit). Return EndBlockResponse with validator_updates to trigger an epoch transition.

Source

fn on_evidence(&self, _proof: &EquivocationProof) -> Result<()>

Called when equivocation (double-voting) is detected. The application can use this to implement slashing.

Source

fn query(&self, _path: &str, _data: &[u8]) -> Result<Vec<u8>>

Query application state (returns opaque bytes).

Implementors§