@@ -10,20 +10,25 @@ import (
10
10
"github.com/zeta-chain/node/pkg/chains"
11
11
"github.com/zeta-chain/node/pkg/coin"
12
12
toncontracts "github.com/zeta-chain/node/pkg/contracts/ton"
13
- cc "github.com/zeta-chain/node/x/crosschain/types"
13
+ cctypes "github.com/zeta-chain/node/x/crosschain/types"
14
14
"github.com/zeta-chain/node/zetaclient/chains/interfaces"
15
15
"github.com/zeta-chain/node/zetaclient/chains/ton/liteapi"
16
- gasconst "github.com/zeta-chain/node/zetaclient/zetacore"
16
+ "github.com/zeta-chain/node/zetaclient/logs"
17
+ "github.com/zeta-chain/node/zetaclient/zetacore"
17
18
)
18
19
20
+ // https://tonscan.com/config-parameters (N21: "Computation costs")
21
+ // This might changes in the future by TON's gov proposal (very unlikely though)
22
+ const maxGasLimit = 1_000_000
23
+
19
24
type outbound struct {
20
25
tx * toncontracts.Transaction
21
26
receiveStatus chains.ReceiveStatus
22
27
nonce uint64
23
28
}
24
29
25
30
// VoteOutboundIfConfirmed checks outbound status and returns (continueKeysign, error)
26
- func (ob * Observer ) VoteOutboundIfConfirmed (ctx context.Context , cctx * cc .CrossChainTx ) (bool , error ) {
31
+ func (ob * Observer ) VoteOutboundIfConfirmed (ctx context.Context , cctx * cctypes .CrossChainTx ) (bool , error ) {
27
32
nonce := cctx .GetCurrentOutboundParam ().TssNonce
28
33
29
34
outboundRes , exists := ob .getOutboundByNonce (nonce )
@@ -39,8 +44,7 @@ func (ob *Observer) VoteOutboundIfConfirmed(ctx context.Context, cctx *cc.CrossC
39
44
// TODO: Add compliance check
40
45
// https://github.com/zeta-chain/node/issues/2916
41
46
42
- txHash := liteapi .TransactionToHashString (outboundRes .tx .Transaction )
43
- if err = ob .postVoteOutbound (ctx , cctx , withdrawal , txHash , outboundRes .receiveStatus ); err != nil {
47
+ if err = ob .postVoteOutbound (ctx , cctx , outboundRes , withdrawal ); err != nil {
44
48
return false , errors .Wrap (err , "unable to post vote" )
45
49
}
46
50
@@ -95,7 +99,7 @@ func (ob *Observer) ProcessOutboundTrackers(ctx context.Context) error {
95
99
96
100
// processOutboundTracker checks TON tx and stores it in memory for further processing
97
101
// by VoteOutboundIfConfirmed.
98
- func (ob * Observer ) processOutboundTracker (ctx context.Context , cctx * cc .CrossChainTx , txHash string ) error {
102
+ func (ob * Observer ) processOutboundTracker (ctx context.Context , cctx * cctypes .CrossChainTx , txHash string ) error {
99
103
if cctx .InboundParams .CoinType != coin .CoinType_Gas {
100
104
return errors .New ("only gas cctxs are supported" )
101
105
}
@@ -204,73 +208,67 @@ func (ob *Observer) setOutboundByNonce(o outbound) {
204
208
205
209
func (ob * Observer ) postVoteOutbound (
206
210
ctx context.Context ,
207
- cctx * cc.CrossChainTx ,
211
+ cctx * cctypes.CrossChainTx ,
212
+ outboundRes outbound ,
208
213
w toncontracts.Withdrawal ,
209
- txHash string ,
210
- status chains.ReceiveStatus ,
211
214
) error {
212
- // I. Gas
213
- // TON implements a different tx fee model. Basically, each operation in our Gateway has a
214
- // tx_fee(operation) which is based on hard-coded gas values per operation
215
- // multiplied by the current gas fees on-chain. Each withdrawal tx takes gas directly
216
- // from the Gateway i.e. gw pays tx fees for itself.
217
- //
218
- // - Gas price is stores in zetacore thanks to Observer.postGasPrice()
219
- // - Gas limit should be hardcoded in TON ZRC-20
220
- //
221
- // II. Block height
222
- // TON doesn't sequential block height because different txs might end up in different shard chains
223
- // tlb.BlockID is essentially a workchain+shard+seqno tuple. We can't use it as a block height. Thus let's use 0.
224
- // Note that for the sake of gas tracking, we use masterchain block height (not applicable here).
225
- const (
226
- outboundGasUsed = 0
227
- outboundGasPrice = 0
228
- outboundGasLimit = 0
229
- outboundBlockHeight = 0
230
- )
215
+ // There's no sequential block height. Also, different txs might end up in different shards.
216
+ // tlb.BlockID is essentially a workchain+shard+seqno tuple. We can't use it as a block height, thus zero.
217
+ const tonBlockHeight = 0
231
218
232
219
var (
233
220
chainID = ob .Chain ().ChainId
221
+ txHash = liteapi .TransactionToHashString (outboundRes .tx .Transaction )
234
222
nonce = cctx .GetCurrentOutboundParam ().TssNonce
235
223
signerAddress = ob .ZetacoreClient ().GetKeys ().GetOperatorAddress ()
236
224
coinType = cctx .InboundParams .CoinType
237
225
)
238
226
239
- msg := cc .NewMsgVoteOutbound (
227
+ gasPrice , ok := ob .getLatestGasPrice ()
228
+
229
+ // should not happen
230
+ if ! ok {
231
+ return errors .New ("gas price is not set (call PostGasPrice first)" )
232
+ }
233
+
234
+ // #nosec G115 len always in range
235
+ gasPriceInt := math .NewInt (int64 (gasPrice ))
236
+
237
+ msg := cctypes .NewMsgVoteOutbound (
240
238
signerAddress .String (),
241
239
cctx .Index ,
242
240
txHash ,
243
- outboundBlockHeight ,
244
- outboundGasUsed ,
245
- math . NewInt ( outboundGasPrice ) ,
246
- outboundGasLimit ,
241
+ tonBlockHeight ,
242
+ outboundRes . tx . GasUsed (). Uint64 () ,
243
+ gasPriceInt ,
244
+ maxGasLimit ,
247
245
w .Amount ,
248
- status ,
246
+ outboundRes . receiveStatus ,
249
247
chainID ,
250
248
nonce ,
251
249
coinType ,
252
- cc .ConfirmationMode_SAFE ,
250
+ cctypes .ConfirmationMode_SAFE ,
253
251
)
254
252
255
- const gasLimit = gasconst .PostVoteOutboundGasLimit
253
+ const gasLimit = zetacore .PostVoteOutboundGasLimit
256
254
257
255
var retryGasLimit uint64
258
256
if msg .Status == chains .ReceiveStatus_failed {
259
- retryGasLimit = gasconst .PostVoteOutboundRevertGasLimit
257
+ retryGasLimit = zetacore .PostVoteOutboundRevertGasLimit
260
258
}
261
259
262
260
log := ob .Logger ().Outbound .With ().
263
- Uint64 ("outbound.nonce" , nonce ).
264
- Str ("outbound.outbound_tx_hash" , txHash ).
261
+ Uint64 (logs . FieldNonce , nonce ).
262
+ Str (logs . FieldTx , txHash ).
265
263
Logger ()
266
264
267
265
zetaTxHash , ballot , err := ob .ZetacoreClient ().PostVoteOutbound (ctx , gasLimit , retryGasLimit , msg )
268
- if err != nil {
269
- log .Error ().Err (err ).Msg ("PostVoteOutbound: error posting vote" )
270
- return err
271
- }
272
266
273
- if zetaTxHash != "" {
267
+ switch {
268
+ case err != nil :
269
+ log .Error ().Err (err ).Msg ("PostVoteOutbound: failed to post vote" )
270
+ return err
271
+ case zetaTxHash != "" :
274
272
log .Info ().
275
273
Str ("outbound.vote_tx_hash" , zetaTxHash ).
276
274
Str ("outbound.ballot_id" , ballot ).
0 commit comments