Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collecting nonceChanges and codeChanges only when the tracer is enabled #9

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions x/evm/statedb/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,30 +547,33 @@ func (s *StateDB) SetBalance(addr common.Address, amount *big.Int) {
func (s *StateDB) SetNonce(addr common.Address, nonce uint64) {
stateObject := s.getOrNewStateObject(addr)
if stateObject != nil {
oldNonce := s.GetNonce(addr)
stateObject.SetNonce(nonce)

// collect nonce changes only if tracer is active to reduce reads to
// StateDB
if s.evmTracer != nil && s.evmTracer.OnNonceChange != nil {
oldNonce := s.GetNonce(addr)
s.evmTracer.OnNonceChange(addr, oldNonce, nonce)
}

stateObject.SetNonce(nonce)
}
}

// SetCode sets the code of account.
func (s *StateDB) SetCode(addr common.Address, code []byte) {
stateObject := s.getOrNewStateObject(addr)
if stateObject != nil {
oldCode := s.GetCode(addr)
stateObject.SetCode(crypto.Keccak256Hash(code), code)

var oldCodeHash common.Hash
if oldCode != nil {
oldCodeHash = crypto.Keccak256Hash(oldCode)
}

// collect code changes only if tracer is active to reduce reads to
// StateDB
if s.evmTracer != nil && s.evmTracer.OnCodeChange != nil {
oldCode := s.GetCode(addr)
var oldCodeHash common.Hash
if oldCode != nil {
oldCodeHash = crypto.Keccak256Hash(oldCode)
}
s.evmTracer.OnCodeChange(addr, oldCodeHash, oldCode, crypto.Keccak256Hash(code), code)
}

stateObject.SetCode(crypto.Keccak256Hash(code), code)
}
}

Expand Down
Loading