aboutsummaryrefslogtreecommitdiffstats
path: root/core/state/statedb.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-01-20 18:09:24 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-01-20 18:09:24 +0800
commit886478b18b73bbe8421531f1a71664a2bc0f5eeb (patch)
tree230986c30bc908eadfcd8b3f862e43ee2dba7d4d /core/state/statedb.go
parent5945a33350ea6e8bfc6308826efe16aab0e2e93d (diff)
downloaddexon-886478b18b73bbe8421531f1a71664a2bc0f5eeb.tar.gz
dexon-886478b18b73bbe8421531f1a71664a2bc0f5eeb.tar.zst
dexon-886478b18b73bbe8421531f1a71664a2bc0f5eeb.zip
core/state, trie: don't leak database writes before commit
Diffstat (limited to 'core/state/statedb.go')
-rw-r--r--core/state/statedb.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/core/state/statedb.go b/core/state/statedb.go
index 8093472b5..22ffa36a0 100644
--- a/core/state/statedb.go
+++ b/core/state/statedb.go
@@ -206,9 +206,6 @@ func (self *StateDB) Delete(addr common.Address) bool {
// Update the given state object and apply it to state trie
func (self *StateDB) UpdateStateObject(stateObject *StateObject) {
- if len(stateObject.code) > 0 {
- self.db.Put(stateObject.codeHash, stateObject.code)
- }
addr := stateObject.Address()
data, err := rlp.EncodeToBytes(stateObject)
if err != nil {
@@ -375,8 +372,15 @@ func (s *StateDB) commit(db trie.DatabaseWriter) (common.Hash, error) {
// and just mark it for deletion in the trie.
s.DeleteStateObject(stateObject)
} else {
+ // Write any contract code associated with the state object
+ if len(stateObject.code) > 0 {
+ if err := db.Put(stateObject.codeHash, stateObject.code); err != nil {
+ return common.Hash{}, err
+ }
+ }
// Write any storage changes in the state object to its trie.
stateObject.Update()
+
// Commit the trie of the object to the batch.
// This updates the trie root internally, so
// getting the root hash of the storage trie