Skip to content

feat(flatkv): add comprehensive writing test coverage and centralize account-field semantics#3057

Merged
blindchaser merged 8 commits intomainfrom
yiren/flatkv-write-test
Mar 12, 2026
Merged

feat(flatkv): add comprehensive writing test coverage and centralize account-field semantics#3057
blindchaser merged 8 commits intomainfrom
yiren/flatkv-write-test

Conversation

@blindchaser
Copy link
Contributor

Summary

Centralize account-field read/delete semantics into explicit AccountValue methods, remove dead pendingAccountWrite.isDelete code path, fix fullScanLtHash legacyDB omission, and add comprehensive write/persistence/fault-tolerance test coverage across all FlatKV sub-DBs.

KVPair.Delete for account fields (nonce, codehash) is a field reset within AccountValue, not a physical row removal. NonceBytes always returns (zero, true) for zero nonce; CodeHashBytes returns (nil, false) for zero codehash. Storage, code, and legacy deletes remain physical tombstones. The accountDB row always persists -- there is no row-level delete.

  • keys.go: Add NonceBytes, CodeHashBytes, ClearNonce, ClearCodeHash to AccountValue. Each method encodes the asymmetric nonce/codehash delete contract at the type level.
  • store.go: Remove isDelete from pendingAccountWrite. Document that account-field deletes are field resets, not row tombstones.
  • store_read.go: Replace duplicated inline nonce/codehash extraction (2 call sites) with NonceBytes()/CodeHashBytes(). Remove dead paw.isDelete guard and unused encoding/binary import.
  • store_write.go: ApplyChangeSets delete path calls ClearNonce()/ClearCodeHash() instead of manual zeroing. LtHash pair construction enforces Delete: false for account rows. commitBatches removes dead paw.isDelete branch -- account writes always use Set.
  • lthash_correctness_test.go: fullScanLtHash now includes legacyDB scan, fixing an omission where legacy entries were excluded from ground-truth LtHash computation.
  • store_test.go, store_read_test.go, store_write_test.go: All test changeset names corrected from "test"/"empty"/"write"/"delete" to "evm" so data flows through the actual EVM key routing path.

Test plan

keys_test.go -- 4 new unit tests:

  • TestAccountValueNonceBytes: zero, non-zero, max uint64 nonce encoding; always found=true.
  • TestAccountValueCodeHashBytes: zero codehash returns (nil, false); non-zero returns bytes.
  • TestAccountValueClearNonce: zeroes nonce, preserves codehash.
  • TestAccountValueClearCodeHash: zeroes codehash, preserves nonce.

store_write_test.go -- 8 new tests:

  • TestDeleteSemanticsCodehashAsymmetry: nonce delete returns (zero, found=true), codehash delete returns (nil, found=false), accountDB row persists, code physically deleted.
  • TestCrossApplyChangeSetsOrdering: write-then-delete and delete-then-write for storage keys within same block.
  • TestCrossApplyChangeSetsAccountOrdering: 4 subtests for nonce/codehash write-delete ordering and asymmetric visibility.
  • TestEmptyCommitWALPayloadsDiffer: nil vs empty changeset WAL payload distinction.
  • TestSubDBEntryCount: live entry counts after writes, overwrites, and deletes across sub-DBs; account delete does not reduce count.
  • TestApplyChangeSetsInvalidNonceLength / TestApplyChangeSetsInvalidCodehashLength: input validation error paths.
  • TestAccountValueEncodingTransition: EOA (40 bytes) to contract (72 bytes) and back via codehash add/delete; nonce survives transitions.

lthash_correctness_test.go -- 6 new tests:

  • TestFullScanLtHashIncludesLegacy: ground-truth scan covers legacyDB.
  • TestLtHashCrossApply{Account,Storage,Code,Legacy,Mixed}Overwrite: same-key overwrite across two ApplyChangeSets calls in one block, full-scan verified for each key type and all types combined.

snapshot_test.go -- 7 new tests:

  • TestReopenAfterEmptyCommits / TestReopenAfterDeletes: version and LtHash persistence across close/reopen; asymmetric nonce/codehash delete visibility after restart.
  • TestWALTruncationThenRollback: snapshot + WAL truncation + rollback to earlier version.
  • TestReopenAfterSnapshotAndTruncation: reopen from snapshot after WAL truncation.
  • TestSingleDBOpenFailure / TestGlobalMetadataCorruption / TestLocalMetaCorruption: fault injection -- corrupt MANIFEST, global version, local meta; LoadVersion rejects.
  • TestWALDirectoryDeleted: recovery from missing WAL directory when snapshot is current.
  • TestWALSegmentCorruption: corrupt WAL segments prevent catchup to target version.

store_meta_test.go -- 1 new test:

  • TestGlobalMetadataPersistence: global version and LtHash checksum survive close/reopen via metadataDB.

- Fix fullScanLtHash to include legacyDB scan (was silently incomplete)
- Add/enhance 18 write tests: semantic routing, delete semantics,
  cross-changeset ordering, input validation, metadata persistence,
  reopen correctness, snapshot+truncation, and fault tolerance
…account-field semantics

Add explicit AccountValue helpers (NonceBytes, CodeHashBytes, ClearNonce,
ClearCodeHash) to encode the asymmetric delete contract at the type level.
Remove dead pendingAccountWrite.isDelete code path. Fix fullScanLtHash
to include legacyDB. Add read-only LoadVersion mode.
Includes write, persistence, fault-tolerance, and LtHash correctness tests
across all sub-DBs.
@github-actions
Copy link

github-actions bot commented Mar 12, 2026

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMar 12, 2026, 9:05 PM

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.35%. Comparing base (904de28) to head (42eb1aa).
⚠️ Report is 2 commits behind head on main.

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

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3057      +/-   ##
==========================================
+ Coverage   58.27%   58.35%   +0.07%     
==========================================
  Files        2076     2079       +3     
  Lines      171480   171010     -470     
==========================================
- Hits        99933    99793     -140     
+ Misses      62619    62283     -336     
- Partials     8928     8934       +6     
Flag Coverage Δ
sei-chain-pr 67.08% <81.81%> (?)
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/keys.go 100.00% <100.00%> (ø)
sei-db/state_db/sc/flatkv/store.go 72.40% <ø> (+12.40%) ⬆️
sei-db/state_db/sc/flatkv/store_read.go 64.34% <50.00%> (+7.50%) ⬆️
sei-db/state_db/sc/flatkv/store_write.go 80.07% <66.66%> (+2.25%) ⬆️

... and 253 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.

@blindchaser blindchaser requested a review from yzang2019 March 12, 2026 18:14
@blindchaser blindchaser added this pull request to the merge queue Mar 12, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 12, 2026
@blindchaser blindchaser enabled auto-merge March 12, 2026 21:04
@blindchaser blindchaser added this pull request to the merge queue Mar 12, 2026
Merged via the queue into main with commit 9029c60 Mar 12, 2026
38 checks passed
@blindchaser blindchaser deleted the yiren/flatkv-write-test branch March 12, 2026 22:18
yzang2019 added a commit that referenced this pull request Mar 13, 2026
* main:
  feat(flatkv): add comprehensive writing test coverage and centralize account-field semantics (#3057)
  Fix flaky test caused by async WAL writes (#3063)
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.

3 participants