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: event converter don't have to be global #1164

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 2 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ import (
ethermint "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm"
evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
"github.com/evmos/ethermint/x/evm/keeper/precompiles"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/evmos/ethermint/x/feemarket"
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
Expand All @@ -146,12 +145,12 @@ import (
"github.com/crypto-org-chain/cronos/v2/app/ante"
"github.com/crypto-org-chain/cronos/v2/x/cronos"
cronosclient "github.com/crypto-org-chain/cronos/v2/x/cronos/client"
cronosevents "github.com/crypto-org-chain/cronos/v2/x/cronos/events"
cronoskeeper "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper"
evmhandlers "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper/evmhandlers"
cronosprecompiles "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper/precompiles"
"github.com/crypto-org-chain/cronos/v2/x/cronos/middleware"
cronostypes "github.com/crypto-org-chain/cronos/v2/x/cronos/types"
"github.com/ethereum/go-ethereum/core/vm"

"github.com/crypto-org-chain/cronos/v2/client/docs"

Expand Down Expand Up @@ -547,11 +546,10 @@ func New(
app.FeeMarketKeeper,
tracer,
evmS,
[]precompiles.StatefulPrecompiledContract{
[]vm.PrecompiledContract{
cronosprecompiles.NewRelayerContract(app.IBCKeeper, appCodec),
},
allKeys,
cronosevents.ConvertEvent,
)

var gravityKeeper gravitykeeper.Keeper
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ replace (
// TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc1
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20230913025430-199ccc232fd4
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20230913063514-bf62d0b33e56
// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ github.com/crypto-org-chain/cometbft-db v0.0.0-20230412133340-ac70df4b45f6 h1:d4
github.com/crypto-org-chain/cometbft-db v0.0.0-20230412133340-ac70df4b45f6/go.mod h1:hF5aclS++7WrW8USOA3zPeKI0CuzwUD2TPYug25ANlQ=
github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20230905040840-b3af5590283b h1:d2GOFR3i3BjDlPsmJkp8Gsrt9LK2nq2IVEnE/rMv1Fo=
github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20230905040840-b3af5590283b/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c=
github.com/crypto-org-chain/ethermint v0.6.1-0.20230913025430-199ccc232fd4 h1:h9rEAyTlS1GkEcK9CPgh16mcVYOTRfKXgmlGyCz129E=
github.com/crypto-org-chain/ethermint v0.6.1-0.20230913025430-199ccc232fd4/go.mod h1:xT6yzwilauRVhkvhjj7lDzazfgG4ZeUNSoQsuKImitY=
github.com/crypto-org-chain/ethermint v0.6.1-0.20230913063514-bf62d0b33e56 h1:nu9oo/IEG8O2PZD57vUB43g+sK/3pH1gov9F5gI26OM=
github.com/crypto-org-chain/ethermint v0.6.1-0.20230913063514-bf62d0b33e56/go.mod h1:xT6yzwilauRVhkvhjj7lDzazfgG4ZeUNSoQsuKImitY=
github.com/crypto-org-chain/gravity-bridge/module/v2 v2.0.1-0.20230825054824-75403cd90c6e h1:rSTc35OBjjCBx47rHPWBCIHNGPbMnEj8f7fNcK2TjVI=
github.com/crypto-org-chain/gravity-bridge/module/v2 v2.0.1-0.20230825054824-75403cd90c6e/go.mod h1:HBaDqlFjlaXJwVQtA7jHejyaA7xwjXI2o6pU/ccP3tE=
github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ schema = 3
hash = "sha256-GgcReGsIIuBE2TabDYqDO9sBGogdVr9RSh4arQzdPnE="
replaced = "github.com/evmos/go-ethereum"
[mod."github.com/evmos/ethermint"]
version = "v0.6.1-0.20230913025430-199ccc232fd4"
hash = "sha256-AnPsOXlXVOYznPBC6vh2alov09p0fy0cO6BTRcekU8o="
version = "v0.6.1-0.20230913063514-bf62d0b33e56"
hash = "sha256-1WE0BADrSWYmRs3DnuleD0+Jhc/ImQbgKHFSCYzNMT4="
replaced = "github.com/crypto-org-chain/ethermint"
[mod."github.com/felixge/httpsnoop"]
version = "v1.0.2"
Expand Down
14 changes: 14 additions & 0 deletions x/cronos/keeper/precompiles/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package precompiles

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/evmos/ethermint/x/evm/statedb"
)

// ExtStateDB defines extra methods of statedb to support stateful precompiled contracts
type ExtStateDB interface {
vm.StateDB
ExecuteNativeAction(contract common.Address, converter statedb.EventConverter, action func(ctx sdk.Context) error) error
}
5 changes: 2 additions & 3 deletions x/cronos/keeper/precompiles/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/evmos/ethermint/x/evm/keeper/precompiles"

ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
)
Expand All @@ -24,7 +23,7 @@ type RelayerContract struct {
ibcKeeper *ibckeeper.Keeper
}

func NewRelayerContract(ibcKeeper *ibckeeper.Keeper, cdc codec.Codec) precompiles.StatefulPrecompiledContract {
func NewRelayerContract(ibcKeeper *ibckeeper.Keeper, cdc codec.Codec) vm.PrecompiledContract {
return &RelayerContract{
BaseContract: NewBaseContract(RelayerContractAddress),
ibcKeeper: ibcKeeper,
Expand Down Expand Up @@ -81,7 +80,7 @@ func (bc *RelayerContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool
}
prefix := int(binary.LittleEndian.Uint32(contract.Input[:prefixSize4Bytes]))
input := contract.Input[prefixSize4Bytes:]
stateDB := evm.StateDB.(precompiles.ExtStateDB)
stateDB := evm.StateDB.(ExtStateDB)
yihuang marked this conversation as resolved.
Show resolved Hide resolved

var (
err error
Expand Down
6 changes: 3 additions & 3 deletions x/cronos/keeper/precompiles/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
cronosevents "github.com/crypto-org-chain/cronos/v2/x/cronos/events"
"github.com/ethereum/go-ethereum/common"
"github.com/evmos/ethermint/x/evm/keeper/precompiles"
)

type NativeMessage interface {
Expand All @@ -22,7 +22,7 @@ func exec[Req any, PReq interface {
NativeMessage
}, Resp codec.ProtoMarshaler](
cdc codec.Codec,
stateDB precompiles.ExtStateDB,
stateDB ExtStateDB,
caller common.Address,
contract common.Address,
input []byte,
Expand All @@ -42,7 +42,7 @@ func exec[Req any, PReq interface {
}

var res Resp
if err := stateDB.ExecuteNativeAction(contract, func(ctx sdk.Context) error {
if err := stateDB.ExecuteNativeAction(contract, cronosevents.ConvertEvent, func(ctx sdk.Context) error {
var err error
res, err = action(ctx, msg)
return err
Expand Down
Loading