Skip to content

Commit 41eef93

Browse files
committed
triedb: get the first state block
Signed-off-by: Delweng <[email protected]>
1 parent 41408af commit 41eef93

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

triedb/database.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,13 @@ func (db *Database) IsVerkle() bool {
375375
func (db *Database) Disk() ethdb.Database {
376376
return db.disk
377377
}
378+
379+
// FirstStateBlock
380+
func (db *Database) FirstStateBlock() (uint64, error) {
381+
pdb, ok := db.backend.(*pathdb.Database)
382+
if !ok {
383+
// Ignore in hash scheme
384+
return 0, nil
385+
}
386+
return pdb.FirstStateBlock()
387+
}

triedb/pathdb/database.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,3 +748,25 @@ func (db *Database) StorageIterator(root common.Hash, account common.Hash, seek
748748
}
749749
return newFastStorageIterator(db, root, account, seek)
750750
}
751+
752+
// FirstStateBlock returns the block number of the oldest state snapshot in the freezer or disk layer.
753+
func (db *Database) FirstStateBlock() (uint64, error) {
754+
var (
755+
m meta
756+
err error
757+
tailID = db.tree.bottom().stateID()
758+
)
759+
760+
if db.freezer != nil {
761+
tailID, err = db.freezer.Tail()
762+
if err != nil {
763+
return 0, err
764+
}
765+
}
766+
767+
blob := rawdb.ReadStateHistoryMeta(db.diskdb, tailID)
768+
if err := m.decode(blob); err != nil {
769+
return 0, err
770+
}
771+
return m.block, nil
772+
}

0 commit comments

Comments
 (0)