Skip to content

Add 9 bytes of metadata to FlatKV store#3163

Open
cody-littley wants to merge 143 commits intomainfrom
cjl/9-byte-metadata
Open

Add 9 bytes of metadata to FlatKV store#3163
cody-littley wants to merge 143 commits intomainfrom
cjl/9-byte-metadata

Conversation

@cody-littley
Copy link
Copy Markdown
Contributor

Describe your changes and provide context

In order to support BUD proofs, we need to add "block last modified" metadata to each value. Since we are about to do a migration, it's lower effort in the long run to add this metadata now instead of later.

Testing performed to validate your change

Unit tests

@cody-littley cody-littley self-assigned this Apr 1, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedApr 8, 2026, 10:13 PM

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 74.51820% with 119 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.71%. Comparing base (289bc61) to head (e80ff1e).

Files with missing lines Patch % Lines
sei-db/state_db/sc/flatkv/store_read.go 59.82% 44 Missing and 3 partials ⚠️
sei-db/state_db/sc/flatkv/store_write.go 68.93% 25 Missing and 16 partials ⚠️
sei-db/state_db/sc/flatkv/store_apply.go 87.80% 14 Missing and 6 partials ⚠️
sei-db/state_db/sc/flatkv/exporter.go 79.31% 3 Missing and 3 partials ⚠️
sei-db/state_db/sc/flatkv/iterator.go 50.00% 4 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3163      +/-   ##
==========================================
- Coverage   59.02%   58.71%   -0.31%     
==========================================
  Files        2065     2106      +41     
  Lines      169349   173563    +4214     
==========================================
+ Hits        99960   101912    +1952     
- Misses      60630    62535    +1905     
- Partials     8759     9116     +357     
Flag Coverage Δ
sei-chain-pr 75.97% <74.51%> (?)
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/config.go 78.66% <100.00%> (+0.28%) ⬆️
sei-db/state_db/sc/flatkv/flatkv_test_config.go 100.00% <100.00%> (ø)
sei-db/state_db/sc/flatkv/keys.go 100.00% <100.00%> (ø)
sei-db/state_db/sc/flatkv/store.go 73.27% <100.00%> (ø)
sei-db/state_db/sc/flatkv/iterator.go 77.24% <50.00%> (-2.18%) ⬇️
sei-db/state_db/sc/flatkv/exporter.go 81.11% <79.31%> (-2.98%) ⬇️
sei-db/state_db/sc/flatkv/store_apply.go 87.80% <87.80%> (ø)
sei-db/state_db/sc/flatkv/store_write.go 72.15% <68.93%> (-13.45%) ⬇️
sei-db/state_db/sc/flatkv/store_read.go 64.49% <59.82%> (-4.53%) ⬇️

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

@cody-littley cody-littley marked this pull request as ready for review April 8, 2026 18:45
// Setup //
///////////
s.phaseTimer.SetPhase("apply_change_sets_prepare")
s.pendingChangeSets = append(s.pendingChangeSets, changeSets...)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ApplyChangeSets now appends to pendingChangeSets before validation/processing succeeds, while Commit writes pendingChangeSets straight into the WAL. If one ApplyChangeSets fails and the caller later commits, the WAL can contain changes that were never reflected in the in-memory writes/LtHash, and catchup will replay bad data.

consider only commit to s.pendingChangeSets, s.accountWrites, etc. after the entire function succeeds


// GetBlockHeightModified returns the block height at which the key was last modified.
// If not found, returns (-1, false, nil).
func (s *CommitStore) GetBlockHeightModified(key []byte) (int64, bool, error) {
Copy link
Copy Markdown
Contributor

@blindchaser blindchaser Apr 8, 2026

Choose a reason for hiding this comment

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

For an EOA (zero code-hash), Get(codeHashKey) returns (nil, false, nil), correctly reporting not found.

But GetBlockHeightModified(codeHashKey) returns (blockHeight, true, nil) because it doesn't check for zero code-hash.

Inconsistent API semantics.

}
return cd.GetBlockHeight(), true, nil
default:
return -1, false, fmt.Errorf("unsupported key type: %v", kind)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we add EVMKeyLegacy switch support here? @yzang2019

@blindchaser
Copy link
Copy Markdown
Contributor

file name spelling: sei-db/state_db/sc/flatkv/vtype/contstants.go -> constants.go

// Process incoming legacy changes into a form appropriate for hashing and insertion into the DB.
func processLegacyChanges(
rawChanges map[string][]byte,
blockHeight int64,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is the blockHeight param being used? and LegacyData has no block height field

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