@@ -952,22 +952,7 @@ func (sdb *IntraBlockState) AddBalance(addr accounts.Address, amount uint256.Int
952952 // EIP161: We must check emptiness for the objects such that the account
953953 // clearing (0,0,0 objects) can take effect.
954954 if amount .IsZero () {
955- stateObject , err := sdb .GetOrNewStateObject (addr )
956- if err != nil {
957- return err
958- }
959-
960- if stateObject .data .Empty () {
961- versionWritten (sdb , addr , BalancePath , accounts .NilKey , uint256.Int {})
962- if _ , ok := sdb .journal .dirties [addr ]; ! ok {
963- if dbg .TraceTransactionIO && (sdb .trace || dbg .TraceAccount (addr .Handle ())) {
964- fmt .Printf ("%d (%d.%d) Touch %x\n " , sdb .blockNum , sdb .txIndex , sdb .version , addr )
965- }
966- sdb .touchAccount (addr )
967- }
968- }
969-
970- return nil
955+ return sdb .TouchAccount (addr )
971956 }
972957
973958 prev , wasCommited , _ := sdb .getBalance (addr )
@@ -1007,6 +992,27 @@ func (sdb *IntraBlockState) touchAccount(addr accounts.Address) {
1007992 }
1008993}
1009994
995+ // TouchAccount materializes an empty account and records the zero-balance touch
996+ // needed for state clearing and trie consistency.
997+ func (sdb * IntraBlockState ) TouchAccount (addr accounts.Address ) error {
998+ stateObject , err := sdb .GetOrNewStateObject (addr )
999+ if err != nil {
1000+ return err
1001+ }
1002+
1003+ if stateObject .data .Empty () {
1004+ versionWritten (sdb , addr , BalancePath , accounts .NilKey , uint256.Int {})
1005+ if _ , ok := sdb .journal .dirties [addr ]; ! ok {
1006+ if dbg .TraceTransactionIO && (sdb .trace || dbg .TraceAccount (addr .Handle ())) {
1007+ fmt .Printf ("%d (%d.%d) Touch %x\n " , sdb .blockNum , sdb .txIndex , sdb .version , addr )
1008+ }
1009+ sdb .touchAccount (addr )
1010+ }
1011+ }
1012+
1013+ return nil
1014+ }
1015+
10101016func (sdb * IntraBlockState ) getVersionedAccount (addr accounts.Address , readStorage bool ) (* accounts.Account , ReadSource , Version , error ) {
10111017 if sdb .versionMap == nil {
10121018 return nil , UnknownSource , UnknownVersion , nil
@@ -1137,10 +1143,11 @@ func (sdb *IntraBlockState) refreshVersionedAccount(addr accounts.Address, readA
11371143// SubBalance subtracts amount from the account associated with addr.
11381144// DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account
11391145func (sdb * IntraBlockState ) SubBalance (addr accounts.Address , amount uint256.Int , reason tracing.BalanceChangeReason ) error {
1140- if amount .IsZero () && addr != params .SystemAddress {
1141- // We skip this early exit if the sender is the system address
1142- // because Gnosis has a special logic to create an empty system account
1143- // even after Spurious Dragon (see PR 5645 and Issue 18276).
1146+ if amount .IsZero () {
1147+ if addr == params .SystemAddress {
1148+ // Gnosis keeps an empty system account even after Spurious Dragon.
1149+ return sdb .TouchAccount (addr )
1150+ }
11441151 return nil
11451152 }
11461153
0 commit comments