Skip to content

feat(builder): incremental trie cache optimization for flashblocks state root#163

Merged
louisliu2048 merged 4 commits intomainfrom
feature/incremental-trie-cache
Mar 10, 2026
Merged

feat(builder): incremental trie cache optimization for flashblocks state root#163
louisliu2048 merged 4 commits intomainfrom
feature/incremental-trie-cache

Conversation

@Vui-Chee
Copy link
Contributor

Summary

Port of flashbots/op-rbuilder#385 — incremental trie cache optimization for flashblocks state root calculation.

  • Add prev_trie_updates: Option<Arc<TrieUpdates>> field to FlashblocksState to hold cached trie nodes across flashblocks
  • On the first flashblock, compute the state root normally via state_root_with_updates
  • On subsequent flashblocks, reuse the cached TrieUpdates via state_root_from_nodes_with_updates, skipping the full DB trie traversal
  • Cache is propagated through FlashblocksState::next() and updated after each state root calculation

Benchmark (from the upstream report) shows ~2.4–2.5x speedup in state root calculation across sequential flashblocks.

Running the benchmark

cargo bench -p xlayer-builder --bench bench_flashblocks_state_root

🤖 Generated with Claude Code

…ks state root

Port flashbots/op-rbuilder#385 - caches TrieUpdates after each flashblock
state root calculation so subsequent flashblocks reuse cached trie nodes
instead of recomputing from the database each time, achieving ~2.4-2.5x
speedup in state root calculation.

Changes:
- Add `prev_trie_updates: Option<Arc<TrieUpdates>>` field to FlashblocksState
- Use `state_root_from_nodes_with_updates` with cached trie on subsequent flashblocks
- Cache trie updates after each calculation and propagate to next flashblock
- Add criterion benchmark: bench_flashblocks_state_root
- Add reth-trie-db and criterion workspace dependencies

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Vui-Chee Vui-Chee requested a review from cliff0412 February 28, 2026 12:53
* main:
  fix: update testcontainers to v0.27.0 to remediate CVE-2025-62518 (#164)
@Vui-Chee
Copy link
Contributor Author

Vui-Chee commented Mar 2, 2026

Maybe TPS is not improve on testnet dataset. cc @cliff0412

WITHOUT cache ======================================================== [TPS log] StartBlock Num: 18696394, NewBlockNum: 18696409, totalTxCount:72641 [Summary] Average BTPS: 4470.82, Max TPS: 4505.51, Min TPS: 1512.50, Time Last: 16s ======================================================== ======================================================== [TPS log] StartBlock Num: 18696394, NewBlockNum: 18696414, totalTxCount:93937 [Summary] Average BTPS: 4409.64, Max TPS: 4505.51, Min TPS: 1512.50, Time Last: 21s ========================================================

WITH cache ======================================================== [TPS log] StartBlock Num: 18696450, NewBlockNum: 18696495, totalTxCount:195854 [Summary] Average BTPS: 4218.62, Max TPS: 4519.30, Min TPS: 1705.02, Time Last: 46s ======================================================== ======================================================== [TPS log] StartBlock Num: 18696450, NewBlockNum: 18696500, totalTxCount:216390 [Summary] Average BTPS: 4204.20, Max TPS: 4519.30, Min TPS: 1705.02, Time Last: 51s ======================================================== ======================================================== [TPS log] StartBlock Num: 18696450, NewBlockNum: 18696505, totalTxCount:236926 [Summary] Average BTPS: 4192.30, Max TPS: 4519.30, Min TPS: 1705.02, Time Last: 56s ======================================================== ======================================================== [TPS log] StartBlock Num: 18696450, NewBlockNum: 18696510, totalTxCount:257462 [Summary] Average BTPS: 4182.11, Max TPS: 4519.30, Min TPS: 1705.02, Time Last: 61s ======================================================== ======================================================== [TPS log] StartBlock Num: 18696450, NewBlockNum: 18696515, totalTxCount:280281 [Summary] Average BTPS: 4207.66, Max TPS: 4519.30, Min TPS: 1705.02, Time Last: 66s ======================================================== ======================================================== [TPS log] StartBlock Num: 18696450, NewBlockNum: 18696520, totalTxCount:300816 [Summary] Average BTPS: 4198.11, Max TPS: 4519.30, Min TPS: 1705.02, Time Last: 71s ========================================================

@cliff0412
Copy link

cliff0412 commented Mar 5, 2026

can port this also. they rebase with other small improvements
flashbots/op-rbuilder#427 (comment)

@Vui-Chee
Copy link
Contributor Author

Vui-Chee commented Mar 6, 2026

I will add on the improvements next week.

Vui-Chee added 2 commits March 9, 2026 09:39
* main:
  Feat(chainspec): adding xlayer-devnet chainspec (#167)
  chore(builder): flatten flashblocks builder, remove unnecessary trait interfaces (#172)
  rpc: remove unnecessary trait bounds and dependencies from XlayerRpcExtApiServer impl (#171)
  fix fmt in bin/tools/gen_genesis.rs (#170)
  fix(builder): Resolve bugs on upstream flashblocks timing scheduler (#169)
  Feat(tools): Add a tool to generate a custom genesis file based on a template and existing chain data (#159)
  feat(flashblocks): Add flashblocks sequence persistence logic on RPC and sequence replay flashblock builder (#162)
  chore(builder): remove unused custom-engine-api feature flag in tests (#168)
  fix: p2p test hang due to hang on port (#165)
Align with upstream flashbots/op-rbuilder#427:
- Wrap trie_output in Arc once upfront instead of cloning then wrapping
- Reuse same Arc allocation for both executed block and fb_state cache
- Remove trie cache benchmark and related dev dependencies (criterion, reth-trie-db)
Copy link

@cliff0412 cliff0412 left a comment

Choose a reason for hiding this comment

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

LGTM

@louisliu2048 louisliu2048 merged commit 17d908d into main Mar 10, 2026
Vui-Chee added a commit that referenced this pull request Mar 13, 2026
* main: (25 commits)
  fix: bump quinn-proto to 0.11.14 to patch CVE-2026-31812 DoS vuln (#183)
  pre-job authorization (#193)
  fix: trigger review skill failed to ack (#192)
  feat: trigger skill review separately (#191)
  feat: add Claude skills and CLAUDE.md for AI-assisted development (#190)
  rename ext (#185)
  supply workflow for claude (#184)
  feat(builder): incremental trie cache optimization for flashblocks state root (#163)
  chore(flashblocks-rpc): migrate op-reth flashblocks into xlayer-reth (#175)
  Feat(chainspec): adding xlayer-devnet chainspec (#167)
  chore(builder): flatten flashblocks builder, remove unnecessary trait interfaces (#172)
  rpc: remove unnecessary trait bounds and dependencies from XlayerRpcExtApiServer impl (#171)
  fix fmt in bin/tools/gen_genesis.rs (#170)
  fix(builder): Resolve bugs on upstream flashblocks timing scheduler (#169)
  Feat(tools): Add a tool to generate a custom genesis file based on a template and existing chain data (#159)
  feat(flashblocks): Add flashblocks sequence persistence logic on RPC and sequence replay flashblock builder (#162)
  chore(builder): remove unused custom-engine-api feature flag in tests (#168)
  fix: p2p test hang due to hang on port (#165)
  fix: update testcontainers to v0.27.0 to remediate CVE-2025-62518 (#164)
  chore(builder): further clean up builder crate (#161)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants