Skip to content

Commit

Permalink
Merge pull request #84 from sei-protocol/kartik/WriteBlockRangehash
Browse files Browse the repository at this point in the history
State Store: Write XOR Hash per block range
  • Loading branch information
Kbhat1 authored Feb 3, 2025
2 parents b91cba5 + eeaea8f commit 8b0fb9f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
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

0 comments on commit 8b0fb9f

Please sign in to comment.