Skip to content

feat(flatkv): add seidb tooling for flatkv dump state and state analysis#3312

Merged
blindchaser merged 10 commits into
mainfrom
yiren/flatkv-cmd
Apr 27, 2026
Merged

feat(flatkv): add seidb tooling for flatkv dump state and state analysis#3312
blindchaser merged 10 commits into
mainfrom
yiren/flatkv-cmd

Conversation

@blindchaser

Copy link
Copy Markdown
Contributor

Summary

This PR adds FlatKV-aware seidb tooling for read-only analysis and dump workflows. The new tooling clones immutable FlatKV snapshots plus changelog state into a temporary store before scanning, so live nodes keep their writer lock while CLI commands operate on a stable view.

  • sei-db/tools/cmd/seidb/main.go: registers dump-flatkv alongside the existing seidb operations.
  • sei-db/tools/cmd/seidb/operations/flatkv_open.go: selects the latest current snapshot for height 0 or the highest snapshot at or below an explicit historical height. The clone path hardlinks snapshot and changelog files, skips live LOCK files, falls back to byte-copy only for cross-device links, retries ENOENT races from concurrent snapshot pruning, and removes the temporary clone on close.
  • sei-db/tools/cmd/seidb/operations/dump_flatkv.go: dumps FlatKV physical keys into ordered bucket files for account, code, storage, and legacy. It preserves physical key bytes, filters optional single-bucket output without changing iterator order, checks iterator errors, and returns final flush/close failures so truncated buffered dumps do not report success.
  • sei-db/tools/cmd/seidb/operations/flatkv_state_size.go: adds FlatKV state-size aggregation with per-DB totals and top EVM contract storage accounting. It classifies physical keys by FlatKV type prefix, emits a dedicated flatkv DynamoDB row shape, and rejects partial scan results by surfacing iterator errors.
  • sei-db/tools/cmd/seidb/operations/state_size.go: auto-detects sibling FlatKV data or accepts --flatkv-dir, scans FlatKV only for compatible module filters, prints FlatKV totals next to memIAVL totals, and skips FlatKV export when open or scan errors would make the result incomplete.

Test plan

  • sei-db/tools/cmd/seidb/operations/dump_flatkv_test.go: covers all-bucket dumps, single-bucket filtering, dump file headers, physical key/value formatting, and bucket validation.
  • sei-db/tools/cmd/seidb/operations/flatkv_state_size_test.go: covers physical key classification, contract address extraction, per-DB size accounting, top-contract ordering, and DynamoDB analysis row shape.
  • sei-db/tools/cmd/seidb/operations/flatkv_open_test.go: covers latest snapshot selection from current, explicit historical snapshot selection, missing current and missing snapshot failures, changelog cloning, lock-file exclusion, retry-on-ENOENT behavior, and real read-only opens for latest and historical heights.
  • Verified with gofmt -s -l and go test ./sei-db/tools/cmd/seidb/operations.

@github-actions

github-actions Bot commented Apr 27, 2026

Copy link
Copy Markdown

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedApr 27, 2026, 9:13 PM

@codecov

codecov Bot commented Apr 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 51.47392% with 214 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.14%. Comparing base (0df5a10) to head (71da1a0).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sei-db/tools/cmd/seidb/operations/dump_flatkv.go 43.24% 52 Missing and 11 partials ⚠️
sei-db/tools/cmd/seidb/operations/state_size.go 0.00% 56 Missing ⚠️
sei-db/tools/cmd/seidb/operations/flatkv_open.go 67.54% 31 Missing and 18 partials ⚠️
...db/tools/cmd/seidb/operations/flatkv_state_size.go 63.11% 41 Missing and 4 partials ⚠️
sei-db/tools/cmd/seidb/main.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3312      +/-   ##
==========================================
- Coverage   59.18%   59.14%   -0.05%     
==========================================
  Files        2094     2096       +2     
  Lines      172070   172179     +109     
==========================================
- Hits       101847   101834      -13     
- Misses      61406    61500      +94     
- Partials     8817     8845      +28     
Flag Coverage Δ
sei-chain-pr 21.61% <51.47%> (?)
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/tools/cmd/seidb/main.go 0.00% <0.00%> (ø)
...db/tools/cmd/seidb/operations/flatkv_state_size.go 63.11% <63.11%> (ø)
sei-db/tools/cmd/seidb/operations/flatkv_open.go 67.54% <67.54%> (ø)
sei-db/tools/cmd/seidb/operations/state_size.go 0.00% <0.00%> (ø)
sei-db/tools/cmd/seidb/operations/dump_flatkv.go 43.24% <43.24%> (ø)

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b7280fe19c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sei-db/tools/cmd/seidb/operations/flatkv_open.go Outdated
Comment thread sei-db/tools/cmd/seidb/operations/flatkv_open.go Outdated
@blindchaser blindchaser changed the title feat(flatkv): add seidb tooling for flatkv read-only analysis and dump workflows. feat(flatkv): add seidb tooling for flatkv dump state and state analysis Apr 27, 2026
Comment on lines +21 to +24
TotalNumKeys uint64
TotalKeySize uint64
TotalValueSize uint64
TotalSize uint64

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.

Could these be collapsed down into a FlatKVDBSize struct?

Comment on lines +120 to +124
case 0x0a:
return flatkvBucketAccount
case 0x07:
return flatkvBucketCode
case 0x03:

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.

We have constants defined for these, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good point, addressed

@blindchaser blindchaser added this pull request to the merge queue Apr 27, 2026
Merged via the queue into main with commit 4a8bfe6 Apr 27, 2026
52 of 56 checks passed
@blindchaser blindchaser deleted the yiren/flatkv-cmd branch April 27, 2026 23:06
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