Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/zeta-chain/node into fea…
Browse files Browse the repository at this point in the history
…t-tx-disable-fast-confirmation
  • Loading branch information
ws4charlie committed Feb 19, 2025
2 parents 66b0745 + ab3e5e1 commit 7db879d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 57 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [3534] (https://github.com/zeta-chain/node/pull/3534) - Add Sui deposit & depositAndCall
* [3541](https://github.com/zeta-chain/node/pull/3541) - implement `MsgUpdateZRC20Name` to update the name or symbol of a ZRC20 token
* [3520](https://github.com/zeta-chain/node/pull/3520) - SPL withdraw and call integration
* [3439](https://github.com/zeta-chain/node/pull/3439) - use protocol contracts V2 with TON deposits
* [3522](https://github.com/zeta-chain/node/pull/3522) - add `MsgDisableFastConfirmation` to disable fast confirmation. This message can be triggered by the emergency policy.

### Refactor
Expand Down
5 changes: 1 addition & 4 deletions e2e/runner/ton.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,9 @@ func (r *E2ERunner) TONDepositAndCall(
}

filter := func(cctx *cctypes.CrossChainTx) bool {
memo := zevmRecipient.Bytes()
memo = append(memo, callData...)

return cctx.InboundParams.SenderChainId == chain.ChainId &&
cctx.InboundParams.Sender == sender.GetAddress().ToRaw() &&
cctx.RelayedMessage == hex.EncodeToString(memo)
cctx.RelayedMessage == hex.EncodeToString(callData)
}

// Wait for cctx
Expand Down
16 changes: 0 additions & 16 deletions pkg/contracts/ton/gateway_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ type Deposit struct {
Recipient eth.Address
}

// Memo casts deposit to memo bytes
func (d Deposit) Memo() []byte {
return d.Recipient.Bytes()
}

// AsBody casts struct as internal message body.
func (d Deposit) AsBody() (*boc.Cell, error) {
b := boc.NewCell()
Expand All @@ -75,17 +70,6 @@ type DepositAndCall struct {
CallData []byte
}

// Memo casts deposit to call to memo bytes
func (d DepositAndCall) Memo() []byte {
recipient := d.Recipient.Bytes()
out := make([]byte, 0, len(recipient)+len(d.CallData))

out = append(out, recipient...)
out = append(out, d.CallData...)

return out
}

// AsBody casts struct to internal message body.
func (d DepositAndCall) AsBody() (*boc.Cell, error) {
b := boc.NewCell()
Expand Down
2 changes: 0 additions & 2 deletions testutil/sample/ton_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func TestTONSamples(t *testing.T) {
require.Equal(t, int(d.Amount.Uint64()), int(d2.Amount.Uint64()))
require.Equal(t, d.Sender.ToRaw(), d2.Sender.ToRaw())
require.Equal(t, d.Recipient.Hex(), d2.Recipient.Hex())
require.Equal(t, d.Memo(), d2.Memo())
})

t.Run("Deposit and call", func(t *testing.T) {
Expand Down Expand Up @@ -88,7 +87,6 @@ func TestTONSamples(t *testing.T) {
require.Equal(t, d.Sender.ToRaw(), d2.Sender.ToRaw())
require.Equal(t, d.Recipient.Hex(), d2.Recipient.Hex())
require.Equal(t, d.CallData, d2.CallData)
require.Equal(t, d.Memo(), d2.Memo())
})

}
65 changes: 42 additions & 23 deletions zetaclient/chains/ton/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ func (ob *Observer) ProcessInboundTrackers(ctx context.Context) error {
return nil
}

// inboundData represents extract data from a TON inbound deposit
type inboundData struct {
sender string
amount math.Uint
receiver string
message []byte
isContractCall bool
}

// Sends PostVoteInbound to zetacore
func (ob *Observer) voteInbound(ctx context.Context, tx *toncontracts.Transaction) (string, error) {
// noop
Expand All @@ -193,44 +202,52 @@ func (ob *Observer) voteInbound(ctx context.Context, tx *toncontracts.Transactio
return "", errors.Wrapf(err, "unable to get block header %s", tx.BlockID.String())
}

sender, amount, memo, err := extractInboundData(tx)
inboundData, err := extractInboundData(tx)
if err != nil {
return "", err
}

seqno := blockHeader.MinRefMcSeqno

return ob.voteDeposit(ctx, tx, sender, amount, memo, seqno)
return ob.voteDeposit(ctx, tx, inboundData, seqno)
}

// extractInboundData parses Gateway tx into deposit (TON sender, amount, memo)
func extractInboundData(tx *toncontracts.Transaction) (string, math.Uint, []byte, error) {
func extractInboundData(tx *toncontracts.Transaction) (inboundData, error) {
switch tx.Operation {
case toncontracts.OpDeposit:
d, err := tx.Deposit()
if err != nil {
return "", math.NewUint(0), nil, err
return inboundData{}, err
}

return d.Sender.ToRaw(), d.Amount, d.Memo(), nil
return inboundData{
sender: d.Sender.ToRaw(),
amount: d.Amount,
receiver: d.Recipient.Hex(),
message: []byte{},
isContractCall: false,
}, nil
case toncontracts.OpDepositAndCall:
d, err := tx.DepositAndCall()
if err != nil {
return "", math.NewUint(0), nil, err
return inboundData{}, err
}

return d.Sender.ToRaw(), d.Amount, d.Memo(), nil
return inboundData{
sender: d.Sender.ToRaw(),
amount: d.Amount,
receiver: d.Recipient.Hex(),
message: d.CallData,
isContractCall: true,
}, nil
default:
return "", math.NewUint(0), nil, fmt.Errorf("unknown operation %d", tx.Operation)
return inboundData{}, fmt.Errorf("unknown operation %d", tx.Operation)
}
}

func (ob *Observer) voteDeposit(
ctx context.Context,
tx *toncontracts.Transaction,
sender string,
amount math.Uint,
memo []byte,
inboundData inboundData,
seqno uint32,
) (string, error) {
const (
Expand All @@ -246,25 +263,27 @@ func (ob *Observer) voteDeposit(
inboundHash = liteapi.TransactionHashToString(tx.Lt, ton.Bits256(tx.Hash()))
)

// TODO: use protocol contract v2 for deposit
// https://github.com/zeta-chain/node/issues/2967

msg := zetacore.GetInboundVoteMessage(
sender,
// create the inbound message
msg := types.NewMsgVoteInbound(
operatorAddress.String(),
inboundData.sender,
ob.Chain().ChainId,
sender,
sender,
inboundData.sender,
inboundData.receiver,
ob.ZetacoreClient().Chain().ChainId,
amount,
hex.EncodeToString(memo),
inboundData.amount,
hex.EncodeToString(inboundData.message),
inboundHash,
uint64(seqno),
gasLimit,
coinType,
asset,
operatorAddress.String(),
eventIndex,
types.ProtocolContractVersion_V2,
false, // not used
types.InboundStatus_SUCCESS,
types.ConfirmationMode_SAFE,
types.WithCrossChainCall(inboundData.isContractCall),
)

return ob.PostVoteInbound(ctx, msg, retryGasLimit)
Expand Down
20 changes: 8 additions & 12 deletions zetaclient/chains/ton/observer/inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package observer

import (
"encoding/hex"
"fmt"
"testing"

"github.com/pkg/errors"
Expand Down Expand Up @@ -163,7 +162,9 @@ func TestInbound(t *testing.T) {

assert.Equal(t, "", cctx.Asset)
assert.Equal(t, deposit.Amount.Uint64(), cctx.Amount.Uint64())
assert.Equal(t, hex.EncodeToString(deposit.Recipient.Bytes()), cctx.Message)
assert.Equal(t, "", cctx.Message)
assert.Equal(t, deposit.Recipient.Hex(), cctx.Receiver)
assert.False(t, cctx.IsCrossChainCall)

// Check hash & block height
expectedHash := liteapi.TransactionHashToString(depositTX.Lt, txHash(depositTX))
Expand Down Expand Up @@ -225,13 +226,9 @@ func TestInbound(t *testing.T) {

assert.Equal(t, "", cctx.Asset)
assert.Equal(t, depositAndCall.Amount.Uint64(), cctx.Amount.Uint64())

expectedMessage := hex.EncodeToString(append(
depositAndCall.Recipient.Bytes(),
[]byte(callData)...,
))

assert.Equal(t, expectedMessage, cctx.Message)
assert.Equal(t, hex.EncodeToString([]byte(callData)), cctx.Message)
assert.Equal(t, depositAndCall.Recipient.Hex(), cctx.Receiver)
assert.True(t, cctx.IsCrossChainCall)

// Check hash & block height
expectedHash := liteapi.TransactionHashToString(depositAndCallTX.Lt, txHash(depositAndCallTX))
Expand Down Expand Up @@ -436,9 +433,8 @@ func TestInboundTracker(t *testing.T) {
vote := ts.votesBag[0]
assert.Equal(t, deposit.Amount, vote.Amount)
assert.Equal(t, deposit.Sender.ToRaw(), vote.Sender)

// zevm recipient bytes == memo bytes
assert.Equal(t, fmt.Sprintf("%x", deposit.Recipient), vote.Message)
assert.Equal(t, "", vote.Message)
assert.Equal(t, deposit.Recipient.Hex(), vote.Receiver)
}

func txHash(tx ton.Transaction) ton.Bits256 {
Expand Down

0 comments on commit 7db879d

Please sign in to comment.