From 151c7bef41ed96d9aace3dba235ad2db5fe26e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 8 Jan 2016 13:46:45 +0200 Subject: core/state, trie: node iterator reports parent hashes too --- core/state/iterator.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'core') diff --git a/core/state/iterator.go b/core/state/iterator.go index 59a8e0242..a051e5e01 100644 --- a/core/state/iterator.go +++ b/core/state/iterator.go @@ -34,11 +34,13 @@ type NodeIterator struct { stateIt *trie.NodeIterator // Primary iterator for the global state trie dataIt *trie.NodeIterator // Secondary iterator for the data trie of a contract - codeHash common.Hash // Hash of the contract source code - code []byte // Source code associated with a contract + accountHash common.Hash // Hash of the node containing the account + codeHash common.Hash // Hash of the contract source code + code []byte // Source code associated with a contract - Hash common.Hash // Hash of the current entry being iterated (nil if not standalone) - Entry interface{} // Current state entry being iterated (internal representation) + Hash common.Hash // Hash of the current entry being iterated (nil if not standalone) + Entry interface{} // Current state entry being iterated (internal representation) + Parent common.Hash // Hash of the first full ancestor node (nil if current is the root) } // NewNodeIterator creates an post-order state node iterator. @@ -112,6 +114,7 @@ func (it *NodeIterator) step() { panic(fmt.Sprintf("code %x: %v", account.CodeHash, err)) } } + it.accountHash = it.stateIt.Parent } // retrieve pulls and caches the current state entry the iterator is traversing. @@ -127,11 +130,14 @@ func (it *NodeIterator) retrieve() bool { // Otherwise retrieve the current entry switch { case it.dataIt != nil: - it.Hash, it.Entry = it.dataIt.Hash, it.dataIt.Node + it.Hash, it.Entry, it.Parent = it.dataIt.Hash, it.dataIt.Node, it.dataIt.Parent + if it.Parent == (common.Hash{}) { + it.Parent = it.accountHash + } case it.code != nil: - it.Hash, it.Entry = it.codeHash, it.code + it.Hash, it.Entry, it.Parent = it.codeHash, it.code, it.accountHash case it.stateIt != nil: - it.Hash, it.Entry = it.stateIt.Hash, it.stateIt.Node + it.Hash, it.Entry, it.Parent = it.stateIt.Hash, it.stateIt.Node, it.stateIt.Parent } return true } -- cgit v1.2.3