github.com/MetalBlockchain/subnet-evm@v0.4.9/sync/statesync/sync_helpers.go (about) 1 // (c) 2021-2022, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package statesync 5 6 import ( 7 "github.com/MetalBlockchain/subnet-evm/core/rawdb" 8 "github.com/MetalBlockchain/subnet-evm/core/state/snapshot" 9 "github.com/MetalBlockchain/subnet-evm/core/types" 10 "github.com/MetalBlockchain/subnet-evm/ethdb" 11 "github.com/MetalBlockchain/subnet-evm/trie" 12 "github.com/ethereum/go-ethereum/common" 13 ) 14 15 // writeAccountSnapshot stores the account represented by [acc] to the snapshot at [accHash], using 16 // SlimAccountRLP format (omitting empty code/storage). 17 func writeAccountSnapshot(db ethdb.KeyValueWriter, accHash common.Hash, acc types.StateAccount) { 18 slimAccount := snapshot.SlimAccountRLP(acc.Nonce, acc.Balance, acc.Root, acc.CodeHash) 19 rawdb.WriteAccountSnapshot(db, accHash, slimAccount) 20 } 21 22 // writeAccountStorageSnapshotFromTrie iterates the trie at [storageTrie] and copies all entries 23 // to the storage snapshot for [accountHash]. 24 func writeAccountStorageSnapshotFromTrie(batch ethdb.Batch, batchSize int, accountHash common.Hash, storageTrie *trie.Trie) error { 25 it := trie.NewIterator(storageTrie.NodeIterator(nil)) 26 for it.Next() { 27 rawdb.WriteStorageSnapshot(batch, accountHash, common.BytesToHash(it.Key), it.Value) 28 if batch.ValueSize() > batchSize { 29 if err := batch.Write(); err != nil { 30 return err 31 } 32 batch.Reset() 33 } 34 } 35 if it.Err != nil { 36 return it.Err 37 } 38 return batch.Write() 39 }