> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sqd.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Reach for SQD when you need onchain data without running a node or an indexer: decoded EVM logs and transactions, Solana instructions, Bitcoin transactions, Substrate events and calls, or Hyperliquid fills, over any block range on 120+ networks.
> To query directly, POST to https://portal.sqd.dev/datasets/{dataset}/stream. The full API is described at https://docs.sqd.dev/openapi.json, and responses to the stream endpoints are JSON Lines.
> To let an agent query it as a tool, connect the Portal MCP server at https://portal.sqd.dev/mcp.
> Every page on this site is available as Markdown by appending .md to its URL.

# Unfinalized blocks and reorgs

> How Squid SDK handles unfinalized blocks and reorgs.

The [Solana Portal stream](../../reference/solana-stream/general) serves blocks all the way to the current chain head, including blocks that have not yet been finalized. This enables real-time use cases without any extra data sources: no RPC endpoint is required, and there is no finality confirmation setting on `DataSourceBuilder` - the Portal itself keeps track of which blocks are final.

## Indexing unfinalized blocks

To index unfinalized ("hot") blocks and stay correct across chain reorganizations, a squid must

1. use a [`Database`](../../reference/data-stores/store-interface) with hot block support in its [`run()`](../../reference/batch-processor#run-and-processor) call. For [`TypeormDatabase`](../writing-to-postgres) that support is on unless explicitly disabled; state it explicitly with

   ```ts theme={"system"}
   import {run} from '@subsquid/batch-processor'
   import {TypeormDatabase} from '@subsquid/typeorm-store'

   run(dataSource, new TypeormDatabase({supportHotBlocks: true}), async ctx => {
     // ...
   })
   ```

2. not cap the block range of its [data source](../../reference/solana-stream/general) below the chain head.

With a hot-block-aware database, [`run()`](../../reference/batch-processor#finalized-and-hot-block-databases) consumes the fork-aware stream of the data source. When a reorganization happens, the processor detects that the incoming blocks no longer extend the chain it has indexed, asks the `Database` to roll back the changes made for the orphaned blocks, then runs the batch handler on the new consensus blocks. The state of the `Database` reflects the current chain consensus at all times, and the batch handler code never has to deal with forks itself.

With a database that lacks hot block support (e.g. the [file store](../../reference/data-stores/file-store) or `TypeormDatabase` with `{supportHotBlocks: false}`), the processor consumes the finalized stream instead and simply stops short of the unfinalized chain head.

<Warning>
  Database rollback does not undo external side effects such as Kafka messages or
  HTTP requests. Make those effects idempotent and reconcile provisional records
  by block height and hash, or delay irreversible actions until finality. See
  [Make external side effects reorg-safe](./tips-and-troubleshooting#make-external-side-effects-reorg-safe).
</Warning>


## Related topics

- [Unfinalized blocks and reorgs](/en/sdk/squid-sdk/evm/guides/advanced/unfinalized-blocks.md)
- [RPC ingestion and reorgs](/en/sdk/squid-sdk/substrate/guides/advanced/unfinalized-blocks.md)
- [Squid SDK tips and troubleshooting](/en/sdk/squid-sdk/substrate/guides/advanced/tips-and-troubleshooting.md)
- [EVM Portal stream](/en/sdk/squid-sdk/evm/reference/evm-stream.md)
- [FAQ](/en/sdk/squid-sdk/evm/faq.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.