Skip to content

feat(stages): implement RocksDB unwind for index history stages#21066

Closed
yongkangc wants to merge 1 commit intoyk/rocksdb-stage-utilsfrom
yk/rocksdb-index-history-stages
Closed

feat(stages): implement RocksDB unwind for index history stages#21066
yongkangc wants to merge 1 commit intoyk/rocksdb-stage-utilsfrom
yk/rocksdb-index-history-stages

Conversation

@yongkangc
Copy link
Member

@yongkangc yongkangc commented Jan 14, 2026

Summary
RocksDB unwind support for index history stages.

Changes

  • Add RocksDB unwind for AccountsHistory stage
  • Add RocksDB unwind for StoragesHistory stage

Testing
Unwind operations verified.


PR Stack

main
  ↑
#21063 (rocksdb-either-reader)
  ↑
#21065 (rocksdb-stage-utils)
  ↑
#21066 (rocksdb-index-history-stages) ◀ you are here
  ↑
#21068 (rocksdb-init-txlookup)
  ↑
#21069 (rocksdb-cli-testutils)
  ↑
#21070 (rocksdb-cli)
  ↑
#21071 (rocksdb-docs)

@yongkangc yongkangc added the A-rocksdb Related to rocksdb integration label Jan 14, 2026
@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Jan 14, 2026
@yongkangc yongkangc force-pushed the yk/rocksdb-index-history-stages branch from 42452c2 to 071cd7b Compare January 14, 2026 20:27
@joshieDo joshieDo force-pushed the joshie/par-save-blocks-rocksdb branch 2 times, most recently from fff917c to d8a600c Compare January 14, 2026 21:38
@yongkangc yongkangc force-pushed the yk/rocksdb-index-history-stages branch 2 times, most recently from 8910828 to 126621c Compare January 15, 2026 10:12
@yongkangc yongkangc changed the base branch from joshie/par-save-blocks-rocksdb to yk/rocksdb-stage-utils January 15, 2026 11:18
Copy link
Member

@gakonst gakonst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: PR #21066

CI Status

  • fmt, docs, unit tests failing

Changes Summary

Implements RocksDB unwind for AccountsHistory and StoragesHistory stages.

Review Notes

✅ Good

  • Uses EitherWriter pattern consistently with execution path
  • Proper grouping of changesets by address before unwinding - smart optimization to only unwind once per address using the LOWEST block number
  • Good test coverage with dedicated rocksdb_stage_tests module

🟡 Suggestions

  1. Unwind correctness: The unwind logic groups by address and finds minimum block:

    account_keys.entry(account.address)
        .and_modify(|min_bn| *min_bn = (*min_bn).min(block_number))
        .or_insert(block_number);

    This is correct - we only need to unwind once per address from the lowest affected block.

  2. Memory consideration: collect::<Result<Vec<_>, _>>() loads all changesets into memory. For large unwinds, consider processing in batches or using the cursor directly.

  3. Comment removal: The old comment // from HistoryIndex higher than that number. was removed but the new code should have equivalent documentation explaining the unwind strategy.

Dependencies

Depends on #21063, #21064, #21065 - these must pass CI first.


Review by @tempo_ai

@yongkangc yongkangc force-pushed the yk/rocksdb-stage-utils branch from fc776db to 057d87f Compare January 16, 2026 08:36
@yongkangc yongkangc force-pushed the yk/rocksdb-index-history-stages branch from 126621c to 968c76f Compare January 16, 2026 08:36
Add RocksDB unwind support for IndexAccountHistory and IndexStorageHistory stages:
- Create RocksDB batch during unwind when storage settings enabled
- Use EitherWriter for history shard operations
- Register batches with pending_batches for atomic commit
@yongkangc
Copy link
Member Author

Superseded by #21120 (combined with #21065)

@yongkangc yongkangc closed this Jan 16, 2026
@github-project-automation github-project-automation bot moved this from Backlog to Done in Reth Tracker Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rocksdb Related to rocksdb integration

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants