Indexing unfinalized blocks
Starting with the ArrowSquid release, Subsquid SDK supports indexing blocks before they are finalized, enabling real-time use cases. To take advantage of this feature, a squid processor must
- have a node RPC endpoint as one of its data sources and
- use a
Database
with hot blocks support (e.g.TypeormDatabase
) in itsprocessor.run()
call, and - (EVM only) not set the
useArchiveOnly(true)
setting.
With this, the processor will consider some blocks to be "hot":
EvmBatchProcessor
: all blocks with fewer confirmations than the number set by thesetFinalityConfirmations()
settingSubstrateBatchProcessor
: all blocks above the latest finalized block provided by thechain_getFinalizedHead()
RPC method
The processor will periodically (interval setting for EVM, Substrate) poll the RPC endpoint for changes in consensus. When the consensus changes, it will re-run the batch handler with the new consensus data and ask the Database
to adjust its state. The Database
then must roll back the changes made due to orphaned blocks and apply the new changes. With this, the state of the Database
reflects the current blockchain consensus at all times.