@@ -24,7 +24,6 @@ import (
2424 "time"
2525
2626 "github.com/XinFinOrg/XDPoSChain/common"
27- "github.com/XinFinOrg/XDPoSChain/core/tracing"
2827 "github.com/XinFinOrg/XDPoSChain/core/types"
2928 "github.com/XinFinOrg/XDPoSChain/crypto"
3029 "github.com/XinFinOrg/XDPoSChain/rlp"
@@ -222,22 +221,21 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
222221}
223222
224223// SetState updates a value in account storage.
225- func (s * stateObject ) SetState (db Database , key , value common.Hash ) {
226- // If the new value is the same as old, don't set
224+ func (s * stateObject ) SetState (db Database , key , value common.Hash ) common.Hash {
225+ // If the new value is the same as old, don't set. Otherwise, track only the
226+ // dirty changes, supporting reverting all of it back to no change.
227227 prev := s .GetState (db , key )
228228 if prev == value {
229- return
229+ return prev
230230 }
231231 // New value is different, update and journal the change
232232 s .db .journal .append (storageChange {
233233 account : & s .address ,
234234 key : key ,
235235 prevalue : prev ,
236236 })
237- if s .db .logger != nil && s .db .logger .OnStorageChange != nil {
238- s .db .logger .OnStorageChange (s .address , key , prev , value )
239- }
240237 s .setState (key , value )
238+ return prev
241239}
242240
243241func (s * stateObject ) setState (key , value common.Hash ) {
@@ -344,36 +342,28 @@ func (s *stateObject) commitTrie(db Database) (*trie.NodeSet, error) {
344342
345343// AddBalance adds amount to s's balance.
346344// It is used to add funds to the destination account of a transfer.
347- func (s * stateObject ) AddBalance (amount * big.Int , reason tracing.BalanceChangeReason ) {
345+ // returns the previous balance
346+ func (s * stateObject ) AddBalance (amount * big.Int ) * big.Int {
348347 // EIP161: We must check emptiness for the objects such that the account
349348 // clearing (0,0,0 objects) can take effect.
350349 if amount .Sign () == 0 {
351350 if s .empty () {
352351 s .touch ()
353352 }
354- return
353+ return new (big. Int ). Set ( s . Balance ())
355354 }
356- s .SetBalance (new (big.Int ).Add (s .Balance (), amount ), reason )
355+ return s .SetBalance (new (big.Int ).Add (s .Balance (), amount ))
357356}
358357
359- // SubBalance removes amount from s's balance.
360- // It is used to remove funds from the origin account of a transfer.
361- func (s * stateObject ) SubBalance (amount * big.Int , reason tracing.BalanceChangeReason ) {
362- if amount .Sign () == 0 {
363- return
364- }
365- s .SetBalance (new (big.Int ).Sub (s .Balance (), amount ), reason )
366- }
367-
368- func (s * stateObject ) SetBalance (amount * big.Int , reason tracing.BalanceChangeReason ) {
358+ // SetBalance sets the balance for the object, and returns the previous balance.
359+ func (s * stateObject ) SetBalance (amount * big.Int ) * big.Int {
360+ prev := new (big.Int ).Set (s .data .Balance )
369361 s .db .journal .append (balanceChange {
370362 account : & s .address ,
371- prev : new (big.Int ).Set (s . data . Balance ),
363+ prev : new (big.Int ).Set (prev ),
372364 })
373- if s .db .logger != nil && s .db .logger .OnBalanceChange != nil {
374- s .db .logger .OnBalanceChange (s .address , s .Balance (), amount , reason )
375- }
376365 s .setBalance (amount )
366+ return prev
377367}
378368
379369func (s * stateObject ) setBalance (amount * big.Int ) {
@@ -444,9 +434,6 @@ func (s *stateObject) SetCode(codeHash common.Hash, code []byte) {
444434 prevhash : s .CodeHash (),
445435 prevcode : prevcode ,
446436 })
447- if s .db .logger != nil && s .db .logger .OnCodeChange != nil {
448- s .db .logger .OnCodeChange (s .address , common .BytesToHash (s .CodeHash ()), prevcode , codeHash , code )
449- }
450437 s .setCode (codeHash , code )
451438}
452439
@@ -461,9 +448,6 @@ func (s *stateObject) SetNonce(nonce uint64) {
461448 account : & s .address ,
462449 prev : s .data .Nonce ,
463450 })
464- if s .db .logger != nil && s .db .logger .OnNonceChange != nil {
465- s .db .logger .OnNonceChange (s .address , s .data .Nonce , nonce )
466- }
467451 s .setNonce (nonce )
468452}
469453
0 commit comments