Files
evm/sync/statesync/sync_helpers.go
2025-08-01 01:23:42 +00:00

43 lines
1.3 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package statesync
import (
"github.com/luxfi/geth/common"
"github.com/luxfi/geth/core/rawdb"
"github.com/luxfi/geth/core/types"
"github.com/luxfi/geth/ethdb"
"github.com/luxfi/geth/trie"
)
// writeAccountSnapshot stores the account represented by [acc] to the snapshot at [accHash], using
// SlimAccountRLP format (omitting empty code/storage).
func writeAccountSnapshot(db ethdb.KeyValueWriter, accHash common.Hash, acc types.StateAccount) {
slimAccount := types.SlimAccountRLP(acc)
rawdb.WriteAccountSnapshot(db, accHash, slimAccount)
}
// writeAccountStorageSnapshotFromTrie iterates the trie at [storageTrie] and copies all entries
// to the storage snapshot for [accountHash].
func writeAccountStorageSnapshotFromTrie(batch ethdb.Batch, batchSize int, accountHash common.Hash, storageTrie *trie.Trie) error {
nodeIt, err := storageTrie.NodeIterator(nil)
if err != nil {
return err
}
it := trie.NewIterator(nodeIt)
for it.Next() {
rawdb.WriteStorageSnapshot(batch, accountHash, common.BytesToHash(it.Key), it.Value)
if batch.ValueSize() > batchSize {
if err := batch.Write(); err != nil {
return err
}
batch.Reset()
}
}
if it.Err != nil {
return it.Err
}
return batch.Write()
}