aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-01-08 19:46:45 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-02-16 18:21:08 +0800
commit151c7bef41ed96d9aace3dba235ad2db5fe26e03 (patch)
tree1902240da75c6ac29ff3edb30d25ddbe2c49ac5e /core
parent5a057a8dedd1fa284e04bc2e7780e74d4600fdeb (diff)
downloadgo-tangerine-151c7bef41ed96d9aace3dba235ad2db5fe26e03.tar
go-tangerine-151c7bef41ed96d9aace3dba235ad2db5fe26e03.tar.gz
go-tangerine-151c7bef41ed96d9aace3dba235ad2db5fe26e03.tar.bz2
go-tangerine-151c7bef41ed96d9aace3dba235ad2db5fe26e03.tar.lz
go-tangerine-151c7bef41ed96d9aace3dba235ad2db5fe26e03.tar.xz
go-tangerine-151c7bef41ed96d9aace3dba235ad2db5fe26e03.tar.zst
go-tangerine-151c7bef41ed96d9aace3dba235ad2db5fe26e03.zip
core/state, trie: node iterator reports parent hashes too
Diffstat (limited to 'core')
-rw-r--r--core/state/iterator.go20
1 files changed, 13 insertions, 7 deletions
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
}