Skip to content

db/state: unify commitment-branch referencing predicate#20944

Merged
wmitsuda merged 1 commit intomainfrom
wmitsuda/fix-shortened-keys
May 3, 2026
Merged

db/state: unify commitment-branch referencing predicate#20944
wmitsuda merged 1 commit intomainfrom
wmitsuda/fix-shortened-keys

Conversation

@wmitsuda
Copy link
Copy Markdown
Member

@wmitsuda wmitsuda commented May 1, 2026

This PR fixes some logic re: handling shortened keys in commitment files:

  • ValuesPlainKeyReferencingThresholdReached as a general rule, if file contains 1 step, then use plain keys, otherwise references. This works well currently because all merged files contains even number of steps (2, 4, 8, 16, 32, etc.).

The problem is the logic uses %0 implying odd number of steps in range should contain plain keys as well. Because I'm modifying the step-rebase command to allow arbitrary number of steps inside a merged range, if you convert an existing node and it ends up containing an odd number of steps, it'll crash on next merge.

  • I noticed a very similar function MayContainValuesPlainKeyReferencing, which kind of does the formula correctly, but it misses files with 2 steps. That function is used only by integrity checks, it is currently missing 2-step files and it is IMO incorrect. I'm removing that almost-duplicate function and retrofitting all callers to use ValuesPlainKeyReferencingThresholdReached.

ValuesPlainKeyReferencingThresholdReached was a parity check
((span)%2 == 0) and MayContainValuesPlainKeyReferencing was a strict-
greater size check (span > 2). Under the old merge planner spans were
always {1, 2, 4, 8, ...}, so the parity test was effectively "merged
file?" — but with clipMergeStartToFileBoundary the planner can now emit
odd spans >= 3, which the parity test misclassifies as plain and the
read path then fails to dereference. The two predicates also disagreed
at span = 2: the write path shortened those files but the integrity
check skipped them.

Replace both bodies with span >= minStepsForReferencing (= 2), matching
the constant's name, and drop MayContainValuesPlainKeyReferencing in
favor of the surviving function. Span-1 files (the only legitimate
plain case) are unchanged; every multi-step file is now consistently
treated as referencing on read, write, and integrity paths.
@wmitsuda wmitsuda requested review from awskii and taratorio May 1, 2026 12:02
@wmitsuda wmitsuda enabled auto-merge May 1, 2026 12:02
@wmitsuda wmitsuda added this pull request to the merge queue May 3, 2026
@awskii
Copy link
Copy Markdown
Member

awskii commented May 3, 2026

spotted same thing

Merged via the queue into main with commit 95cb6a5 May 3, 2026
38 checks passed
@wmitsuda wmitsuda deleted the wmitsuda/fix-shortened-keys branch May 3, 2026 11:02
@AskAlexSharov AskAlexSharov changed the title db/state, db/integrity: unify commitment-branch referencing predicate db/state: unify commitment-branch referencing predicate May 4, 2026
AskAlexSharov added a commit that referenced this pull request May 4, 2026
…#20963)

Cherry-pick of #20944 to performance branch.

Co-authored-by: Willian Mitsuda <wmitsuda@gmail.com>
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.

2 participants