@@ -13,6 +13,8 @@ import (
13
13
"github.com/ethereum/go-ethereum/params"
14
14
15
15
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"
16
18
cronosevents "github.com/crypto-org-chain/cronos/v2/x/cronos/events"
17
19
"github.com/crypto-org-chain/cronos/v2/x/cronos/events/bindings/cosmos/precompile/relayer"
18
20
"github.com/crypto-org-chain/cronos/v2/x/cronos/types"
@@ -58,6 +60,10 @@ const (
58
60
UpdateClientAndAcknowledgement = "updateClientAndAcknowledgement"
59
61
UpdateClientAndTimeout = "updateClientAndTimeout"
60
62
UpdateClientAndTimeoutOnClose = "updateClientAndTimeoutOnClose"
63
+
64
+ GasForUpdateClient = 111894
65
+ GasWhenReceiverChainIsSource = 51705
66
+ GasWhenReceiverChainIsNotSource = 144025
61
67
)
62
68
63
69
func init () {
@@ -93,7 +99,7 @@ func init() {
93
99
case ChannelCloseConfirm :
94
100
relayerGasRequiredByMethod [methodID ] = 31199
95
101
case RecvPacket :
96
- relayerGasRequiredByMethod [methodID ] = 144025
102
+ relayerGasRequiredByMethod [methodID ] = GasWhenReceiverChainIsNotSource
97
103
case Acknowledgement :
98
104
relayerGasRequiredByMethod [methodID ] = 61781
99
105
case Timeout :
@@ -107,7 +113,7 @@ func init() {
107
113
case UpdateClientAndChannelOpenConfirm :
108
114
relayerGasRequiredByMethod [methodID ] = 132734
109
115
case UpdateClientAndRecvPacket :
110
- relayerGasRequiredByMethod [methodID ] = 257120
116
+ relayerGasRequiredByMethod [methodID ] = GasForUpdateClient + GasWhenReceiverChainIsNotSource
111
117
case UpdateClientAndConnectionOpenInit :
112
118
relayerGasRequiredByMethod [methodID ] = 131649
113
119
case UpdateClientAndConnectionOpenAck :
@@ -165,6 +171,34 @@ func (bc *RelayerContract) RequiredGas(input []byte) (gas uint64) {
165
171
var methodID [4 ]byte
166
172
copy (methodID [:], input [:4 ])
167
173
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
+ }
168
202
intrinsicGas , _ := core .IntrinsicGas (input , nil , false , bc .isHomestead , bc .isIstanbul , bc .isShanghai )
169
203
defer func () {
170
204
methodName := relayerMethodNamedByMethod [methodID ]
0 commit comments