@@ -13,6 +13,8 @@ import (
1313 "github.com/ethereum/go-ethereum/params"
1414
1515 authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
16+ ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
17+ channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
1618 cronosevents "github.com/crypto-org-chain/cronos/v2/x/cronos/events"
1719 "github.com/crypto-org-chain/cronos/v2/x/cronos/events/bindings/cosmos/precompile/relayer"
1820 "github.com/crypto-org-chain/cronos/v2/x/cronos/types"
@@ -58,6 +60,10 @@ const (
5860 UpdateClientAndAcknowledgement = "updateClientAndAcknowledgement"
5961 UpdateClientAndTimeout = "updateClientAndTimeout"
6062 UpdateClientAndTimeoutOnClose = "updateClientAndTimeoutOnClose"
63+
64+ GasForUpdateClient = 111894
65+ GasWhenReceiverChainIsSource = 51705
66+ GasWhenReceiverChainIsNotSource = 144025
6167)
6268
6369func init () {
@@ -93,7 +99,7 @@ func init() {
9399 case ChannelCloseConfirm :
94100 relayerGasRequiredByMethod [methodID ] = 31199
95101 case RecvPacket :
96- relayerGasRequiredByMethod [methodID ] = 144025
102+ relayerGasRequiredByMethod [methodID ] = GasWhenReceiverChainIsNotSource
97103 case Acknowledgement :
98104 relayerGasRequiredByMethod [methodID ] = 61781
99105 case Timeout :
@@ -107,7 +113,7 @@ func init() {
107113 case UpdateClientAndChannelOpenConfirm :
108114 relayerGasRequiredByMethod [methodID ] = 132734
109115 case UpdateClientAndRecvPacket :
110- relayerGasRequiredByMethod [methodID ] = 257120
116+ relayerGasRequiredByMethod [methodID ] = GasForUpdateClient + GasWhenReceiverChainIsNotSource
111117 case UpdateClientAndConnectionOpenInit :
112118 relayerGasRequiredByMethod [methodID ] = 131649
113119 case UpdateClientAndConnectionOpenAck :
@@ -165,6 +171,34 @@ func (bc *RelayerContract) RequiredGas(input []byte) (gas uint64) {
165171 var methodID [4 ]byte
166172 copy (methodID [:], input [:4 ])
167173 requiredGas , ok := relayerGasRequiredByMethod [methodID ]
174+ method , err := irelayerABI .MethodById (methodID [:])
175+ if err != nil {
176+ panic (err )
177+ }
178+ if method .Name == RecvPacket || method .Name == UpdateClientAndRecvPacket {
179+ args , err := method .Inputs .Unpack (input [4 :])
180+ if err != nil {
181+ panic (err )
182+ }
183+ i := args [0 ].([]byte )
184+ if method .Name == UpdateClientAndRecvPacket {
185+ i = args [1 ].([]byte )
186+ }
187+ var msg channeltypes.MsgRecvPacket
188+ if err = bc .cdc .Unmarshal (i , & msg ); err != nil {
189+ panic (err )
190+ }
191+ var data ibctransfertypes.FungibleTokenPacketData
192+ if err = ibctransfertypes .ModuleCdc .UnmarshalJSON (msg .Packet .GetData (), & data ); err != nil {
193+ panic (err )
194+ }
195+ if ibctransfertypes .ReceiverChainIsSource (msg .Packet .GetSourcePort (), msg .Packet .GetSourceChannel (), data .Denom ) {
196+ requiredGas = GasWhenReceiverChainIsSource
197+ if method .Name == UpdateClientAndRecvPacket {
198+ requiredGas += GasForUpdateClient
199+ }
200+ }
201+ }
168202 intrinsicGas , _ := core .IntrinsicGas (input , nil , false , bc .isHomestead , bc .isIstanbul , bc .isShanghai )
169203 defer func () {
170204 methodName := relayerMethodNamedByMethod [methodID ]
0 commit comments