@@ -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/v8/modules/apps/transfer/types"
17
+ channeltypes "github.com/cosmos/ibc-go/v8/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"
@@ -26,38 +28,27 @@ var (
26
28
)
27
29
28
30
const (
29
- CreateClient = "createClient"
30
- UpdateClient = "updateClient"
31
- UpgradeClient = "upgradeClient"
32
- SubmitMisbehaviour = "submitMisbehaviour"
33
- ConnectionOpenInit = "connectionOpenInit"
34
- ConnectionOpenTry = "connectionOpenTry"
35
- ConnectionOpenAck = "connectionOpenAck"
36
- ConnectionOpenConfirm = "connectionOpenConfirm"
37
- ChannelOpenInit = "channelOpenInit"
38
- ChannelOpenTry = "channelOpenTry"
39
- ChannelOpenAck = "channelOpenAck"
40
- ChannelOpenConfirm = "channelOpenConfirm"
41
- ChannelCloseInit = "channelCloseInit"
42
- ChannelCloseConfirm = "channelCloseConfirm"
43
- RecvPacket = "recvPacket"
44
- Acknowledgement = "acknowledgement"
45
- Timeout = "timeout"
46
- TimeoutOnClose = "timeoutOnClose"
47
- UpdateClientAndConnectionOpenInit = "updateClientAndConnectionOpenInit"
48
- UpdateClientAndConnectionOpenTry = "updateClientAndConnectionOpenTry"
49
- UpdateClientAndConnectionOpenAck = "updateClientAndConnectionOpenAck"
50
- UpdateClientAndConnectionOpenConfirm = "updateClientAndConnectionOpenConfirm"
51
- UpdateClientAndChannelOpenInit = "updateClientAndChannelOpenInit"
52
- UpdateClientAndChannelOpenTry = "updateClientAndChannelOpenTry"
53
- UpdateClientAndChannelOpenAck = "updateClientAndChannelOpenAck"
54
- UpdateClientAndChannelCloseInit = "updateClientAndChannelCloseInit"
55
- UpdateClientAndChannelCloseConfirm = "updateClientAndChannelCloseConfirm"
56
- UpdateClientAndChannelOpenConfirm = "updateClientAndChannelOpenConfirm"
57
- UpdateClientAndRecvPacket = "updateClientAndRecvPacket"
58
- UpdateClientAndAcknowledgement = "updateClientAndAcknowledgement"
59
- UpdateClientAndTimeout = "updateClientAndTimeout"
60
- UpdateClientAndTimeoutOnClose = "updateClientAndTimeoutOnClose"
31
+ CreateClient = "createClient"
32
+ UpdateClient = "updateClient"
33
+ UpgradeClient = "upgradeClient"
34
+ SubmitMisbehaviour = "submitMisbehaviour"
35
+ ConnectionOpenInit = "connectionOpenInit"
36
+ ConnectionOpenTry = "connectionOpenTry"
37
+ ConnectionOpenAck = "connectionOpenAck"
38
+ ConnectionOpenConfirm = "connectionOpenConfirm"
39
+ ChannelOpenInit = "channelOpenInit"
40
+ ChannelOpenTry = "channelOpenTry"
41
+ ChannelOpenAck = "channelOpenAck"
42
+ ChannelOpenConfirm = "channelOpenConfirm"
43
+ ChannelCloseInit = "channelCloseInit"
44
+ ChannelCloseConfirm = "channelCloseConfirm"
45
+ RecvPacket = "recvPacket"
46
+ Acknowledgement = "acknowledgement"
47
+ Timeout = "timeout"
48
+ TimeoutOnClose = "timeoutOnClose"
49
+
50
+ GasWhenReceiverChainIsSource = 51705
51
+ GasWhenReceiverChainIsNotSource = 144025
61
52
)
62
53
63
54
func init () {
@@ -93,35 +84,11 @@ func init() {
93
84
case ChannelCloseConfirm :
94
85
relayerGasRequiredByMethod [methodID ] = 31199
95
86
case RecvPacket :
96
- relayerGasRequiredByMethod [methodID ] = 144025
87
+ relayerGasRequiredByMethod [methodID ] = GasWhenReceiverChainIsNotSource
97
88
case Acknowledgement :
98
89
relayerGasRequiredByMethod [methodID ] = 61781
99
90
case Timeout :
100
91
relayerGasRequiredByMethod [methodID ] = 104283
101
- case UpdateClientAndConnectionOpenTry :
102
- relayerGasRequiredByMethod [methodID ] = 150362
103
- case UpdateClientAndConnectionOpenConfirm :
104
- relayerGasRequiredByMethod [methodID ] = 124820
105
- case UpdateClientAndChannelOpenTry :
106
- relayerGasRequiredByMethod [methodID ] = 182676
107
- case UpdateClientAndChannelOpenConfirm :
108
- relayerGasRequiredByMethod [methodID ] = 132734
109
- case UpdateClientAndRecvPacket :
110
- relayerGasRequiredByMethod [methodID ] = 257120
111
- case UpdateClientAndConnectionOpenInit :
112
- relayerGasRequiredByMethod [methodID ] = 131649
113
- case UpdateClientAndConnectionOpenAck :
114
- relayerGasRequiredByMethod [methodID ] = 141558
115
- case UpdateClientAndChannelOpenInit :
116
- relayerGasRequiredByMethod [methodID ] = 180815
117
- case UpdateClientAndChannelOpenAck :
118
- relayerGasRequiredByMethod [methodID ] = 133834
119
- case UpdateClientAndChannelCloseConfirm :
120
- relayerGasRequiredByMethod [methodID ] = 143366
121
- case UpdateClientAndTimeout :
122
- relayerGasRequiredByMethod [methodID ] = 230638
123
- case UpdateClientAndAcknowledgement :
124
- relayerGasRequiredByMethod [methodID ] = 174785
125
92
default :
126
93
relayerGasRequiredByMethod [methodID ] = 100000
127
94
}
@@ -165,6 +132,28 @@ func (bc *RelayerContract) RequiredGas(input []byte) (gas uint64) {
165
132
var methodID [4 ]byte
166
133
copy (methodID [:], input [:4 ])
167
134
requiredGas , ok := relayerGasRequiredByMethod [methodID ]
135
+ method , err := irelayerABI .MethodById (methodID [:])
136
+ if err != nil {
137
+ panic (err )
138
+ }
139
+ if method .Name == RecvPacket {
140
+ args , err := method .Inputs .Unpack (input [4 :])
141
+ if err != nil {
142
+ panic (err )
143
+ }
144
+ i := args [0 ].([]byte )
145
+ var msg channeltypes.MsgRecvPacket
146
+ if err = bc .cdc .Unmarshal (i , & msg ); err != nil {
147
+ panic (err )
148
+ }
149
+ var data ibctransfertypes.FungibleTokenPacketData
150
+ if err = ibctransfertypes .ModuleCdc .UnmarshalJSON (msg .Packet .GetData (), & data ); err != nil {
151
+ panic (err )
152
+ }
153
+ if ibctransfertypes .ReceiverChainIsSource (msg .Packet .GetSourcePort (), msg .Packet .GetSourceChannel (), data .Denom ) {
154
+ requiredGas = GasWhenReceiverChainIsSource
155
+ }
156
+ }
168
157
intrinsicGas , _ := core .IntrinsicGas (input , nil , false , bc .isHomestead , bc .isIstanbul , bc .isShanghai )
169
158
defer func () {
170
159
methodName := relayerMethodNamedByMethod [methodID ]
@@ -211,9 +200,6 @@ func (bc *RelayerContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool
211
200
input : input ,
212
201
converter : converter ,
213
202
}
214
- if len (args ) > 1 {
215
- e .input2 = args [1 ].([]byte )
216
- }
217
203
switch method .Name {
218
204
case CreateClient :
219
205
res , err = exec (e , bc .ibcKeeper .CreateClient )
@@ -249,34 +235,6 @@ func (bc *RelayerContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool
249
235
res , err = exec (e , bc .ibcKeeper .Timeout )
250
236
case TimeoutOnClose :
251
237
res , err = exec (e , bc .ibcKeeper .TimeoutOnClose )
252
- case UpdateClientAndConnectionOpenInit :
253
- res , err = execMultiple (e , bc .ibcKeeper .UpdateClient , bc .ibcKeeper .ConnectionOpenInit )
254
- case UpdateClientAndConnectionOpenTry :
255
- res , err = execMultiple (e , bc .ibcKeeper .UpdateClient , bc .ibcKeeper .ConnectionOpenTry )
256
- case UpdateClientAndConnectionOpenAck :
257
- res , err = execMultiple (e , bc .ibcKeeper .UpdateClient , bc .ibcKeeper .ConnectionOpenAck )
258
- case UpdateClientAndConnectionOpenConfirm :
259
- res , err = execMultiple (e , bc .ibcKeeper .UpdateClient , bc .ibcKeeper .ConnectionOpenConfirm )
260
- case UpdateClientAndChannelOpenInit :
261
- res , err = execMultiple (e , bc .ibcKeeper .UpdateClient , bc .ibcKeeper .ChannelOpenInit )
262
- case UpdateClientAndChannelOpenTry :
263
- res , err = execMultiple (e , bc .ibcKeeper .UpdateClient , bc .ibcKeeper .ChannelOpenTry )
264
- case UpdateClientAndChannelCloseInit :
265
- res , err = execMultiple (e , bc .ibcKeeper .UpdateClient , bc .ibcKeeper .ChannelCloseInit )
266
- case UpdateClientAndChannelCloseConfirm :
267
- res , err = execMultiple (e , bc .ibcKeeper .UpdateClient , bc .ibcKeeper .ChannelCloseConfirm )
268
- case UpdateClientAndChannelOpenAck :
269
- res , err = execMultiple (e , bc .ibcKeeper .UpdateClient , bc .ibcKeeper .ChannelOpenAck )
270
- case UpdateClientAndChannelOpenConfirm :
271
- res , err = execMultiple (e , bc .ibcKeeper .UpdateClient , bc .ibcKeeper .ChannelOpenConfirm )
272
- case UpdateClientAndRecvPacket :
273
- res , err = execMultiple (e , bc .ibcKeeper .UpdateClient , bc .ibcKeeper .RecvPacket )
274
- case UpdateClientAndAcknowledgement :
275
- res , err = execMultiple (e , bc .ibcKeeper .UpdateClient , bc .ibcKeeper .Acknowledgement )
276
- case UpdateClientAndTimeout :
277
- res , err = execMultiple (e , bc .ibcKeeper .UpdateClient , bc .ibcKeeper .Timeout )
278
- case UpdateClientAndTimeoutOnClose :
279
- res , err = execMultiple (e , bc .ibcKeeper .UpdateClient , bc .ibcKeeper .TimeoutOnClose )
280
238
default :
281
239
return nil , fmt .Errorf ("unknown method: %s" , method .Name )
282
240
}
0 commit comments