Skip to content

Make PruneExecutionDB not depend on consensusDB#4217

Merged
tsahee merged 24 commits intomasterfrom
braga/no-consensus-for-prune
Feb 28, 2026
Merged

Make PruneExecutionDB not depend on consensusDB#4217
tsahee merged 24 commits intomasterfrom
braga/no-consensus-for-prune

Conversation

@bragaigor
Copy link
Copy Markdown
Contributor

Refactor PruneExecutionDB, more specifically findImportantRoots so it does not depend on consensusDB, but only on executionDB. The former PruneExecutionDB used to depend on consensusDB for 2 things:

  • latest validated block
    • used in Prune mode "validator"
    • fetched using staker.ReadLastValidatedInfo
  • latest finalized block
    • used in Prune mode "minimal"
    • fetched using MEL batch count + batch metadata

For the replacements we use:

  • latest validated block:
    • use executionDB to store such validated block using key LastValidatedBlockHashKey
    • add a call to executionDB.Put(validatedBlockHashKey, ... to SetFinalityData to store latest validated block
  • latest finalized block
    • no new logic was added for this
    • using existing rawdb.ReadFinalizedBlockHash and rawdb.ReadHeaderNumber to get finalized block number and hash

Closes NIT-4266

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 0% with 70 lines in your changes missing coverage. Please review.
✅ Project coverage is 33.04%. Comparing base (68e4e17) to head (1e49a46).
⚠️ Report is 503 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4217      +/-   ##
==========================================
- Coverage   34.96%   33.04%   -1.92%     
==========================================
  Files         483      484       +1     
  Lines       57556    57664     +108     
==========================================
- Hits        20125    19057    -1068     
- Misses      33868    35290    +1422     
+ Partials     3563     3317     -246     

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 9, 2026

❌ 6 Tests Failed:

Tests completed Failed Passed Skipped
4152 6 4146 0
View the top 3 failed tests by shortest run time
TestNitroNodeVersionAlerter
Stack Traces | 0.280s run time
... [CONTENT TRUNCATED: Keeping last 20 lines]
INFO [02-06|19:26:36.222] Persisted trie from memory database      nodes=0   flushnodes=0 size=0.00B     flushsize=0.00B time=561ns        flushtime=0s gcnodes=0 gcsize=0.00B gctime=0s         livenodes=0    livesize=0.00B
INFO [02-06|19:26:36.222] Writing snapshot state to disk           root=80a283..4b0cae
INFO [02-06|19:26:36.222] Persisted trie from memory database      nodes=0   flushnodes=0 size=0.00B     flushsize=0.00B time=370ns        flushtime=0s gcnodes=0 gcsize=0.00B gctime=0s         livenodes=0    livesize=0.00B
INFO [02-06|19:26:36.222] Blockchain stopped
INFO [02-06|19:26:36.258] Gasprice oracle is ignoring threshold set threshold=2
INFO [02-06|19:26:36.260] Submitted contract creation              hash=0x66a5eba4c55ea7c9e0c95ca30c5730da6d7457039f8345704357197385b17e76 from=0x57Ff0F473737a1c161bfF9efDF016F7991585088 nonce=2   contract=0x871464604Ce05d630517695fE4446717506485B8 value=0
INFO [02-06|19:26:36.261] Starting work on payload                 id=0x03618c0901dac42b
INFO [02-06|19:26:36.262] Updated payload                          id=0x03618c0901dac42b number=3  hash=a99f8e..42c4b2 txs=1   withdrawals=0 gas=72844      fees=7.2844e-08     root=e87fd4..d3b00a elapsed="487.028µs"
INFO [02-06|19:26:36.263] Stopping work on payload                 id=0x03618c0901dac42b reason=delivery
INFO [02-06|19:26:36.263] Imported new potential chain segment     number=3  hash=a99f8e..42c4b2 blocks=1  txs=1   mgas=0.073  elapsed="951.712µs"  mgasps=76.540   triediffs=9.06KiB   triedirty=0.00B
INFO [02-06|19:26:36.264] Chain head was updated                   number=3  hash=a99f8e..42c4b2 root=e87fd4..d3b00a elapsed="236.161µs"
�[38;5;48;1myay!! we validated block 15 in 192.37ms�[0;0m
INFO [02-06|19:26:36.376] Deploying seq inbox bufferable
INFO [02-06|19:26:36.385] Submitted contract creation              hash=0x2de2774e30ebefd5c3fce7127bbbabee765b7e4911f73bd38f09fe468d554ed5 from=0x57Ff0F473737a1c161bfF9efDF016F7991585088 nonce=4   contract=0x68c55BbCAbb6EC7D623c420B6169CF277Fe040b5 value=0
INFO [02-06|19:26:36.385] Starting work on payload                 id=0x0329611569a4c859
INFO [02-06|19:26:36.386] Updated payload                          id=0x0329611569a4c859 number=5  hash=c947b5..14e7ad txs=1   withdrawals=0 gas=4,765,394  fees=4.765394e-06   root=02ca52..744bab elapsed="989.314µs"
INFO [02-06|19:26:36.387] Stopping work on payload                 id=0x0329611569a4c859 reason=delivery
INFO [02-06|19:26:36.388] Imported new potential chain segment     number=5  hash=c947b5..14e7ad blocks=1  txs=1   mgas=4.765  elapsed=1.515ms      mgasps=3143.572 triediffs=15.10KiB  triedirty=0.00B
INFO [02-06|19:26:36.389] Chain head was updated                   number=5  hash=c947b5..14e7ad root=02ca52..744bab elapsed="358.618µs"
--- FAIL: TestNitroNodeVersionAlerter (0.28s)
TestBlocksReExecutorCommitState
Stack Traces | 2.750s run time
... [CONTENT TRUNCATED: Keeping last 20 lines]
DEBUG[02-06|19:19:49.182] Served eth_getBlockByNumber              reqid=3556  duration="50.855µs"
DEBUG[02-06|19:19:49.182] Served eth_getBlockByNumber              reqid=342   duration="44.493µs"
TRACE[02-06|19:19:49.182] Handled RPC response                     reqid=1181  duration="1.864µs"
TRACE[02-06|19:19:49.182] Handled RPC response                     reqid=636   duration="1.382µs"
TRACE[02-06|19:19:49.182] Handled RPC response                     reqid=342   duration=732ns
TRACE[02-06|19:19:49.182] Handled RPC response                     reqid=3556  duration="1.463µs"
DEBUG[02-06|19:19:49.182] Served eth_getBlockByNumber              reqid=931   duration="36.378µs"
DEBUG[02-06|19:19:49.182] Served eth_getBlockByNumber              reqid=1469  duration="45.214µs"
TRACE[02-06|19:19:49.182] Handled RPC response                     reqid=931   duration="1.432µs"
TRACE[02-06|19:19:49.182] Handled RPC response                     reqid=1469  duration=792ns
DEBUG[02-06|19:19:49.182] Served eth_getBlockByNumber              reqid=3495  duration="54.912µs"
DEBUG[02-06|19:19:49.182] Served eth_getBlockByNumber              reqid=801   duration="36.387µs"
TRACE[02-06|19:19:49.182] Handled RPC response                     reqid=3495  duration="1.012µs"
TRACE[02-06|19:19:49.182] Handled RPC response                     reqid=801   duration=982ns
TRACE[02-06|19:19:49.183] P2P networking is spinning down
DEBUG[02-06|19:19:49.183] Served eth_getBlockByNumber              reqid=344   duration="59.961µs"
TRACE[02-06|19:19:49.183] Handled RPC response                     reqid=344   duration="1.282µs"
DEBUG[02-06|19:19:49.184] Finality not supported, not pushing finality data to execution
DEBUG[02-06|19:19:49.185] Finality not supported, not pushing finality data to execution
--- FAIL: TestBlocksReExecutorCommitState (2.75s)
TestVersion30
Stack Traces | 5.360s run time
... [CONTENT TRUNCATED: Keeping last 20 lines]
        github.com/offchainlabs/nitro/system_tests.testPrecompiles(0xc0b6fe9dc0, 0x1e, {0xc0b2a39db0, 0x6, 0x90000c044d0bbc8?})
        	/home/runner/work/nitro/nitro/system_tests/precompile_inclusion_test.go:94 +0x371
        github.com/offchainlabs/nitro/system_tests.TestVersion30(0xc0b6fe9dc0?)
        	/home/runner/work/nitro/nitro/system_tests/precompile_inclusion_test.go:67 +0x798
        testing.tRunner(0xc0b6fe9dc0, 0x3cfe6f8)
        	/opt/hostedtoolcache/go/1.25.6/x64/src/testing/testing.go:1934 +0xea
        created by testing.(*T).Run in goroutine 1
        	/opt/hostedtoolcache/go/1.25.6/x64/src/testing/testing.go:1997 +0x465
        
    precompile_inclusion_test.go:94: �[31;1m [] execution aborted (timeout = 5s) �[0;0m
INFO [02-06|19:27:02.997] Blockchain stopped
INFO [02-06|19:27:02.997] Stopping work on payload                 id=0x03be95cac2d0ba08 reason=delivery
INFO [02-06|19:27:02.998] Writing cached state to disk             block=1   hash=52f93d..539574 root=c02835..9ffaab
INFO [02-06|19:27:02.998] Persisted trie from memory database      nodes=20  flushnodes=0 size=3.26KiB   flushsize=0.00B time="142.396µs"  flushtime=0s gcnodes=0 gcsize=0.00B gctime="1.752µs"  livenodes=0    livesize=0.00B
INFO [02-06|19:27:02.998] Writing cached state to disk             block=1   hash=52f93d..539574 root=c02835..9ffaab
INFO [02-06|19:27:02.998] Persisted trie from memory database      nodes=0   flushnodes=0 size=0.00B     flushsize=0.00B time=962ns        flushtime=0s gcnodes=0 gcsize=0.00B gctime=0s         livenodes=0    livesize=0.00B
INFO [02-06|19:27:02.998] Writing snapshot state to disk           root=92585b..f227c9
INFO [02-06|19:27:02.998] Persisted trie from memory database      nodes=0   flushnodes=0 size=0.00B     flushsize=0.00B time=512ns        flushtime=0s gcnodes=0 gcsize=0.00B gctime=0s         livenodes=0    livesize=0.00B
INFO [02-06|19:27:02.998] Starting work on payload                 id=0x03a3c9c9038dbd4f
--- FAIL: TestVersion30 (5.36s)

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

@bragaigor bragaigor marked this pull request as ready for review January 9, 2026 15:32
Comment thread execution/gethexec/sync_monitor.go Outdated
Comment thread cmd/pruning/pruning.go
Comment thread execution/gethexec/sync_monitor.go Outdated
Comment thread system_tests/finality_data_test.go
Comment thread system_tests/pruning_test.go Outdated
Comment thread system_tests/pruning_test.go Outdated
Comment thread cmd/pruning/pruning.go Outdated
Comment thread system_tests/pruning_test.go
Refactor PruneExecutionDB, more specifically findImportantRoots
so it does not depend on consensusDB, but only on executionDB

Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
@bragaigor bragaigor force-pushed the braga/no-consensus-for-prune branch from a59d76b to 4965575 Compare January 15, 2026 15:58
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@diegoximenes diegoximenes left a comment

Choose a reason for hiding this comment

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

Almost there 🙂, just some test nitpicks

Comment thread system_tests/pruning_test.go Outdated
Comment thread system_tests/pruning_test.go Outdated
Comment thread system_tests/pruning_test.go Outdated
Comment on lines +315 to +318
// Create a safety buffer (+/- 2 blocks) around the expected prune point.
// Due to synchronization latency, the second node's state may vary slightly,
// making the exact availability of these boundary blocks non-deterministic.
if i >= checkUntilBlock-2 && i <= checkUntilBlock+2 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't fully understand this, but it is only a test so it is OK to have it here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah I'm fully 100% sure what causes these fluctuations but that's my best guess where sometimes blocks in the range [balanceShouldntExistUntilBlock-1, balanceShouldntExistUntilBlock+1] might or might not have been persisted to trieDB, so to be safe I did a +/-2 window.

Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
@bragaigor bragaigor assigned diegoximenes and unassigned bragaigor Feb 5, 2026
Comment thread system_tests/pruning_test.go
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
@bragaigor bragaigor assigned diegoximenes and unassigned bragaigor Feb 6, 2026
Copy link
Copy Markdown
Contributor

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

approving with comments

Comment thread cmd/pruning/pruning.go

validatorDB := rawdb.NewTable(consensusDB, storage.BlockValidatorPrefix)
lastValidated, err := staker.ReadLastValidatedInfo(validatorDB)
data, err := executionDB.Get(gethexec.ValidatedBlockHashKey)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wrap the error so the user will understand that "validator" prune mode cannot work for a node that has not been used as validator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(old behavior wouldn've been to just not try saving another block but I think it's better as you wrote it, especially since nodes that have a database before the change don't have that key in db even if they do work as validators)

@tsahee tsahee added this pull request to the merge queue Feb 28, 2026
Merged via the queue into master with commit d0abe6b Feb 28, 2026
40 of 41 checks passed
@tsahee tsahee deleted the braga/no-consensus-for-prune branch February 28, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants