aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2016-06-13 17:56:42 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2016-06-13 17:57:42 +0800
commitbb3651abc865c6f6babec0d357afa85f5a539d83 (patch)
tree7f1839985359fdb2e25d34b7fd4b0c534f851e91 /core
parentfdd61b83ffe1ac0e3ef0621acbd92dd61df9910d (diff)
downloaddexon-bb3651abc865c6f6babec0d357afa85f5a539d83.tar
dexon-bb3651abc865c6f6babec0d357afa85f5a539d83.tar.gz
dexon-bb3651abc865c6f6babec0d357afa85f5a539d83.tar.bz2
dexon-bb3651abc865c6f6babec0d357afa85f5a539d83.tar.lz
dexon-bb3651abc865c6f6babec0d357afa85f5a539d83.tar.xz
dexon-bb3651abc865c6f6babec0d357afa85f5a539d83.tar.zst
dexon-bb3651abc865c6f6babec0d357afa85f5a539d83.zip
core/state, eth: Updated suicides objects when tracing transactions
Consensus rules dictate that objects can only be removed during the finalisation of the transaction (i.e. after all calls have finished). Thus calling a suicided contract twice from the same transaction: A->B(S)->ret(A)->B(S) results in 2 suicides. Calling the suicided object twice from two transactions: A->B(S), A->B, results in only one suicide and a call to an empty object. Our current debug tracing functionality replays all transaction that were executed prior to the targetted transaction in order to provide the user with an accurate trace. As a side effect to calling StateDB.IntermediateRoot it also deletes any suicides objects. Our tracing code never calls this function because it isn't interested in the intermediate root. Becasue of this it caused a bug in the tracing code where transactions that were send to priviously deleted objects resulted in two suicides rather than one suicide and a call to an empty object. Fixes #2542
Diffstat (limited to 'core')
-rw-r--r--core/state/statedb.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/core/state/statedb.go b/core/state/statedb.go
index 70673799e..3e25e0c16 100644
--- a/core/state/statedb.go
+++ b/core/state/statedb.go
@@ -370,6 +370,27 @@ func (s *StateDB) IntermediateRoot() common.Hash {
return s.trie.Hash()
}
+// DeleteSuicides flags the suicided objects for deletion so that it
+// won't be referenced again when called / queried up on.
+//
+// DeleteSuicides should not be used for consensus related updates
+// under any circumstances.
+func (s *StateDB) DeleteSuicides() {
+ // Reset refund so that any used-gas calculations can use
+ // this method.
+ s.refund = new(big.Int)
+ for _, stateObject := range s.stateObjects {
+ if stateObject.dirty {
+ // If the object has been removed by a suicide
+ // flag the object as deleted.
+ if stateObject.remove {
+ stateObject.deleted = true
+ }
+ stateObject.dirty = false
+ }
+ }
+}
+
// Commit commits all state changes to the database.
func (s *StateDB) Commit() (root common.Hash, err error) {
root, batch := s.CommitBatch()