Repository navigation
Description
When a node takes its scheduled state-sync snapshot, I want it to keep committing blocks and answering reads, so it does not fall 20 minutes behind the chain and out of service every time.
What happens
- The snapshot runs inside the block commit.
Commitholds the block processor's lock for the whole call and callssnapshotDB, which runspg_dumpto the end before it returns. The node commits no block until the dump is done. - Every read that needs the node's status waits with it.
user.call,user.healthand/api/v1/healthgo throughStatus, which reads the network parameters under the block processor's read lock. snapshotDBalready handspg_dumpits own database snapshot, so the dump does not need the lock to see a consistent state.
On the mainnet sentry that makes the snapshots, on 24 Nov 2026 (UTC):
- 04:32:41.706: committed block 3227967.
- 04:32:42.767:
pg_dumpstarted for block 3227968. - 04:53:39.718:
pg_dumpfinished, 212 chunks and 3.38 GB. - 04:53:39.856: four RPC handlers that the dump had blocked could finally answer, and each failed with
Write error: http: Handler timeout, because their callers had already been sent an RPC timeout error after 10 s. - 04:53:39.865: committed block 3227968, 20 min 58 s after the block before it.
- 04:54:51.403: back at the tip, after block syncing 3227969 to 3228145 in 10.5 s.
The leader and the other sentry committed every block in that window, and the mainnet gateway returned no 5xx. The same happens on every snapshot, once every 14,400 blocks. The snapshots at block 3199168 (17 Nov, 03:59 to 04:20 UTC) and block 3213568 (21 Nov, 21:20 to 21:41 UTC) took the same 21 minutes. Since 6 Nov the node's stall alert has fired at ten snapshots, each time reporting a height less than 80 blocks below the snapshot's.
Committakes the lock and callssnapshotDB: https://github.com/trufnetwork/kwil-db/blob/83d68e65c71b280b0a0b983155a3c320db18e421/node/block_processor/processor.go#L688-L690 and https://github.com/trufnetwork/kwil-db/blob/83d68e65c71b280b0a0b983155a3c320db18e421/node/block_processor/processor.go#L744-L747snapshotDBrunspg_dumpon its own database snapshot: https://github.com/trufnetwork/kwil-db/blob/83d68e65c71b280b0a0b983155a3c320db18e421/node/block_processor/processor.go#L784-L808Statuswaits on the lock: https://github.com/trufnetwork/kwil-db/blob/83d68e65c71b280b0a0b983155a3c320db18e421/node/consensus/engine.go#L503-L504 and https://github.com/trufnetwork/kwil-db/blob/83d68e65c71b280b0a0b983155a3c320db18e421/node/block_processor/processor.go#L957-L959- The snapshot settings in the deployment template:
node/deployments/infra/config/node/kwild-config.tmpl
Lines 97 to 100 in 19d2493
[snapshots] enable = {{ default false .Snapshots.Enable }} recurring_height = {{ default 14400 .Snapshots.RecurringHeight }} max_snapshots = {{ default 3 .Snapshots.MaxSnapshots }}
Scope
- Take the snapshot off the commit path: keep the database snapshot that
snapshotDBopens, release the lock, and runpg_dumpin the background, one dump at a time. - Until that ships, weigh moving the snapshots to a node that serves no reads, or a larger
recurring_height, against the catch-up length that a snapshot's age sets. - Answering
Statuswithout the lock is covered by the related read-lock issue. - The change itself goes in trufnetwork/kwil-db.
Acceptance criteria
- On a node with mainnet-sized data and snapshots on, the snapshot block commits in its usual time, and the next blocks commit while
pg_dumpruns. - During the dump,
user.healthandGET /api/v1/healthanswer in their usual time. - A node restored from the new snapshot by state sync reaches the same app hash as one restored from a snapshot made today.
Activity