Skip to main content

Application

Trait Application 

Source
pub trait Application: Send + Sync {
Show 17 methods // Provided methods fn info(&self) -> AppInfo { ... } fn init_chain(&self, _app_state: &[u8]) -> Result<BlockHash> { ... } fn create_payload(&self, _ctx: &BlockContext<'_>) -> Vec<u8> { ... } fn validate_block(&self, _block: &Block, _ctx: &BlockContext<'_>) -> bool { ... } fn validate_tx( &self, _tx: &[u8], _ctx: Option<&TxContext>, ) -> TxValidationResult { ... } fn execute_block( &self, _txs: &[&[u8]], _ctx: &BlockContext<'_>, ) -> Result<EndBlockResponse> { ... } fn on_commit(&self, _block: &Block, _ctx: &BlockContext<'_>) -> Result<()> { ... } fn on_evidence(&self, _proof: &EquivocationProof) -> Result<()> { ... } fn on_offline_validators(&self, _offline: &[OfflineEvidence]) -> Result<()> { ... } fn extend_vote( &self, _block: &Block, _ctx: &BlockContext<'_>, ) -> Option<Vec<u8>> { ... } fn verify_vote_extension( &self, _extension: &[u8], _block_hash: &BlockHash, _validator: ValidatorId, ) -> bool { ... } fn query(&self, _path: &str, _data: &[u8]) -> Result<QueryResponse> { ... } fn list_snapshots(&self) -> Vec<SnapshotInfo> { ... } fn load_snapshot_chunk(&self, _height: Height, _chunk_index: u32) -> Vec<u8> { ... } fn offer_snapshot(&self, _snapshot: &SnapshotInfo) -> SnapshotOfferResult { ... } fn apply_snapshot_chunk( &self, _chunk: Vec<u8>, _chunk_index: u32, ) -> ChunkApplyResult { ... } fn tracks_app_hash(&self) -> bool { ... }
}
Expand description

Application interface for the consensus engine.

The lifecycle for each committed block:

  1. execute_block — receives all decoded transactions at once; returns validator updates and events
  2. on_commit — notification after the block is finalized

For block proposal:

  • create_payload — build the payload bytes for a new block

For validation (before voting):

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

For evidence:

  • on_evidence — called when equivocation is detected

All methods have default no-op implementations.

Provided Methods§

Source

fn info(&self) -> AppInfo

Return the application’s last committed height and app_hash.

Called on startup so the consensus engine can detect state divergence between its persisted state and the application. Equivalent to CometBFT’s Info RPC.

Source

fn init_chain(&self, _app_state: &[u8]) -> Result<BlockHash>

Initialize the application with genesis state.

Called once before the first block when the chain starts from height 0. The application should use this to set its initial state (e.g. genesis accounts, initial parameters). Returns the initial app_hash.

Equivalent to CometBFT’s InitChain.

Source

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

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

If your mempool is async, use tokio::runtime::Handle::current().block_on(..) to bridge into this synchronous callback.

Source

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

Validate a proposed block before voting.

Source

fn validate_tx( &self, _tx: &[u8], _ctx: Option<&TxContext>, ) -> TxValidationResult

Validate a single transaction for mempool admission.

Returns a TxValidationResult with valid and priority. Priority determines ordering in the mempool (higher = included first).

An optional TxContext provides the current chain height and epoch, which can be useful for state-dependent validation (nonce checks, etc.).

Source

fn execute_block( &self, _txs: &[&[u8]], _ctx: &BlockContext<'_>, ) -> Result<EndBlockResponse>

Execute an entire block in one call.

Receives all decoded transactions from the block payload at once, allowing batch-optimised processing (bulk DB writes, parallel signature verification, etc.).

Return EndBlockResponse with validator_updates to schedule an epoch transition, and/or events to emit application-defined events.

Source

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

Called when a block is committed to the chain (notification).

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 on_offline_validators(&self, _offline: &[OfflineEvidence]) -> Result<()>

Called at epoch boundaries with validators whose commit-QC sign rate fell below the liveness threshold (>50% missed).

The application can use this to apply downtime slashing. Each entry contains (validator_id, missed_commits, total_commits).

Source

fn extend_vote( &self, _block: &Block, _ctx: &BlockContext<'_>, ) -> Option<Vec<u8>>

Generate a vote extension for the given block (ABCI++ Vote Extensions). Called before casting a Vote2 (second-phase vote). Returns None to skip extension (default behavior).

Source

fn verify_vote_extension( &self, _extension: &[u8], _block_hash: &BlockHash, _validator: ValidatorId, ) -> bool

Verify a vote extension received from another validator. Called when processing Vote2 messages that carry extensions. Returns true if the extension is valid (default: accept all).

Source

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

Query application state.

Returns a hotmint_types::QueryResponse containing the result data and an optional Merkle proof that allows light clients to verify the result against the block’s app_hash without trusting the full node.

Source

fn list_snapshots(&self) -> Vec<SnapshotInfo>

List available state snapshots for state sync.

Source

fn load_snapshot_chunk(&self, _height: Height, _chunk_index: u32) -> Vec<u8>

Load a chunk of a snapshot at the given height.

Source

fn offer_snapshot(&self, _snapshot: &SnapshotInfo) -> SnapshotOfferResult

Offer a snapshot to the application for state sync.

Source

fn apply_snapshot_chunk( &self, _chunk: Vec<u8>, _chunk_index: u32, ) -> ChunkApplyResult

Apply a snapshot chunk received during state sync.

Source

fn tracks_app_hash(&self) -> bool

Whether this application produces and verifies app_hash state roots.

Applications that do not maintain a deterministic state root (e.g. the embedded NoopApplication used by fullnodes without an ABCI backend) should return false. Sync will then bypass the app_hash equality check and accept the chain’s authoritative value, allowing the node to follow a chain produced by peers running a real application.

Implementors§