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

Problem: no api to convert native events to logs #343

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (cli) [#242](https://github.com/crypto-org-chain/ethermint/pull/242) Integrate tendermint bootstrap cmd.
- (cli) [#246](https://github.com/crypto-org-chain/ethermint/pull/246) Call app.Close to cleanup resource on graceful shutdown.
* (cli) [#288](https://github.com/crypto-org-chain/ethermint/pull/288) make abci handshake shutdown gracefully.
- (evm) [#]() Add native event converter APIs.
mmsqe marked this conversation as resolved.
Show resolved Hide resolved


## [v0.21.0] - 2023-01-26
Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ func NewEthermintApp(
tracer,
evmSs, nil,
allKeys,
nil,
)

// Create IBC Keeper
Expand Down
7 changes: 7 additions & 0 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"math/big"

errorsmod "cosmossdk.io/errors"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
Expand All @@ -37,6 +38,8 @@ import (
"github.com/evmos/ethermint/x/evm/types"
)

type EventConverter = func([]abci.EventAttribute) []*ethtypes.Log

// Keeper grants access to the EVM module state and implements the go-ethereum StateDB interface.
type Keeper struct {
// Protobuf codec
Expand Down Expand Up @@ -77,6 +80,8 @@ type Keeper struct {
// a set of store keys that should cover all the precompile use cases,
// or ideally just pass the application's all stores.
keys map[string]storetypes.StoreKey

eventConverters map[string]EventConverter
}

// NewKeeper generates new evm module keeper
Expand All @@ -92,6 +97,7 @@ func NewKeeper(
ss paramstypes.Subspace,
customContracts []precompiles.StatefulPrecompiledContract,
keys map[string]storetypes.StoreKey,
eventConverters map[string]EventConverter,
) *Keeper {
// ensure evm module account is set
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
Expand All @@ -117,6 +123,7 @@ func NewKeeper(
ss: ss,
customContracts: customContracts,
keys: keys,
eventConverters: eventConverters,
}
}

Expand Down
22 changes: 22 additions & 0 deletions x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
}
}

// convert native events to ethereum logs
convertNativeEvents(stateDB, k.eventConverters)

// calculate a minimum amount of gas to be charged to sender if GasLimit
// is considerably higher than GasUsed to stay more aligned with Tendermint gas mechanics
// for more info https://github.com/evmos/ethermint/issues/1085
Expand All @@ -445,3 +448,22 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
Hash: txConfig.TxHash.Hex(),
}, nil
}

func convertNativeEvents(stateDB *statedb.StateDB, converters map[string]EventConverter) {
if len(converters) == 0 {
return
}

events := stateDB.NativeEvents()
if len(events) == 0 {
return
}

for _, event := range events {
if converter, ok := converters[event.Type]; ok {
for _, log := range converter(event.Attributes) {
stateDB.AddLog(log)
}
}
}
}
Loading