Hooks & Lifecycle
Bitplanet's block lifecycle includes standard BitSDK hooks (BeginBlock, EndBlock) and custom EVM hooks (PostTxProcessing) that execute at specific points in block processing. This page explains when these hooks run and what operations they perform.
Block Lifecycle Overview
Each block follows this execution flow:
BeginBlock (all modules in order)
Transaction Execution
Validate transaction
Execute message handlers
PostTxProcessing hooks (after each EVM tx)
EndBlock (all modules in order)
Commit (state finalized)
BeginBlock Hooks
Module Execution Order
BeginBlock hooks execute in this sequence:
mint
ibc
erc20
feemarket
evm
brahma
precompile
Why Order Matters:
Mint must run first (creates new tokens for distribution)
EVM must run after feemarket (gas price updates)
Brahma must run after EVM (queries EVM state for market caps)
Feemarket runs last in EndBlock (updates base fee)
x/brahma BeginBlock
The primary custom hook in Bitplanet's BeginBlock.
Purpose: Distributes inflation rewards to AI creators, AI Apps, and contributors.
Operations:
Query distribution module balance
Calculate siphon amount
Transfer tokens to brahma module
Query AI market caps from EVM contracts
Distribute proportionally to stakeholders
Update claimable reward balances
Performance: O(n) where n = number of AIs (limited by max_ais_for_rewards parameter)
For detailed technical implementation, see Inflation Mechanism and Reward Distribution.
EndBlock Hooks
Module Execution Order
EndBlock hooks execute in this sequence:
gov
staking
auth
bank
evm
erc20
feemarket
Key Operations:
gov: Tally proposal votes, execute passed proposals
staking: Update validator set, process unbonding
feemarket: Update EIP-1559 base fee (must run last)
Note: Most Bitplanet-specific logic runs in BeginBlock. EndBlock primarily handles standard BitSDK operations.
PostTxProcessing Hooks
Custom hooks that execute after each EVM transaction completes.
Hook Registration
Hooks are registered in reverse order of execution:
x/precompile PostTxProcessing
Purpose: Bridge EVM events to BitSDK operations.
Flow:
EVM Transaction → Receipt with Logs
PostTxProcessing Hook
Check logs for precompile addresses
Match event signatures
Execute BitSDK operations
Supported Events:
CoreGrantApplication: Creates governance proposal for core grant - see Core Tokens
OreRequest: Processes contribution tensors, mints cores - see AI Tensor Matrix
ContributionTypes: Updates contribution type parameters
See x/precompile Module - Event Processing for implementation details.
x/brahma PostTxProcessing
Purpose: Process reward claim events from EVM contracts.
Operation:
Listens for
BplCoinClaimedeventsValidates claim data
Transfers rewards to claimant
For detailed claiming process, see Reward Distribution.
Event Emission
Event Types
Bitplanet modules emit events for indexing and external monitoring:
x/brahma Events:
x/precompile Events:
Standard Cosmos Events:
message: Module and actiontransfer: Token movementsdelegate: Staking operations
Event Structure
Events include typed attributes:
Use Cases:
Block explorers index events for queries
AI Apps subscribe to specific event types
Analytics track on-chain activity
Module Dependencies
BeginBlock Dependencies
mint (creates tokens)
brahma (distributes tokens)
evm (queries contract state)
Brahma depends on mint running first and queries EVM state for market caps.
PostTxProcessing Dependencies
EVM transaction completes
precompile hook (processes events)
brahma hook (processes claims)
Both hooks depend on EVM transaction execution completing successfully.
Performance Considerations
BeginBlock Limits
Governance parameters prevent unbounded processing:
max_ais_for_rewards
500
Limits AIs processed per block
max_ai_block_heights
1,000
Limits historical data processed
max_tensor_rows_per_block
1,000
Limits contributor rows processed
Why: Ensures BeginBlock completes within block time (~6 seconds).
For how these parameters affect reward calculations, see Inflation Mechanism.
PostTxProcessing Overhead
Each EVM transaction triggers hooks:
Iterates through transaction logs
Checks for registered precompile addresses
Minimal overhead if no matching events
Optimization: Hooks exit early if no relevant events detected.
Hook Execution Guarantees
Atomicity
BeginBlock/EndBlock operations are atomic:
All operations succeed or entire block fails
State changes committed together
No partial execution
Determinism
All hooks must be deterministic:
Same inputs → same outputs
No randomness or external dependencies
Consistent ordering across validators
Example: Brahma uses rolling averages stored in state (not memory) to ensure deterministic reward calculations.
Last updated