Skip to content

Commit

Permalink
inject the statedb in ethermint
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Nov 1, 2023
1 parent 24750f1 commit 9cb8be6
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,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.20231027030935-291bfa0458c4
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20231101080732-b9078abfe0fd
// 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 @@ -484,8 +484,8 @@ github.com/crypto-org-chain/cometbft-db v0.0.0-20231011055109-57922ac52a63 h1:R1
github.com/crypto-org-chain/cometbft-db v0.0.0-20231011055109-57922ac52a63/go.mod h1:rocwIfnS+kA060x64gkSIRvWB9StSppIkJuo5MWzL24=
github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20231013072415-eec017435467 h1:m0/aHPIJAzi2MSP3TXzzbLTFf+koRFQiaYmerRZUtK4=
github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20231013072415-eec017435467/go.mod h1:G384omH7cXgm90xXR7xpHvsKG7vdBaDuz4To6GpTHUU=
github.com/crypto-org-chain/ethermint v0.6.1-0.20231027030935-291bfa0458c4 h1:uLaq7qqIYJ2tJ5fQE5EBvqAgvM5Y4jWbz9V4AURwMGI=
github.com/crypto-org-chain/ethermint v0.6.1-0.20231027030935-291bfa0458c4/go.mod h1:rbAKU2rftDobCIoCiol3SO+bTqw2cERu9TEki7PvfK0=
github.com/crypto-org-chain/ethermint v0.6.1-0.20231101080732-b9078abfe0fd h1:8AWwJrxYtQxoZ1rrM9+w6MLScVe6LzskRo8UF9ep7Qs=
github.com/crypto-org-chain/ethermint v0.6.1-0.20231101080732-b9078abfe0fd/go.mod h1:rbAKU2rftDobCIoCiol3SO+bTqw2cERu9TEki7PvfK0=
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 @@ -216,8 +216,8 @@ schema = 3
hash = "sha256-GgcReGsIIuBE2TabDYqDO9sBGogdVr9RSh4arQzdPnE="
replaced = "github.com/evmos/go-ethereum"
[mod."github.com/evmos/ethermint"]
version = "v0.6.1-0.20231027030935-291bfa0458c4"
hash = "sha256-T+iQ9tSyGTvJn7wSIFCFWqUeU9KUk3Ml4v1rgC9FENk="
version = "v0.6.1-0.20231101080732-b9078abfe0fd"
hash = "sha256-FlKoOdJbNqQfloOxV5AGd5TIm3VLjoZW8YOLnuJY7FY="
replaced = "github.com/crypto-org-chain/ethermint"
[mod."github.com/felixge/httpsnoop"]
version = "v1.0.2"
Expand Down
5 changes: 3 additions & 2 deletions x/cronos/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/evmos/ethermint/x/evm/statedb"
evmtypes "github.com/evmos/ethermint/x/evm/types"

"github.com/crypto-org-chain/cronos/v2/x/cronos/types"
Expand Down Expand Up @@ -37,8 +38,8 @@ func (k Keeper) CallEVM(ctx sdk.Context, to *common.Address, data []byte, value
return nil, nil, err
}

// if the call originally comes from an ibc-in precompiled message, re-emit the logs into the original stateDB.
if stateDB, ok := ctx.Value(types.StateDBContextKey).(vm.StateDB); ok {
// if the call is from an precompiled contract call, then re-emit the logs into the original stateDB.
if stateDB, ok := ctx.Value(statedb.StateDBContextKey).(vm.StateDB); ok {
for _, l := range ret.Logs {
stateDB.AddLog(l.ToEthereum())
}

Check warning on line 45 in x/cronos/keeper/evm.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/keeper/evm.go#L43-L45

Added lines #L43 - L45 were not covered by tests
Expand Down
6 changes: 1 addition & 5 deletions x/cronos/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,7 @@ func (k Keeper) onPacketResult(
}
gasLimit := k.GetParams(ctx).MaxCallbackGas
_, _, err = k.CallEVM(ctx, &contractAddr, data, big.NewInt(0), gasLimit)
if err != nil {
return err
}

return nil
return err
}

func (k Keeper) IBCOnAcknowledgementPacketCallback(
Expand Down
2 changes: 0 additions & 2 deletions x/cronos/keeper/precompiles/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/crypto-org-chain/cronos/v2/x/cronos/types"
"github.com/ethereum/go-ethereum/common"
"github.com/evmos/ethermint/x/evm/statedb"
)
Expand Down Expand Up @@ -46,7 +45,6 @@ func exec[Req any, PReq interface {
var res Resp
if err := stateDB.ExecuteNativeAction(contract, converter, func(ctx sdk.Context) error {
var err error
ctx = ctx.WithValue(types.StateDBContextKey, stateDB)
res, err = action(ctx, msg)
return err
}); err != nil {
Expand Down
2 changes: 0 additions & 2 deletions x/cronos/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const (
prefixContractToDenom
paramsKey
prefixAdminToPermissions

StateDBContextKey = "statedb"
)

// KVStore key prefixes
Expand Down

0 comments on commit 9cb8be6

Please sign in to comment.