Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Fixes
* [3711](https://github.com/zeta-chain/node/pull/3711) - fix TON call_data parsing
* [3717](https://github.com/zeta-chain/node/pull/3717) - fix solana withdraw and call panic

## v29.0.3

Expand Down
147 changes: 89 additions & 58 deletions zetaclient/chains/solana/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
SolanaMaxComputeBudget = 1_400_000
)

type txGetterT func() (*solana.Transaction, error)

// Signer deals with signing Solana transactions and implements the ChainSigner interface
type Signer struct {
*base.Signer
Expand Down Expand Up @@ -135,68 +137,68 @@
nonce := params.TssNonce
coinType := cctx.InboundParams.CoinType

var tx *solana.Transaction
var fallbackTx *solana.Transaction
var txGetter txGetterT
var fallbackTxGetter txGetterT

Check warning on line 141 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L140-L141

Added lines #L140 - L141 were not covered by tests

switch coinType {
case coin.CoinType_Cmd:
whitelistTx, err := signer.prepareWhitelistTx(ctx, cctx, height)
whitelistTxGetter, err := signer.prepareWhitelistTx(ctx, cctx, height)

Check warning on line 145 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L145

Added line #L145 was not covered by tests
if err != nil {
logger.Error().Err(err).Msgf("TryProcessOutbound: Fail to sign whitelist outbound")
return
}

tx = whitelistTx
txGetter = whitelistTxGetter

Check warning on line 151 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L151

Added line #L151 was not covered by tests

case coin.CoinType_Gas:
if cctx.IsWithdrawAndCall() {
executeTx, err := signer.prepareExecuteTx(ctx, cctx, height, logger)
executeTxGetter, err := signer.prepareExecuteTx(ctx, cctx, height, logger)

Check warning on line 155 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L155

Added line #L155 was not covered by tests
if err != nil {
logger.Error().Err(err).Msgf("TryProcessOutbound: Fail to sign execute outbound")
return
}
incrementNonceTx, err := signer.prepareIncrementNonceTx(ctx, cctx, height, logger)
incrementNonceTxGetter, err := signer.prepareIncrementNonceTx(ctx, cctx, height, logger)

Check warning on line 160 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L160

Added line #L160 was not covered by tests
if err != nil {
logger.Error().Err(err).Msgf("TryProcessOutbound: Fail to sign increment_nonce outbound")
return
}

tx = executeTx
fallbackTx = incrementNonceTx
txGetter = executeTxGetter
fallbackTxGetter = incrementNonceTxGetter

Check warning on line 167 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L166-L167

Added lines #L166 - L167 were not covered by tests
} else {
withdrawTx, err := signer.prepareWithdrawTx(ctx, cctx, height, logger)
withdrawTxGetter, err := signer.prepareWithdrawTx(ctx, cctx, height, logger)

Check warning on line 169 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L169

Added line #L169 was not covered by tests
if err != nil {
logger.Error().Err(err).Msgf("TryProcessOutbound: Fail to sign withdraw outbound")
return
}

tx = withdrawTx
txGetter = withdrawTxGetter

Check warning on line 175 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L175

Added line #L175 was not covered by tests
}

case coin.CoinType_ERC20:
if cctx.IsWithdrawAndCall() {
executeSPLTx, err := signer.prepareExecuteSPLTx(ctx, cctx, height, logger)
executeSPLTxGetter, err := signer.prepareExecuteSPLTx(ctx, cctx, height, logger)

Check warning on line 180 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L180

Added line #L180 was not covered by tests
if err != nil {
logger.Error().Err(err).Msgf("TryProcessOutbound: Fail to sign execute spl outbound")
return
}

incrementNonceTx, err := signer.prepareIncrementNonceTx(ctx, cctx, height, logger)
incrementNonceTxGetter, err := signer.prepareIncrementNonceTx(ctx, cctx, height, logger)

Check warning on line 186 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L186

Added line #L186 was not covered by tests
if err != nil {
logger.Error().Err(err).Msgf("TryProcessOutbound: Fail to sign increment_nonce outbound")
return
}

tx = executeSPLTx
fallbackTx = incrementNonceTx
txGetter = executeSPLTxGetter
fallbackTxGetter = incrementNonceTxGetter

Check warning on line 193 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L192-L193

Added lines #L192 - L193 were not covered by tests
} else {
withdrawSPLTx, err := signer.prepareWithdrawSPLTx(ctx, cctx, height, logger)
withdrawSPLTxGetter, err := signer.prepareWithdrawSPLTx(ctx, cctx, height, logger)

Check warning on line 195 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L195

Added line #L195 was not covered by tests
if err != nil {
logger.Error().Err(err).Msgf("TryProcessOutbound: Fail to sign withdraw spl outbound")
return
}

tx = withdrawSPLTx
txGetter = withdrawSPLTxGetter

Check warning on line 201 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L201

Added line #L201 was not covered by tests
}
default:
logger.Error().
Expand All @@ -213,6 +215,23 @@
// set relayer balance metrics
signer.SetRelayerBalanceMetrics(ctx)

// Get transactions from getters
// This is when the recent block hash timer starts
tx, err := txGetter()
if err != nil {
logger.Error().Err(err).Msgf("TryProcessOutbound: Failed to get transaction")
return
}

Check warning on line 224 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L218-L224

Added lines #L218 - L224 were not covered by tests

var fallbackTx *solana.Transaction
if fallbackTxGetter != nil {
fallbackTx, err = fallbackTxGetter()
if err != nil {
logger.Error().Err(err).Msgf("TryProcessOutbound: Failed to get fallback transaction")
return
}

Check warning on line 232 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L226-L232

Added lines #L226 - L232 were not covered by tests
}

// broadcast the signed tx to the Solana network
signer.broadcastOutbound(ctx, tx, fallbackTx, chainID, nonce, logger, zetacoreClient)
}
Expand Down Expand Up @@ -339,7 +358,7 @@
cctx *types.CrossChainTx,
height uint64,
logger zerolog.Logger,
) (*solana.Transaction, error) {
) (txGetterT, error) {

Check warning on line 361 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L361

Added line #L361 was not covered by tests
params := cctx.GetCurrentOutboundParam()
// compliance check
cancelTx := compliance.IsCctxRestricted(cctx)
Expand All @@ -362,21 +381,23 @@
return nil, err
}

// sign the increment_nonce transaction by relayer key
inst, err := signer.createIncrementNonceInstruction(*msg)
if err != nil {
return nil, errors.Wrap(err, "error creating increment nonce instruction")
}
return func() (*solana.Transaction, error) {
// sign the increment_nonce transaction by relayer key
inst, err := signer.createIncrementNonceInstruction(*msg)
if err != nil {
return nil, errors.Wrap(err, "error creating increment nonce instruction")
}

Check warning on line 389 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L384-L389

Added lines #L384 - L389 were not covered by tests

return signer.signTx(ctx, inst, 0)
return signer.signTx(ctx, inst, 0)

Check warning on line 391 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L391

Added line #L391 was not covered by tests
}, nil
}

