feat(sei-db): add flatkv store implementation#2793
Conversation
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2793 +/- ##
==========================================
+ Coverage 56.65% 56.66% +0.01%
==========================================
Files 2031 2036 +5
Lines 165854 166570 +716
==========================================
+ Hits 93959 94382 +423
- Misses 63664 63867 +203
- Partials 8231 8321 +90
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 34a6fed4c3
ℹ️ 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".
| for _, pw := range s.codeWrites { | ||
| if pw.isDelete { | ||
| if err := batch.Delete(pw.key); err != nil { | ||
| return fmt.Errorf("codeDB delete: %w", err) | ||
| } | ||
| } else { | ||
| if err := batch.Set(pw.key, pw.value); err != nil { | ||
| return fmt.Errorf("codeDB set: %w", err) | ||
| } | ||
| } | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
| for _, pw := range s.storageWrites { | ||
| if pw.isDelete { | ||
| if err := batch.Delete(pw.key); err != nil { | ||
| return fmt.Errorf("storageDB delete: %w", err) | ||
| } | ||
| } else { | ||
| if err := batch.Set(pw.key, pw.value); err != nil { | ||
| return fmt.Errorf("storageDB set: %w", err) | ||
| } | ||
| } | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
- Multi-DB storage: storageDB, accountDB, codeDB, metadataDB - LtHash-based state commitment using internal key formats - Configurable write toggles per DB type - Iterator support for storage keys
34a6fed to
e3a525f
Compare
| for _, paw := range s.accountWrites { | ||
| key := AccountKey(paw.addr) | ||
| if paw.isDelete { | ||
| if err := batch.Delete(key); err != nil { | ||
| return fmt.Errorf("accountDB delete: %w", err) | ||
| } | ||
| } else { | ||
| // Encode AccountValue and store with addr as key | ||
| encoded := EncodeAccountValue(paw.value) | ||
| if err := batch.Set(key, encoded); err != nil { | ||
| return fmt.Errorf("accountDB set: %w", err) | ||
| } | ||
| } | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
| package config | ||
|
|
||
| // FlatKVConfig defines configuration for the FlatKV (EVM) commit store. | ||
| type FlatKVConfig struct { |
There was a problem hiding this comment.
Let's put this under flatkv package?
| // EnableStorageWrites enables writes to storageDB and its LtHash contribution. | ||
| // When false, storage data is skipped entirely (no DB writes, no LtHash updates). | ||
| // Default: true | ||
| EnableStorageWrites bool `mapstructure:"enable-storage-writes"` |
There was a problem hiding this comment.
Not sure why we want these configs, as long as dual write is true, all EVM state should be written to flatkv, and we don't need to control which key to write or not
| // When false (default): all writes use Sync=true for maximum durability. | ||
| // WAL and metaDB always use sync writes regardless of this setting. | ||
| // Default: false | ||
| AsyncWrites bool `mapstructure:"async-writes"` |
There was a problem hiding this comment.
Probably better to split into Fsync: bool and AsyncWriteBuffer: int
| // - 0 or 1: flush every block (safest, slowest) | ||
| // - N > 1: flush every N blocks (faster, recovers up to N blocks from WAL) | ||
| // Default: 100 | ||
| FlushInterval int `mapstructure:"flush-interval"` |
There was a problem hiding this comment.
I think we don't need this config today, since we have to flush every block, we can add in the future if we really need it
| // TODO: initialize FlatKV store for evmSC when cfg.WriteMode != config.CosmosOnlyWrite | ||
| // Initialize FlatKV store struct if write mode is not cosmos_only | ||
| // Note: DB is NOT opened here, will be opened in LoadVersion | ||
| if cfg.WriteMode != config.CosmosOnlyWrite { |
There was a problem hiding this comment.
Would recommend checking DualWrite or SplitWrite to determine whether we should initialize EMVCommitter
| } | ||
|
|
||
| // Also load evmCommitter if enabled | ||
| if cs.config.WriteMode != config.CosmosOnlyWrite && cs.evmCommitter != nil { |
There was a problem hiding this comment.
We can remove this check cs.config.WriteMode != config.CosmosOnlyWrite since evmCommitter will be nil if write is not enabled
| if cs.config.WriteMode != config.CosmosOnlyWrite && cs.evmCommitter != nil { | ||
| // Use LoadVersion on existing evmCommitter (matches memiavl pattern) | ||
| // This properly handles readOnly flag and avoids resource leaks | ||
| evmStore, err := cs.evmCommitter.LoadVersion(targetVersion, readOnly) |
There was a problem hiding this comment.
Not sure if we wanna call LoadVersion here, CMS will call LoadVersion as well, we need to make sure it's only called in one place
| ) | ||
|
|
||
| const ( | ||
| // DB subdirectories |
There was a problem hiding this comment.
We need a legacyDB as well
| metadataDir = "metadata" | ||
|
|
||
| // Metadata DB keys | ||
| MetaGlobalVersion = "v" // Global committed version watermark (8 bytes) |
There was a problem hiding this comment.
suggest metadata key stored with _meta/version, _meta/hash
|
|
||
| // Get returns the value for the given memiavl key. | ||
| // Returns (value, true) if found, (nil, false) if not found. | ||
| func (s *CommitStore) Get(key []byte) ([]byte, bool) { |
There was a problem hiding this comment.
Why do we have store_read.go but not store_write.go? If we want to split, I was expecting to see read and write. Otherwise maybe we should just combine
Describe your changes and provide context
Testing performed to validate your change