Skip to content

check-commitment-hist-at-blk: Compute block commitment correctly + refactoring of commitment readers#19364

Open
antonis19 wants to merge 11 commits intomainfrom
fix-compute-commitment-integrity-check
Open

check-commitment-hist-at-blk: Compute block commitment correctly + refactoring of commitment readers#19364
antonis19 wants to merge 11 commits intomainfrom
fix-compute-commitment-integrity-check

Conversation

@antonis19
Copy link
Member

@antonis19 antonis19 commented Feb 20, 2026

This PR :

  1. Uses a SplitStateReader for the erigon snapshots check-commitment-hist-at-blk command, so that the state root for the block can be calculated correctly by reading branch data as of the beginning of the block and account and storage state data as of the end of block. The old behavior was that both plain state (accounts+storage) and commitment branch data were being read as of the end of the block, so the already updated MPT branches were being read instead of them being recomputed.
  2. Removes some duplicated commitment StateReader implementations.

WithHistory() bool
CheckDataAvailable(d kv.Domain, step kv.Step) error
Read(d kv.Domain, plainKey []byte, stepSize uint64) (enc []byte, step kv.Step, err error)
Clone() StateReader
Copy link
Member

Choose a reason for hiding this comment

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

Clone needs to accept a tx - the idea of Clone is to clone the reader but with a new fresh tx

Copy link
Member

Choose a reason for hiding this comment

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

To give you a bit more context: the reason Clone(tx) exists is to support parallel commitment trie in the backtester.

In order for the backtesterStateReader to work with parallel commitment it needs to spawn itself with many RoTx-es.

That is why in the trie we have:

if sdc.stateReader != nil {
	mainTtx.stateReader = sdc.stateReader.Clone(tx)
}

So that when we set the stateReader to be the backtestStateReader it will clone itself 16 times with 16 different RoTx-es for the para-trie experiments

Copy link
Member

@taratorio taratorio left a comment

Choose a reason for hiding this comment

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

@sudeepdino008
Copy link
Member

sudeepdino008 commented Feb 26, 2026

fyi, i tried this pr just now:

~/fix-compute-commitment-integrity-check$ ./build/bin/erigon seg check-commitment-hist-at-blk-range --datadir /erigon-data/sepolia_1 --from 3744100 --to 3744180
INFO[02-26|11:25:46.634] logging to file system                   log dir=/erigon-data/sepolia_1/logs file prefix=erigon log level=dbug json=false
INFO[02-26|11:25:46.642] [db] open                                label=chaindata sizeLimit=2TB pageSize=16KB
WARN[02-26|11:25:46.658] Preverified list reduced after applying type filter from=5127 to=5126
INFO[02-26|11:25:48.113] [snapshots:block] Stat                   blocks=10.21M indices=10.21M alloc=686.1MB sys=706.6MB
INFO[02-26|11:25:48.161] [snapshots:caplin] Stat                  blocks=1 indices=1
INFO[02-26|11:25:48.166] [snapshots:caplin-state] Stat            blocks=1 indices=1
INFO[02-26|11:25:48.176] Reading DB settings from existing erigondb.toml
INFO[02-26|11:25:48.176] erigondb settings                        step_size=1562500 steps_in_frozen_file=64
INFO[02-26|11:25:48.445] [snapshots:history] Stat                 blocks=3.79M step2blockNum="16=3.51M,24=3.75M,26=3.79M" txs=40.62M first_history_idx_in_db=3796853 alloc=735.6MB sys=851.3MB
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744118
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744113
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744107
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744116
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744108
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744103
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744106
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744100
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744102
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744110
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744105
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744109
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744104
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744111
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744112
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744115
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744114
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744117
INFO[02-26|11:25:48.446] checking commitment hist at block        blockNum=3744101
EROR[02-26|11:25:48.549] [check-commitment-hist-at-blk-range] failure err="checkCommitmentHistAtBlk: 3744105, commitment state blockNum doesn't match blockNum: 3744104 != 3744105"
Error: checkCommitmentHistAtBlk: 3744105, commitment state blockNum doesn't match blockNum: 3744104 != 3744105

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