func (signer *Signer) prepareWithdrawTx(
ctx context.Context,
cctx *types.CrossChainTx,
height uint64,
logger zerolog.Logger,
) (*solana.Transaction, error) {
) (txGetterT, error) {

Check warning on line 400 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L400

Added line #L400 was not covered by tests
params := cctx.GetCurrentOutboundParam()
// compliance check
cancelTx := compliance.IsCctxRestricted(cctx)
Expand All @@ -399,21 +420,23 @@
return nil, errors.Wrap(err, "createAndSignMsgWithdraw error")
}

// sign the withdraw transaction by relayer key
inst, err := signer.createWithdrawInstruction(*msg)
if err != nil {
return nil, errors.Wrap(err, "error creating withdraw instruction")
}
return func() (*solana.Transaction, error) {
// sign the withdraw transaction by relayer key
inst, err := signer.createWithdrawInstruction(*msg)
if err != nil {
return nil, errors.Wrap(err, "error creating withdraw instruction")
}

Check warning on line 428 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L423-L428

Added lines #L423 - L428 were not covered by tests

return signer.signTx(ctx, inst, 0)
return signer.signTx(ctx, inst, 0)

Check warning on line 430 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L430

Added line #L430 was not covered by tests
}, nil
}

func (signer *Signer) prepareExecuteTx(
ctx context.Context,
cctx *types.CrossChainTx,
height uint64,
logger zerolog.Logger,
) (*solana.Transaction, error) {
) (txGetterT, error) {

Check warning on line 439 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L439

Added line #L439 was not covered by tests
params := cctx.GetCurrentOutboundParam()
// compliance check
cancelTx := compliance.IsCctxRestricted(cctx)
Expand Down Expand Up @@ -462,21 +485,23 @@
return nil, errors.Wrap(err, "createAndSignMsgExecute error")
}

