Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State Store: Write XOR Hash per block range #84

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions ss/pebbledb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ const (

PrefixStore = "s/k:"
LenPrefixStore = 4
StorePrefixTpl = "s/k:%s/" // s/k:<storeKey>
latestVersionKey = "s/_latest" // NB: latestVersionKey key must be lexically smaller than StorePrefixTpl
StorePrefixTpl = "s/k:%s/" // s/k:<storeKey>
HashTpl = "s_/hash:%s:%d-%d" // "s_/hash:<storeKey>:%d-%d"
latestVersionKey = "s/_latest" // NB: latestVersionKey key must be lexically smaller than StorePrefixTpl
earliestVersionKey = "s/_earliest"
latestMigratedKeyMetadata = "s/_latestMigratedKey"
latestMigratedModuleMetadata = "s/_latestMigratedModule"
Expand Down Expand Up @@ -808,3 +809,13 @@ func valTombstoned(value []byte) bool {

return true
}

// WriteBlockRangeHash writes a hash for a range of blocks to the database
func (db *Database) WriteBlockRangeHash(storeKey string, beginBlockRange, endBlockRange int64, hash []byte) error {
key := []byte(fmt.Sprintf(HashTpl, storeKey, beginBlockRange, endBlockRange))
err := db.storage.Set(key, hash, defaultWriteOpts)
if err != nil {
return fmt.Errorf("failed to write block range hash: %w", err)
}
return nil
}
5 changes: 5 additions & 0 deletions ss/rocksdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,8 @@ func cloneAppend(bz []byte, tail []byte) (res []byte) {
func (db *Database) RawImport(ch <-chan types.RawSnapshotNode) error {
panic("implement me")
}

// WriteBlockRangeHash writes a hash for a range of blocks to the database
func (db *Database) WriteBlockRangeHash(storeKey string, beginBlockRange, endBlockRange int64, hash []byte) error {
panic("implement me")
}
5 changes: 5 additions & 0 deletions ss/sqlite/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,8 @@ func execPragmas(db *sql.DB, pragmas []string) error {
func (db *Database) RawImport(ch <-chan types.RawSnapshotNode) error {
panic("implement me")
}

// WriteBlockRangeHash writes a hash for a range of blocks to the database
func (db *Database) WriteBlockRangeHash(storeKey string, beginBlockRange, endBlockRange int64, hash []byte) error {
panic("implement me")
}
1 change: 1 addition & 0 deletions ss/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type StateStore interface {
SetLatestMigratedKey(key []byte) error
GetLatestMigratedModule() (string, error)
SetLatestMigratedModule(module string) error
WriteBlockRangeHash(storeKey string, beginBlockRange, endBlockRange int64, hash []byte) error

// ApplyChangeset Persist the change set of a block,
// the `changeSet` should be ordered by (storeKey, key),
Expand Down
Loading