feat(toolkit): keep transaction results in lite snapshot
What does this PR do?
db lite -o split -t snapshot now copies the transactionRetStore entries of the retained blocks into the snapshot, together with the blocks and transactions it already copies.
- Entries are read from the checkpoint first, the same way as blocks.
- Empty blocks have no entry and are skipped.
engine.propertiesoftransactionRetStoreis copied as well.plugins/README.mdstates what a snapshot contains.
No new option is added.
Why are these changes required?
A lite snapshot held the latest 65,536 blocks without their transaction results, so a lite node started from it could not serve receipts or logs for any of these blocks: eth_getLogs and eth_getBlockReceipts returned 4444, and eth_getTransactionReceipt returned null.
This PR has been tested by:
- Unit Tests:
DbLiteTestwrites transaction results into the source database before splitting, and asserts that the snapshot holds exactly those of the retained blocks. All fiveDbLite*tests pass on JDK 8 / x86_64 (LevelDB and RocksDB); the three RocksDB ones also pass on JDK 17 / arm64. - Manual Testing on mainnet: split a snapshot from a mainnet lite node (LevelDB, head 82,859,896) with the default window and started a lite node from it.
- The snapshot holds 65,536 transaction results (1.4 GiB), one per block of the window, all byte-identical to the source.
eth_getBlockReceiptsreturns one receipt per transaction at the lowest block of the window (237), the middle (328) and the head (460); the block below the window returns4444.eth_getTransactionReceiptreturns the receipt of a transaction in the lowest block;eth_getLogsover the first 100 blocks returns 5,228 logs.
- Manual Testing on Nile: split a snapshot from a Nile lite node (LevelDB, head 68,820,767) and started a lite node from it. The source node had stopped persisting transaction results after block 68,249,810, so the window was widened to 1,000,000 blocks with
DbLite.setRecentBlks()to cover blocks both with and without them.- The snapshot holds 398,896 transaction results, the same count as the source in the window; none are outside the window, and all are byte-identical to the source.
eth_getBlockReceiptsreturns one receipt per transaction at the lowest block of the window, in the middle, and at the last block with source results; the block below the window returns4444.eth_getTransactionReceiptreturns the receipt of a transaction in the lowest block;eth_getLogsover the first 1,000 blocks returns 643 logs.
Follow up
- None
Extra details
- Size: on mainnet the transaction results of 65,536 blocks take about 1.4 GiB, about 2% of the snapshot.
mergeis unaffected: it already handlestransactionRetStoreby block number.- Transaction results are copied as far as the source node has them. If the source ran with
transHistory.switch = offfor part of the window, the gap stays in the snapshot. Results the source never persisted cannot be recovered from its database; the only way to fill a gap is to sync again from an earlier snapshot with the switch on. Both points are documented inplugins/README.md; no recovery is implemented in Toolkit.
Summary by cubic
Lite snapshots created with db lite -o split -t snapshot now include the transaction results of the retained blocks, so a lite node started from a snapshot can serve receipts and logs for those blocks.
- Copies each block's
transactionRetStoreentry from the checkpoint alongside blocks and transactions; empty blocks (no entry) are skipped. - Copies
engine.propertiesfortransactionRetStoreand updatesplugins/README.mdto describe snapshot contents, including the gaps left whenstorage.transHistory.switch = off.