aboutsummaryrefslogtreecommitdiffstats
path: root/core/state/statedb.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-07-04 18:42:13 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-07-04 18:42:13 +0800
commit9c3db1be1dd24c366a58a7ced22adfa0b0839efe (patch)
tree0c102cd7f590a80bc291b82274e7ca16335a250f /core/state/statedb.go
parent9bb575be7db85f967771018a915fbc4e80345ee2 (diff)
parent47460b3b4af51e08518c781680897cf2986415cc (diff)
downloaddexon-9c3db1be1dd24c366a58a7ced22adfa0b0839efe.tar.gz
dexon-9c3db1be1dd24c366a58a7ced22adfa0b0839efe.tar.zst
dexon-9c3db1be1dd24c366a58a7ced22adfa0b0839efe.zip
Merge pull request #1369 from obscuren/statedb-update-cleanup
core, core/state: throw out intermediate state
Diffstat (limited to 'core/state/statedb.go')
-rw-r--r--core/state/statedb.go26
1 files changed, 23 insertions, 3 deletions
diff --git a/core/state/statedb.go b/core/state/statedb.go
index f6f63f329..4ccda1fc7 100644
--- a/core/state/statedb.go
+++ b/core/state/statedb.go
@@ -18,6 +18,7 @@ import (
type StateDB struct {
db common.Database
trie *trie.SecureTrie
+ root common.Hash
stateObjects map[string]*StateObject
@@ -31,7 +32,7 @@ type StateDB struct {
// Create a new state from a given trie
func New(root common.Hash, db common.Database) *StateDB {
trie := trie.NewSecure(root[:], db)
- return &StateDB{db: db, trie: trie, stateObjects: make(map[string]*StateObject), refund: new(big.Int), logs: make(map[common.Hash]Logs)}
+ return &StateDB{root: root, db: db, trie: trie, stateObjects: make(map[string]*StateObject), refund: new(big.Int), logs: make(map[common.Hash]Logs)}
}
func (self *StateDB) PrintRoot() {
@@ -185,7 +186,7 @@ func (self *StateDB) DeleteStateObject(stateObject *StateObject) {
addr := stateObject.Address()
self.trie.Delete(addr[:])
- delete(self.stateObjects, addr.Str())
+ //delete(self.stateObjects, addr.Str())
}
// Retrieve a state object given my the address. Nil if not found
@@ -323,7 +324,8 @@ func (self *StateDB) Refunds() *big.Int {
return self.refund
}
-func (self *StateDB) Update() {
+// SyncIntermediate updates the intermediate state and all mid steps
+func (self *StateDB) SyncIntermediate() {
self.refund = new(big.Int)
for _, stateObject := range self.stateObjects {
@@ -340,6 +342,24 @@ func (self *StateDB) Update() {
}
}
+// SyncObjects syncs the changed objects to the trie
+func (self *StateDB) SyncObjects() {
+ self.trie = trie.NewSecure(self.root[:], self.db)
+
+ self.refund = new(big.Int)
+
+ for _, stateObject := range self.stateObjects {
+ if stateObject.remove {
+ self.DeleteStateObject(stateObject)
+ } else {
+ stateObject.Update()
+
+ self.UpdateStateObject(stateObject)
+ }
+ stateObject.dirty = false
+ }
+}
+
// Debug stuff
func (self *StateDB) CreateOutputForDiff() {
for _, stateObject := range self.stateObjects {