diff --git a/ss/pebbledb/db.go b/ss/pebbledb/db.go index d5eccb99..ee0269b0 100644 --- a/ss/pebbledb/db.go +++ b/ss/pebbledb/db.go @@ -28,8 +28,9 @@ const ( PrefixStore = "s/k:" LenPrefixStore = 4 - StorePrefixTpl = "s/k:%s/" // s/k: - latestVersionKey = "s/_latest" // NB: latestVersionKey key must be lexically smaller than StorePrefixTpl + StorePrefixTpl = "s/k:%s/" // s/k: + HashTpl = "s/_hash:%s:%d-%d" // "s/_hash::%d-%d" + latestVersionKey = "s/_latest" // NB: latestVersionKey key must be lexically smaller than StorePrefixTpl earliestVersionKey = "s/_earliest" latestMigratedKeyMetadata = "s/_latestMigratedKey" latestMigratedModuleMetadata = "s/_latestMigratedModule" @@ -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 +} diff --git a/ss/rocksdb/db.go b/ss/rocksdb/db.go index 272bc334..e4375679 100644 --- a/ss/rocksdb/db.go +++ b/ss/rocksdb/db.go @@ -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") +} diff --git a/ss/sqlite/db.go b/ss/sqlite/db.go index d9a45fd6..92e7959c 100644 --- a/ss/sqlite/db.go +++ b/ss/sqlite/db.go @@ -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") +} diff --git a/ss/types/store.go b/ss/types/store.go index ffa19b57..ca573da0 100644 --- a/ss/types/store.go +++ b/ss/types/store.go @@ -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),