Skip to content

Commit

Permalink
Skip noop state changes on SetState
Browse files Browse the repository at this point in the history
  • Loading branch information
drklee3 committed Feb 21, 2024
1 parent 0e03788 commit 5cf3bc5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions x/evm/statedb/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,23 @@ func (s *StateDB) SetCode(addr common.Address, code []byte) {
account := s.getOrNewAccount(addr)
account.CodeHash = crypto.Keccak256Hash(code).Bytes()

// Set account so CodeHash is updated
if err := s.keeper.SetAccount(s.ctx.CurrentCtx(), addr, *account); err != nil {
s.SetError(fmt.Errorf("failed to set account for code: %w", err))
}

s.keeper.SetCode(s.ctx.CurrentCtx(), account.CodeHash, code)
}

// SetState sets the contract state.
func (s *StateDB) SetState(addr common.Address, key, value common.Hash) {
commitedState := s.GetCommittedState(addr, key)

// Skip noop state changes
if commitedState == value {
return
}

s.keeper.SetState(s.ctx.CurrentCtx(), addr, key, value.Bytes())
}

Expand Down

0 comments on commit 5cf3bc5

Please sign in to comment.