Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/state/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,23 +291,37 @@ func (t *Tree) Disable() {

// Snapshot retrieves a snapshot belonging to the given block root, or nil if no
// snapshot is maintained for that block.
//
// For ZK-era blocks the header carries a zkStateRoot (Poseidon hash) while
// snapshot layers are keyed by the locally-computed mptStateRoot (Keccak256).
// Translate the root through the on-disk mapping so callers can always pass
// the block header root without knowing which format the snapshot uses.
func (t *Tree) Snapshot(blockRoot common.Hash) Snapshot {
t.lock.RLock()
defer t.lock.RUnlock()

if mptRoot, err := rawdb.ReadDiskStateRoot(t.diskdb, blockRoot); err == nil {
blockRoot = mptRoot
}
return t.layers[blockRoot]
}

// Snapshots returns all visited layers from the topmost layer with specific
// root and traverses downward. The layer amount is limited by the given number.
// If nodisk is set, then disk layer is excluded.
//
// For ZK-era blocks the root may be a zkStateRoot; translate it to the
// locally-computed mptStateRoot before lookup (same as Snapshot does).
func (t *Tree) Snapshots(root common.Hash, limits int, nodisk bool) []Snapshot {
t.lock.RLock()
defer t.lock.RUnlock()

if limits == 0 {
return nil
}
if mptRoot, err := rawdb.ReadDiskStateRoot(t.diskdb, root); err == nil {
root = mptRoot
}
layer := t.layers[root]
if layer == nil {
return nil
Expand Down
Loading