[r3.4] db/state, db/integrity: FilesOnlyStateReader for commitment rebuild and CommitmentRoot#21143
Merged
Merged
Conversation
…nd CommitmentRoot (#21026) `CommitmentRoot` has a subcheck `checkCommitmentRootViaRecompute`: it touches/replays content of the final block in commitment.kv file and does `ComputeCommitment`. The resulting root hash should remain unchanged. `RebuildCommitment`: it creates shard of size 16 and ultimately merged. Both need contrainted/limited query of state data (i.e. only return value for key K from before step X) both suffer from 2 problems today: - `getLatestFromFiles(maxTxNum)`: it effectively searches only a single kv file (the one that contains maxTxNum). The files "left and right" of it are ignored. - `LimitedHistoryStateReader`: if `getLatestFromFiles(maxTxNum)` returns nil, it fallbacks to GetLatest. This creates problem like: - commitment prefix is queried, it's not there in current step range. It's there in some previous file, so it'd return nil (because of `getLatestFromFiles` logic) - say we're building 128-192 range, we look for a storage slot key which became nil in this range; `LimitedHistoryStateReader` would fallback on GetLatest in this case. FilesOnlyStateReader: it's essentially LimitedHistoryStateReader, without the fallback on `GetLatest`. the problem is mentioned above. The fix simply walks back from "maxTxNum containing snapshot" to the first snapshot. The change only impacts when `maxTxNum != uint64.max` which is used in `FilesOnlyStateReader`, `checkCommitmentRootViaFileData` and `commitment print` command. domain. - `checkCommitmentRootViaRecompute` — switch from account-domain-only `touchHistoricalKeys` to `sd.TouchChangedKeysFromHistory` (accounts + storage; code is covered transitively via `account.codeHash`). This is the same helper used by `rpc/rpchelper/commitment.go` and receipts generation. (cherry picked from commit a81cc87)
AskAlexSharov
approved these changes
May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-pick of #21026 to
release/3.4.Conflicts resolved:
db/state/squeeze.go— kept theSetStateReader(NewFilesOnlyStateReader(...))swap; dropped the unrelatedif concurrent { EnableParaTrieDB }context lines that don't exist onrelease/3.4.execution/commitment/commitmentdb/commitment_context.go— removedSetLimitedHistoryStateReaderas in the original PR; did not introduceSetCustomHistoryStateReadersince it isn't part of this PR's diff and isn't present onrelease/3.4.