Skip to content

Hdiff fixes#16533

Merged
prestonvanloon merged 6 commits intohdiff-restart-supportfrom
hdiff-fixes
Mar 19, 2026
Merged

Hdiff fixes#16533
prestonvanloon merged 6 commits intohdiff-restart-supportfrom
hdiff-fixes

Conversation

@Inspector-Butters
Copy link
Copy Markdown
Contributor

@Inspector-Butters Inspector-Butters commented Mar 13, 2026

This PR addresses multiple issues in the hdiff code:

  1. the function hasStateUsingStateDiff() that's called in db.HasState() was returning true for any slot that fell on the hdiff tree levels. This is wrong because those states might not actually be saved. This PR fixes that by actually looking in the db to check.
  2. add the call to saveStateByDiff() in db.SaveState() to actually save the states in the hdiff tree. this was missed previously. the reason for the if guard s.stateDiffCache != nil over this call is that when syncing from genesis, the call to initialize state diff comes after the call of SaveState() to save the genesis state. which would cause a panic here. with this guard, that save goes to the legacy stateBucket. but the state will later get saved in the hdiff tree when initializeStateDiff() is called.
  3. adds an early return to getStateUsingStateDiff() when computeLevel(slot) returns -1.
  4. moves the call to initializeStateDiff() higher when doing checkpoint sync. specifically moves it before the call to SaveState(). otherwise there is a bug: state diff tries to save that state in the tree because it has offset 0 from the genesis call, then it would error out because the checkpoint slot doesn't have the necessary parents in the tree. (the offset isn't updated yet). this move makes it so the offset is updated before saving the state. the SaveState() call is also skipped after initializing state diff, because it's redundant. NOTE: maybe if this pattern is good, we want to do the same in genesis.go to avoid writing to the legacy stateBucket entirely. This is done in Hdiff fixes 2 #16534
  5. other small fixes.

Copy link
Copy Markdown
Member

@prestonvanloon prestonvanloon left a comment

Choose a reason for hiding this comment

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

LGTM thanks

@prestonvanloon prestonvanloon merged commit 83553de into hdiff-restart-support Mar 19, 2026
17 checks passed
@prestonvanloon prestonvanloon deleted the hdiff-fixes branch March 19, 2026 15:23
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