From c7058949fd96c7f5542b464071e27277d882f599 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 31 Jan 2025 13:33:33 -0800 Subject: [PATCH 1/3] Write Block Range Hash --- ss/pebbledb/db.go | 15 +++++++++++++-- ss/rocksdb/db.go | 5 +++++ ss/sqlite/db.go | 5 +++++ ss/types/store.go | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ss/pebbledb/db.go b/ss/pebbledb/db.go index d5eccb99..20393e1e 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..33eb6e8f 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(beginBlockRange, endBlockRange int64, hash []byte) error { + panic("implement me") +} diff --git a/ss/sqlite/db.go b/ss/sqlite/db.go index d9a45fd6..971e0fc9 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(beginBlockRange, endBlockRange int64, hash []byte) error { + panic("implement me") +} diff --git a/ss/types/store.go b/ss/types/store.go index ffa19b57..1472e3ac 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(beginBlockRange, endBlockRange int64, hash []byte) error // ApplyChangeset Persist the change set of a block, // the `changeSet` should be ordered by (storeKey, key), From 8df3fc8bd2bb0366c303741ee89478be13a99d8e Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 31 Jan 2025 13:51:33 -0800 Subject: [PATCH 2/3] Update store key --- ss/rocksdb/db.go | 2 +- ss/sqlite/db.go | 2 +- ss/types/store.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ss/rocksdb/db.go b/ss/rocksdb/db.go index 33eb6e8f..e4375679 100644 --- a/ss/rocksdb/db.go +++ b/ss/rocksdb/db.go @@ -379,6 +379,6 @@ func (db *Database) RawImport(ch <-chan types.RawSnapshotNode) error { } // WriteBlockRangeHash writes a hash for a range of blocks to the database -func (db *Database) WriteBlockRangeHash(beginBlockRange, endBlockRange int64, hash []byte) error { +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 971e0fc9..92e7959c 100644 --- a/ss/sqlite/db.go +++ b/ss/sqlite/db.go @@ -340,6 +340,6 @@ func (db *Database) RawImport(ch <-chan types.RawSnapshotNode) error { } // WriteBlockRangeHash writes a hash for a range of blocks to the database -func (db *Database) WriteBlockRangeHash(beginBlockRange, endBlockRange int64, hash []byte) error { +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 1472e3ac..ca573da0 100644 --- a/ss/types/store.go +++ b/ss/types/store.go @@ -22,7 +22,7 @@ type StateStore interface { SetLatestMigratedKey(key []byte) error GetLatestMigratedModule() (string, error) SetLatestMigratedModule(module string) error - WriteBlockRangeHash(beginBlockRange, endBlockRange int64, hash []byte) 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), From eeaea8f77ee2a18085e7a85c8ea3fe7ddb68bf6f Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Mon, 3 Feb 2025 11:41:09 -0500 Subject: [PATCH 3/3] Update hashtpl --- ss/pebbledb/db.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ss/pebbledb/db.go b/ss/pebbledb/db.go index 20393e1e..ee0269b0 100644 --- a/ss/pebbledb/db.go +++ b/ss/pebbledb/db.go @@ -29,7 +29,7 @@ const ( PrefixStore = "s/k:" LenPrefixStore = 4 StorePrefixTpl = "s/k:%s/" // s/k: - HashTpl = "s_/hash:%s:%d-%d" // "s_/hash::%d-%d" + 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"