// sign the execute transaction by relayer key
inst, err := signer.createExecuteInstruction(*msgExecute)
if err != nil {
return nil, errors.Wrap(err, "error creating execute instruction")
}
return func() (*solana.Transaction, error) {
// sign the execute transaction by relayer key
inst, err := signer.createExecuteInstruction(*msgExecute)
if err != nil {
return nil, errors.Wrap(err, "error creating execute instruction")
}

Check warning on line 493 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L488-L493

Added lines #L488 - L493 were not covered by tests

return signer.signTx(ctx, inst, params.CallOptions.GasLimit)
return signer.signTx(ctx, inst, params.CallOptions.GasLimit)

Check warning on line 495 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L495

Added line #L495 was not covered by tests
}, nil
}

func (signer *Signer) prepareWithdrawSPLTx(
ctx context.Context,
cctx *types.CrossChainTx,
height uint64,
logger zerolog.Logger,
) (*solana.Transaction, error) {
) (txGetterT, error) {

Check warning on line 504 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L504

Added line #L504 was not covered by tests
params := cctx.GetCurrentOutboundParam()
// compliance check
cancelTx := compliance.IsCctxRestricted(cctx)
Expand Down Expand Up @@ -512,21 +537,23 @@
return nil, errors.Wrap(err, "createAndSignMsgWithdrawSPL error")
}

// sign the withdraw transaction by relayer key
inst, err := signer.createWithdrawSPLInstruction(*msg)
if err != nil {
return nil, errors.Wrap(err, "error creating withdraw SPL instruction")
}
return func() (*solana.Transaction, error) {
// sign the withdraw transaction by relayer key
inst, err := signer.createWithdrawSPLInstruction(*msg)
if err != nil {
return nil, errors.Wrap(err, "error creating withdraw SPL instruction")
}

Check warning on line 545 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L540-L545

Added lines #L540 - L545 were not covered by tests

return signer.signTx(ctx, inst, 0)
return signer.signTx(ctx, inst, 0)

Check warning on line 547 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L547

Added line #L547 was not covered by tests
}, nil
}

func (signer *Signer) prepareExecuteSPLTx(
ctx context.Context,
cctx *types.CrossChainTx,
height uint64,
logger zerolog.Logger,
) (*solana.Transaction, error) {
) (txGetterT, error) {

Check warning on line 556 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L556

Added line #L556 was not covered by tests
params := cctx.GetCurrentOutboundParam()
// compliance check
cancelTx := compliance.IsCctxRestricted(cctx)
Expand Down Expand Up @@ -584,20 +611,22 @@
return nil, err
}

// sign the execute spl transaction by relayer key
inst, err := signer.createExecuteSPLInstruction(*msgExecuteSpl)
if err != nil {
return nil, errors.Wrap(err, "error creating execute SPL instruction")
}
return func() (*solana.Transaction, error) {
// sign the execute spl transaction by relayer key
inst, err := signer.createExecuteSPLInstruction(*msgExecuteSpl)
if err != nil {
return nil, errors.Wrap(err, "error creating execute SPL instruction")
}

Check warning on line 619 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L614-L619

Added lines #L614 - L619 were not covered by tests

return signer.signTx(ctx, inst, params.CallOptions.GasLimit)
return signer.signTx(ctx, inst, params.CallOptions.GasLimit)

Check warning on line 621 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L621

Added line #L621 was not covered by tests
}, nil
}

func (signer *Signer) prepareWhitelistTx(
ctx context.Context,
cctx *types.CrossChainTx,
height uint64,
) (*solana.Transaction, error) {
) (txGetterT, error) {

Check warning on line 629 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L629

Added line #L629 was not covered by tests
params := cctx.GetCurrentOutboundParam()
relayedMsg := strings.Split(cctx.RelayedMessage, ":")
if len(relayedMsg) != 2 {
Expand All @@ -621,13 +650,15 @@
return nil, errors.Wrap(err, "createAndSignMsgWhitelist error")
}

// sign the whitelist transaction by relayer key
inst, err := signer.createWhitelistInstruction(msg)
if err != nil {
return nil, errors.Wrap(err, "error creating whitelist instruction")
}
return func() (*solana.Transaction, error) {
// sign the whitelist transaction by relayer key
inst, err := signer.createWhitelistInstruction(msg)
if err != nil {
return nil, errors.Wrap(err, "error creating whitelist instruction")
}

Check warning on line 658 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L653-L658

Added lines #L653 - L658 were not covered by tests

return signer.signTx(ctx, inst, 0)
return signer.signTx(ctx, inst, 0)

Check warning on line 660 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L660

Added line #L660 was not covered by tests
}, nil
}

func (signer *Signer) decodeMintAccountDetails(ctx context.Context, asset string) (token.Mint, error) {
Expand Down