Skip to content

Commit

Permalink
- address pr comments
Browse files Browse the repository at this point in the history
- move tracer calls to storage changes higher up
  • Loading branch information
Eduard-Voiculescu committed Oct 17, 2024
1 parent 4e2ce71 commit bc9cb03
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
1 change: 0 additions & 1 deletion x/evm/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ func (suite *HandlerTestSuite) TestHandleMsgEthereumTx() {

for _, tc := range testCases {
suite.Run(tc.msg, func() {
// todo: it seems we are missing a hook on a balance change? or something like that?
suite.SetupTest() // reset
//nolint
tc.malleate()
Expand Down
4 changes: 2 additions & 2 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
ethermint "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm/statedb"
"github.com/evmos/ethermint/x/evm/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
)

// CustomContractFn defines a custom precompiled contract generator with ctx, rules and returns a precompiled contract.
Expand Down Expand Up @@ -141,7 +140,7 @@ func (k Keeper) ChainID() *big.Int {

func (k *Keeper) InitChainer(ctx sdk.Context) {
if tracer := cosmostracing.GetCtxBlockchainTracer(ctx); tracer != nil && tracer.OnBlockchainInit != nil {
tracer.OnBlockchainInit(evmtypes.DefaultChainConfig().EthereumConfig(k.ChainID()))
tracer.OnBlockchainInit(types.DefaultChainConfig().EthereumConfig(k.ChainID()))
}
}

Expand Down Expand Up @@ -204,6 +203,7 @@ func (k *Keeper) PostTxProcessing(ctx sdk.Context, msg *core.Message, receipt *e
return k.hooks.PostTxProcessing(ctx, msg, receipt)
}

// SetTracer should only be called during initialization
func (k *Keeper) SetTracer(tracer *cosmostracing.Hooks) {
k.evmTracer = tracer
}
Expand Down
20 changes: 13 additions & 7 deletions x/evm/statedb/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,34 +552,40 @@ func (s *StateDB) SetCode(addr common.Address, code []byte) {
oldCode := s.GetCode(addr)
stateObject.SetCode(crypto.Keccak256Hash(code), code)

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

if s.evmTracer != nil && s.evmTracer.OnCodeChange != nil {
s.evmTracer.OnCodeChange(addr, crypto.Keccak256Hash(oldCode), oldCode, crypto.Keccak256Hash(code), code)
s.evmTracer.OnCodeChange(addr, oldCodeHash, oldCode, crypto.Keccak256Hash(code), code)
}
}
}

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

if s.evmTracer != nil && s.evmTracer.OnStorageChange != nil {
s.evmTracer.OnStorageChange(addr, key, s.GetState(addr, key), value)
}

stateObject := s.getOrNewStateObject(addr)
stateObject.SetState(key, value)
}

// SetStorage replaces the entire storage for the specified account with given
// storage. This function should only be used for debugging and the mutations
// must be discarded afterward.
func (s *StateDB) SetStorage(addr common.Address, storage Storage) {
stateObject := s.getOrNewStateObject(addr)
stateObject.SetStorage(storage)

if s.evmTracer != nil && s.evmTracer.OnStorageChange != nil {
for key, value := range storage {
s.evmTracer.OnStorageChange(addr, key, s.GetState(addr, key), value)
}
}

stateObject := s.getOrNewStateObject(addr)
stateObject.SetStorage(storage)

}

// Suicide marks the given account as suicided.
Expand Down
2 changes: 1 addition & 1 deletion x/evm/tracers/firehose.go
Original file line number Diff line number Diff line change
Expand Up @@ -2430,7 +2430,7 @@ func (m Memory) GetPtr(offset, size int64) []byte {
// work because the memory is going to be expanded before the operation is actually
// executed so the memory will be of the correct size.
//
// In this situtation, we must pad with zeroes when the memory is not big enough.
// In this situation, we must pad with zeroes when the memory is not big enough.
reminder := m[offset:]
return append(reminder, make([]byte, int(size)-len(reminder))...)
}
9 changes: 4 additions & 5 deletions x/evm/tracers/firehose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,11 @@ func TestFirehose_reorderIsolatedTransactionsAndOrdinals(t *testing.T) {
ordinals := maps.Keys(seenOrdinals)
slices.Sort(ordinals)

// All ordinals should be in stricly increasing order
prev := -1
// All ordinals should be in strictly increasing order
prev := 0
for _, ordinal := range ordinals {
if prev != -1 {
assert.Equal(t, prev+1, int(ordinal), "Ordinal %d is not in sequence", ordinal)
}
assert.Equal(t, prev+1, int(ordinal), "Ordinal %d is not in sequence", ordinal)
prev = int(ordinal)
}
})
}
Expand Down

0 comments on commit bc9cb03

Please sign in to comment.