Skip to content

Commit

Permalink
Merge pull request #9 from InjectiveLabs/firehose-tracer/improvements
Browse files Browse the repository at this point in the history
collecting nonceChanges and codeChanges only when the tracer is enabled
  • Loading branch information
maxim-inj authored Oct 29, 2024
2 parents 8f05d8e + 642c6ba commit 3a7bd68
Showing 1 changed file with 14 additions and 11 deletions.
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

0 comments on commit 3a7bd68

Please sign in to comment.