core/state/snapshot: release iterator after verification

This commit is contained in:
Péter Szilágyi 2020-05-04 15:14:08 +03:00
parent 5e45db7610
commit da59147014
No known key found for this signature in database
GPG Key ID: E9AE538CEDF8293D
1 changed files with 5 additions and 1 deletions

View File

@ -63,11 +63,15 @@ func VerifyState(snaptree *Tree, root common.Hash) error {
if err != nil { if err != nil {
return err return err
} }
defer acctIt.Release()
got, err := generateTrieRoot(acctIt, common.Hash{}, stdGenerate, func(account common.Hash, stat *generateStats) common.Hash { got, err := generateTrieRoot(acctIt, common.Hash{}, stdGenerate, func(account common.Hash, stat *generateStats) common.Hash {
storageIt, err := snaptree.StorageIterator(root, account, common.Hash{}) storageIt, err := snaptree.StorageIterator(root, account, common.Hash{})
if err != nil { if err != nil {
return common.Hash{} return common.Hash{}
} }
defer storageIt.Release()
hash, err := generateTrieRoot(storageIt, account, stdGenerate, nil, stat, false) hash, err := generateTrieRoot(storageIt, account, stdGenerate, nil, stat, false)
if err != nil { if err != nil {
return common.Hash{} return common.Hash{}
@ -79,7 +83,7 @@ func VerifyState(snaptree *Tree, root common.Hash) error {
return err return err
} }
if got != root { if got != root {
return fmt.Errorf("State root hash mismatch, got %x, want %x", got, root) return fmt.Errorf("state root hash mismatch: got %x, want %x", got, root)
} }
return nil return nil
} }