core/tracing: emit state change events for journal reverts
This commit is contained in:
parent
b4e01743ea
commit
f670a7fd93
|
@ -20,6 +20,7 @@ import (
|
|||
"maps"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/tracing"
|
||||
"github.com/holiman/uint256"
|
||||
)
|
||||
|
||||
|
@ -233,7 +234,7 @@ func (ch touchChange) copy() journalEntry {
|
|||
}
|
||||
|
||||
func (ch balanceChange) revert(s *StateDB) {
|
||||
s.getStateObject(*ch.account).setBalance(ch.prev)
|
||||
s.getStateObject(*ch.account).setBalanceLogged(ch.prev, tracing.BalanceChangeRevert)
|
||||
}
|
||||
|
||||
func (ch balanceChange) dirtied() *common.Address {
|
||||
|
@ -248,7 +249,7 @@ func (ch balanceChange) copy() journalEntry {
|
|||
}
|
||||
|
||||
func (ch nonceChange) revert(s *StateDB) {
|
||||
s.getStateObject(*ch.account).setNonce(ch.prev)
|
||||
s.getStateObject(*ch.account).setNonceLogged(ch.prev)
|
||||
}
|
||||
|
||||
func (ch nonceChange) dirtied() *common.Address {
|
||||
|
@ -263,7 +264,7 @@ func (ch nonceChange) copy() journalEntry {
|
|||
}
|
||||
|
||||
func (ch codeChange) revert(s *StateDB) {
|
||||
s.getStateObject(*ch.account).setCode(common.BytesToHash(ch.prevhash), ch.prevcode)
|
||||
s.getStateObject(*ch.account).setCodeLogged(common.BytesToHash(ch.prevhash), ch.prevcode)
|
||||
}
|
||||
|
||||
func (ch codeChange) dirtied() *common.Address {
|
||||
|
@ -279,7 +280,7 @@ func (ch codeChange) copy() journalEntry {
|
|||
}
|
||||
|
||||
func (ch storageChange) revert(s *StateDB) {
|
||||
s.getStateObject(*ch.account).setState(ch.key, ch.prevvalue, ch.origvalue)
|
||||
s.getStateObject(*ch.account).setStateLogged(ch.key, ch.prevvalue, ch.origvalue)
|
||||
}
|
||||
|
||||
func (ch storageChange) dirtied() *common.Address {
|
||||
|
|
|
@ -257,6 +257,11 @@ func (s *stateObject) SetState(key, value common.Hash) {
|
|||
prevvalue: prev,
|
||||
origvalue: origin,
|
||||
})
|
||||
s.setStateLogged(key, value, origin)
|
||||
}
|
||||
|
||||
func (s *stateObject) setStateLogged(key, value, origin common.Hash) {
|
||||
prev, _ := s.getState(key)
|
||||
if s.db.logger != nil && s.db.logger.OnStorageChange != nil {
|
||||
s.db.logger.OnStorageChange(s.address, key, prev, value)
|
||||
}
|
||||
|
@ -514,6 +519,10 @@ func (s *stateObject) SetBalance(amount *uint256.Int, reason tracing.BalanceChan
|
|||
account: &s.address,
|
||||
prev: new(uint256.Int).Set(s.data.Balance),
|
||||
})
|
||||
s.setBalanceLogged(amount, reason)
|
||||
}
|
||||
|
||||
func (s *stateObject) setBalanceLogged(amount *uint256.Int, reason tracing.BalanceChangeReason) {
|
||||
if s.db.logger != nil && s.db.logger.OnBalanceChange != nil {
|
||||
s.db.logger.OnBalanceChange(s.address, s.Balance().ToBig(), amount.ToBig(), reason)
|
||||
}
|
||||
|
@ -595,6 +604,11 @@ func (s *stateObject) SetCode(codeHash common.Hash, code []byte) {
|
|||
prevhash: s.CodeHash(),
|
||||
prevcode: prevcode,
|
||||
})
|
||||
s.setCodeLogged(codeHash, code)
|
||||
}
|
||||
|
||||
func (s *stateObject) setCodeLogged(codeHash common.Hash, code []byte) {
|
||||
prevcode := s.Code()
|
||||
if s.db.logger != nil && s.db.logger.OnCodeChange != nil {
|
||||
s.db.logger.OnCodeChange(s.address, common.BytesToHash(s.CodeHash()), prevcode, codeHash, code)
|
||||
}
|
||||
|
@ -612,6 +626,10 @@ func (s *stateObject) SetNonce(nonce uint64) {
|
|||
account: &s.address,
|
||||
prev: s.data.Nonce,
|
||||
})
|
||||
s.setNonceLogged(nonce)
|
||||
}
|
||||
|
||||
func (s *stateObject) setNonceLogged(nonce uint64) {
|
||||
if s.db.logger != nil && s.db.logger.OnNonceChange != nil {
|
||||
s.db.logger.OnNonceChange(s.address, s.data.Nonce, nonce)
|
||||
}
|
||||
|
|
|
@ -245,6 +245,9 @@ const (
|
|||
// account within the same tx (captured at end of tx).
|
||||
// Note it doesn't account for a self-destruct which appoints itself as recipient.
|
||||
BalanceDecreaseSelfdestructBurn BalanceChangeReason = 14
|
||||
|
||||
// BalanceChangeRevert is emitted when the balance is reverted back to a previous value due to call failure.
|
||||
BalanceChangeRevert BalanceChangeReason = 15
|
||||
)
|
||||
|
||||
// GasChangeReason is used to indicate the reason for a gas change, useful
|
||||
|
|
Loading…
Reference in New Issue