Skip to content

Commit

Permalink
perf: remove gas limit field when ibc call (PundiAI#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir-code authored May 9, 2024
1 parent 3972a87 commit 8342522
Show file tree
Hide file tree
Showing 8 changed files with 508 additions and 395 deletions.
22 changes: 22 additions & 0 deletions proto/fx/ibc/applications/transfer/v1/call.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";
package fx.ibc.applications.transfer.v1;

import "gogoproto/gogo.proto";

option go_package = "github.com/functionx/fx-core/x/ibc/applications/transfer/types";

enum IbcCallType {
option (gogoproto.goproto_enum_prefix) = false;

IBC_CALL_TYPE_UNSPECIFIED = 0;
IBC_CALL_TYPE_EVM = 1;
}

message IbcCallEvmPacket {
string to = 1;
string data = 2;
string value = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
17 changes: 0 additions & 17 deletions proto/fx/ibc/applications/transfer/v1/transfer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,3 @@ message FungibleTokenPacketData {
// optional memo
string memo = 7;
}

enum IbcCallType {
option (gogoproto.goproto_enum_prefix) = false;

IBC_CALL_TYPE_UNSPECIFIED = 0;
IBC_CALL_TYPE_EVM = 1;
}

message IbcCallEvmPacket {
string to = 1;
string value = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
uint64 gas_limit = 3;
string message = 4;
}
5 changes: 3 additions & 2 deletions x/ibc/applications/transfer/keeper/ibc_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ func (k Keeper) HandlerIbcCall(ctx sdk.Context, sourcePort, sourceChannel string
hexSender := types.IntermediateSender(sourcePort, sourceChannel, data.Sender)
return k.HandlerIbcCallEvm(ctx, hexSender, packet)
default:
return types.ErrMemoNotSupport.Wrapf("invalid call type %s", mp.GetType())
return errorsmod.Wrapf(types.ErrMemoNotSupport, "invalid call type %s", mp.GetType())
}
}

func (k Keeper) HandlerIbcCallEvm(ctx sdk.Context, sender common.Address, evmPacket *types.IbcCallEvmPacket) error {
limit := ctx.ConsensusParams().GetBlock().GetMaxGas()
evmErr, evmResult := "", false
defer func() {
attrs := []sdk.Attribute{
Expand All @@ -44,7 +45,7 @@ func (k Keeper) HandlerIbcCallEvm(ctx sdk.Context, sender common.Address, evmPac
ctx.EventManager().EmitEvents(sdk.Events{sdk.NewEvent(types.EventTypeIBCCall, attrs...)})
}()
txResp, err := k.evmKeeper.CallEVM(ctx, sender,
evmPacket.MustGetToAddr(), evmPacket.Value.BigInt(), evmPacket.GasLimit, evmPacket.MustGetMessage(), true)
evmPacket.GetToAddress(), evmPacket.Value.BigInt(), uint64(limit), evmPacket.MustGetMessage(), true)
if err != nil {
evmErr = err.Error()
return err
Expand Down
9 changes: 5 additions & 4 deletions x/ibc/applications/transfer/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
ibctesting "github.com/cosmos/ibc-go/v6/testing"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/abci/types"
tmrand "github.com/tendermint/tendermint/libs/rand"

"github.com/functionx/fx-core/v7/contract"
Expand Down Expand Up @@ -419,10 +420,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
suite.NoError(ibcCallBaseAcc.SetSequence(0))
suite.GetApp(suite.chainA.App).AccountKeeper.SetAccount(suite.chainA.GetContext(), ibcCallBaseAcc)
evmPacket := fxtransfertypes.IbcCallEvmPacket{
To: common.BigToAddress(big.NewInt(0)).String(),
Value: sdkmath.ZeroInt(),
GasLimit: 300000,
Message: "",
To: common.BigToAddress(big.NewInt(0)).String(),
Value: sdkmath.ZeroInt(),
Data: "",
}
cdc := suite.GetApp(suite.chainA.App).AppCodec()
bz, err := cdc.MarshalInterfaceJSON(&evmPacket)
Expand Down Expand Up @@ -453,6 +453,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
tc.malleate(&packet)

cacheCtx, writeFn := suite.chainA.GetContext().CacheContext()
cacheCtx = cacheCtx.WithConsensusParams(&types.ConsensusParams{Block: &types.BlockParams{MaxGas: 5000000}})
ackI := fxIBCMiddleware.OnRecvPacket(cacheCtx, packet, nil)
if ackI == nil || ackI.Success() {
// write application state changes for asynchronous and successful acknowledgements
Expand Down
Loading

0 comments on commit 8342522

Please sign in to comment.