Block Best Practices
Recommendations
Fetching
Use Batch Requests
Use getBlocks() to fetch multiple blocks in a single request, reducing network overhead.
Cache Blocks
Blocks are immutable once confirmed, making them safe to cache indefinitely.
Prefetch Transactions
Enable prefetchTxs to include transaction data in the response when required, avoiding additional queries.
Handle Missing Blocks
Queries for future or non-existent block numbers will fail; validate block heights before fetching.
Indexers
Use Threading
Process blocks in parallel across multiple threads to maximize indexer performance.
Witnesses
Prioritize trusted witnesses
Rely on witnesses from known validators when verifying block finality.
Wait for finality
For critical transactions, wait until sufficient witnesses have attested to the block before considering it final.
Handle missing witnesses
Recently produced blocks may not yet have witnesses; implement retry logic for pending blocks.
Paginate large result sets
Use the limit and page parameters when querying blocks with numerous witnesses.
Cache witness data
Once a block is confirmed, its witnesses are immutable and safe to cache.
Reorganization
Wait for Sufficient Confirmations
Higher confirmation counts significantly reduce reorganization risk for critical transactions.
Monitor Critical Blocks
Track blocks containing important transactions and verify their validity regularly.
Implement Graceful Recovery
Design applications to recover state rather than fail when reorganizations occur.
Invalidate Caches on Detection
Clear cached block and transaction data when a reorganization is detected to prevent stale reads.
Notify Affected Users
Inform users promptly when their transactions are impacted by a reorganization.
Gas Parameters
Cache Parameters
Gas parameters do not change frequently. Rely on the built-in caching mechanism and avoid excessive calls to gasParameters().
Use Medium Priority
The medium fee rate provides a good balance between confirmation speed and cost for most transactions.
Monitor for Large Transactions
Check current fee rates before executing expensive operations to avoid unexpected costs during periods of high network congestion.
Include Buffer
Add a 10-20% buffer to gas estimates to account for fee fluctuations between estimation and broadcast.
Batch During Low Fees
Schedule UTXO consolidation and batch operations during periods of low network fees to minimize costs.