aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-04-25 16:10:21 +0800
committerGitHub <noreply@github.com>2017-04-25 16:10:20 +0800
commitba3bcd16a6d99bc0e58516556df8e96b730c2d60 (patch)
treee6622b6dd3ca30a28ea68ad69d0d1b2d675b7bb3 /core
parent7cc6abeef6ec0b6c5fd5a94920fa79157cdfcd37 (diff)
parent207bd7d2cddbf16ac2cb870fd6a1c558f02fd8ac (diff)
downloadgo-tangerine-ba3bcd16a6d99bc0e58516556df8e96b730c2d60.tar.gz
go-tangerine-ba3bcd16a6d99bc0e58516556df8e96b730c2d60.tar.zst
go-tangerine-ba3bcd16a6d99bc0e58516556df8e96b730c2d60.zip
Merge pull request #14350 from fjl/trie-iterator-skip-2
eth: add debug_storageRangeAt
Diffstat (limited to 'core')
-rw-r--r--core/state/dump.go5
-rw-r--r--core/state/iterator.go4
-rw-r--r--core/state/state_object.go9
-rw-r--r--core/state/statedb.go13
4 files changed, 24 insertions, 7 deletions
diff --git a/core/state/dump.go b/core/state/dump.go
index 8294d61b9..ffa1a7283 100644
--- a/core/state/dump.go
+++ b/core/state/dump.go
@@ -22,6 +22,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp"
+ "github.com/ethereum/go-ethereum/trie"
)
type DumpAccount struct {
@@ -44,7 +45,7 @@ func (self *StateDB) RawDump() Dump {
Accounts: make(map[string]DumpAccount),
}
- it := self.trie.Iterator()
+ it := trie.NewIterator(self.trie.NodeIterator(nil))
for it.Next() {
addr := self.trie.GetKey(it.Key)
var data Account
@@ -61,7 +62,7 @@ func (self *StateDB) RawDump() Dump {
Code: common.Bytes2Hex(obj.Code(self.db)),
Storage: make(map[string]string),
}
- storageIt := obj.getTrie(self.db).Iterator()
+ storageIt := trie.NewIterator(obj.getTrie(self.db).NodeIterator(nil))
for storageIt.Next() {
account.Storage[common.Bytes2Hex(self.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(storageIt.Value)
}
diff --git a/core/state/iterator.go b/core/state/iterator.go
index 170aec983..a8a2722ae 100644
--- a/core/state/iterator.go
+++ b/core/state/iterator.go
@@ -75,7 +75,7 @@ func (it *NodeIterator) step() error {
}
// Initialize the iterator if we've just started
if it.stateIt == nil {
- it.stateIt = it.state.trie.NodeIterator()
+ it.stateIt = it.state.trie.NodeIterator(nil)
}
// If we had data nodes previously, we surely have at least state nodes
if it.dataIt != nil {
@@ -118,7 +118,7 @@ func (it *NodeIterator) step() error {
if err != nil {
return err
}
- it.dataIt = trie.NewNodeIterator(dataTrie)
+ it.dataIt = dataTrie.NodeIterator(nil)
if !it.dataIt.Next(true) {
it.dataIt = nil
}
diff --git a/core/state/state_object.go b/core/state/state_object.go
index 7d3315303..dcad9d068 100644
--- a/core/state/state_object.go
+++ b/core/state/state_object.go
@@ -201,7 +201,7 @@ func (self *stateObject) setState(key, value common.Hash) {
}
// updateTrie writes cached storage modifications into the object's storage trie.
-func (self *stateObject) updateTrie(db trie.Database) {
+func (self *stateObject) updateTrie(db trie.Database) *trie.SecureTrie {
tr := self.getTrie(db)
for key, value := range self.dirtyStorage {
delete(self.dirtyStorage, key)
@@ -213,6 +213,7 @@ func (self *stateObject) updateTrie(db trie.Database) {
v, _ := rlp.EncodeToBytes(bytes.TrimLeft(value[:], "\x00"))
tr.Update(key[:], v)
}
+ return tr
}
// UpdateRoot sets the trie root to the current root hash of
@@ -280,7 +281,11 @@ func (c *stateObject) ReturnGas(gas *big.Int) {}
func (self *stateObject) deepCopy(db *StateDB, onDirty func(addr common.Address)) *stateObject {
stateObject := newObject(db, self.address, self.data, onDirty)
- stateObject.trie = self.trie
+ if self.trie != nil {
+ // A shallow copy makes the two tries independent.
+ cpy := *self.trie
+ stateObject.trie = &cpy
+ }
stateObject.code = self.code
stateObject.dirtyStorage = self.dirtyStorage.Copy()
stateObject.cachedStorage = self.dirtyStorage.Copy()
diff --git a/core/state/statedb.go b/core/state/statedb.go
index 0c72fc6b0..3b753a2e6 100644
--- a/core/state/statedb.go
+++ b/core/state/statedb.go
@@ -296,6 +296,17 @@ func (self *StateDB) GetState(a common.Address, b common.Hash) common.Hash {
return common.Hash{}
}
+// StorageTrie returns the storage trie of an account.
+// The return value is a copy and is nil for non-existent accounts.
+func (self *StateDB) StorageTrie(a common.Address) *trie.SecureTrie {
+ stateObject := self.getStateObject(a)
+ if stateObject == nil {
+ return nil
+ }
+ cpy := stateObject.deepCopy(self, nil)
+ return cpy.updateTrie(self.db)
+}
+
func (self *StateDB) HasSuicided(addr common.Address) bool {
stateObject := self.getStateObject(addr)
if stateObject != nil {
@@ -481,7 +492,7 @@ func (db *StateDB) ForEachStorage(addr common.Address, cb func(key, value common
cb(h, value)
}
- it := so.getTrie(db.db).Iterator()
+ it := trie.NewIterator(so.getTrie(db.db).NodeIterator(nil))
for it.Next() {
// ignore cached values
key := common.BytesToHash(db.trie.GetKey(it.Key))