mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
This commit is contained in:
parent
0206909058
commit
ecb0408521
1 changed files with 25 additions and 5 deletions
|
|
@ -17,7 +17,9 @@
|
||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/tracing"
|
"github.com/XinFinOrg/XDPoSChain/core/tracing"
|
||||||
|
|
@ -223,15 +225,33 @@ func (s *hookedStateDB) AddLog(log *types.Log) {
|
||||||
func (s *hookedStateDB) Finalise(deleteEmptyObjects bool) {
|
func (s *hookedStateDB) Finalise(deleteEmptyObjects bool) {
|
||||||
defer s.inner.Finalise(deleteEmptyObjects)
|
defer s.inner.Finalise(deleteEmptyObjects)
|
||||||
if s.hooks.OnBalanceChange == nil {
|
if s.hooks.OnBalanceChange == nil {
|
||||||
|
// Short circuit if no relevant hooks are set.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Collect all self-destructed addresses first, then sort them to ensure
|
||||||
|
// that state change hooks will be invoked in deterministic
|
||||||
|
// order when the accounts are deleted below
|
||||||
|
var selfDestructedAddrs []common.Address
|
||||||
for addr := range s.inner.journal.dirties {
|
for addr := range s.inner.journal.dirties {
|
||||||
obj := s.inner.stateObjects[addr]
|
obj := s.inner.stateObjects[addr]
|
||||||
if obj != nil && obj.selfDestructed {
|
if obj == nil || !obj.selfDestructed {
|
||||||
// If ether was sent to account post-selfdestruct it is burnt.
|
// Not self-destructed, keep searching.
|
||||||
if bal := obj.Balance(); bal.Sign() != 0 {
|
continue
|
||||||
s.hooks.OnBalanceChange(addr, bal, new(big.Int), tracing.BalanceDecreaseSelfdestructBurn)
|
}
|
||||||
}
|
selfDestructedAddrs = append(selfDestructedAddrs, addr)
|
||||||
|
}
|
||||||
|
sort.Slice(selfDestructedAddrs, func(i, j int) bool {
|
||||||
|
return bytes.Compare(selfDestructedAddrs[i][:], selfDestructedAddrs[j][:]) < 0
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, addr := range selfDestructedAddrs {
|
||||||
|
obj := s.inner.stateObjects[addr]
|
||||||
|
// Bingo: state object was self-destructed, call relevant hooks.
|
||||||
|
|
||||||
|
// If ether was sent to account post-selfdestruct, record as burnt.
|
||||||
|
if bal := obj.Balance(); bal.Sign() != 0 {
|
||||||
|
s.hooks.OnBalanceChange(addr, bal, new(big.Int), tracing.BalanceDecreaseSelfdestructBurn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue