Files
evmgpu/plugin/evm/customrawdb/accessors_snapshot_ext.go

47 lines
1.7 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package customrawdb
import (
"github.com/luxfi/geth/common"
ethrawdb "github.com/luxfi/geth/core/rawdb"
"github.com/luxfi/geth/ethdb"
log "github.com/luxfi/log"
)
// ReadSnapshotBlockHash retrieves the hash of the block whose state is contained in
// the persisted snapshot.
func ReadSnapshotBlockHash(db ethdb.KeyValueReader) common.Hash {
data, _ := db.Get(snapshotBlockHashKey)
if len(data) != common.HashLength {
return common.Hash{}
}
return common.BytesToHash(data)
}
// WriteSnapshotBlockHash stores the root of the block whose state is contained in
// the persisted snapshot.
func WriteSnapshotBlockHash(db ethdb.KeyValueWriter, blockHash common.Hash) {
if err := db.Put(snapshotBlockHashKey, blockHash[:]); err != nil {
log.Crit("Failed to store snapshot block hash", "err", err)
}
}
// DeleteSnapshotBlockHash deletes the hash of the block whose state is contained in
// the persisted snapshot. Since snapshots are not immutable, this method can
// be used during updates, so a crash or failure will mark the entire snapshot
// invalid.
func DeleteSnapshotBlockHash(db ethdb.KeyValueWriter) {
if err := db.Delete(snapshotBlockHashKey); err != nil {
log.Crit("Failed to remove snapshot block hash", "err", err)
}
}
// IterateAccountSnapshots returns an iterator for walking all of the accounts in the snapshot
func IterateAccountSnapshots(db ethdb.Iteratee) ethdb.Iterator {
it := db.NewIterator(ethrawdb.SnapshotAccountPrefix, nil)
keyLen := len(ethrawdb.SnapshotAccountPrefix) + common.HashLength
return ethrawdb.NewKeyLengthIterator(it, keyLen)
}