Skip to content

fix(flatkv): prevent phantom MixOut for new accounts in LtHash#3000

Open
blindchaser wants to merge 4 commits intomainfrom
yiren/lthash-new-account
Open

fix(flatkv): prevent phantom MixOut for new accounts in LtHash#3000
blindchaser wants to merge 4 commits intomainfrom
yiren/lthash-new-account

Conversation

@blindchaser
Copy link
Contributor

Describe your changes and provide context

  • When a new account (not in accountDB) was first written, getAccountValue returned a zero AccountValue{}. Encoding it produced 40 zero-bytes (len>0), so LtHash performed a MixOut on data that was never MixIn'd, corrupting the hash.
  • Replace oldAccountValues (map[string]AccountValue) with oldAccountRawValues (map[string][]byte) that stores raw DB bytes. Accounts not found in DB get nil, and LtHash correctly skips MixOut when len(LastValue)==0.

Testing performed to validate your change

  • Add lthash_correctness_test.go with 100-block end-to-end test verifying incremental LtHash matches full-scan at every checkpoint.
  • Add focused regression tests for new-account phantom MixOut and multi-ApplyChangeSets-per-block scenarios

When a new account (not in accountDB) was first written,
getAccountValue returned a zero AccountValue{}. Encoding it produced
40 zero-bytes (len>0), so LtHash performed a MixOut on data that was
never MixIn'd, corrupting the hash

Replace oldAccountValues (map[string]AccountValue) with
oldAccountRawValues (map[string][]byte) that stores raw DB bytes.
Accounts not found in DB get nil, and LtHash correctly skips MixOut
when len(LastValue)==0

Tests:
- Add lthash_correctness_test.go with 100-block end-to-end test
  verifying incremental LtHash matches full-scan at every checkpoint
- Add focused regression tests for new-account phantom MixOut and
  multi-ApplyChangeSets-per-block scenarios
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMar 2, 2026, 11:23 PM

@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

❌ Patch coverage is 82.60870% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.30%. Comparing base (778ced7) to head (ccee95d).

Files with missing lines Patch % Lines
sei-db/state_db/sc/flatkv/lthash/lthash.go 50.00% 1 Missing and 1 partial ⚠️
sei-db/state_db/sc/flatkv/store_write.go 89.47% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3000      +/-   ##
==========================================
- Coverage   58.30%   58.30%   -0.01%     
==========================================
  Files        2108     2108              
  Lines      173668   173648      -20     
==========================================
- Hits       101259   101238      -21     
- Misses      63389    63392       +3     
+ Partials     9020     9018       -2     
Flag Coverage Δ
sei-chain-pr 66.08% <82.60%> (?)
sei-db 70.41% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sei-db/state_db/sc/flatkv/lthash/lthash.go 89.91% <50.00%> (-1.39%) ⬇️
sei-db/state_db/sc/flatkv/store_write.go 70.16% <89.47%> (+1.41%) ⬆️

... and 34 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant