Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Feb 13, 2025
1 parent d8a1213 commit 463931d
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion e2e/runner/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r *E2ERunner) VerifySolanaWithdrawalAmountFromCCTX(cctx *crosschaintypes.C

// 1st instruction is the withdraw
instruction := tx.Message.Instructions[0]
instWithdrae, err := solanacontracts.TryParseInstructionWithdraw(instruction)
instWithdrae, err := solanacontracts.ParseInstructionWithdraw(instruction)
require.NoError(r, err)

// verify the amount
Expand Down
16 changes: 8 additions & 8 deletions pkg/contracts/solana/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ func (inst *WithdrawInstructionParams) TokenAmount() uint64 {
return inst.Amount
}

// TryParseInstructionWithdraw tries to parse the instruction as a 'withdraw'.
// ParseInstructionWithdraw tries to parse the instruction as a 'withdraw'.
// It returns nil if the instruction can't be parsed as a 'withdraw'.
func TryParseInstructionWithdraw(instruction solana.CompiledInstruction) (*WithdrawInstructionParams, error) {
func ParseInstructionWithdraw(instruction solana.CompiledInstruction) (*WithdrawInstructionParams, error) {
// try deserializing instruction as a 'withdraw'
inst := &WithdrawInstructionParams{}
err := borsh.Deserialize(inst, instruction.Data)
Expand Down Expand Up @@ -198,9 +198,9 @@ func (inst *ExecuteInstructionParams) TokenAmount() uint64 {
return inst.Amount
}

// TryParseInstructionExecute tries to parse the instruction as a 'execute'.
// ParseInstructionExecute tries to parse the instruction as a 'execute'.
// It returns nil if the instruction can't be parsed as a 'execute'.
func TryParseInstructionExecute(instruction solana.CompiledInstruction) (*ExecuteInstructionParams, error) {
func ParseInstructionExecute(instruction solana.CompiledInstruction) (*ExecuteInstructionParams, error) {
// try deserializing instruction as a 'execute'
inst := &ExecuteInstructionParams{}
err := borsh.Deserialize(inst, instruction.Data)
Expand Down Expand Up @@ -258,9 +258,9 @@ func (inst *WithdrawSPLInstructionParams) TokenAmount() uint64 {
return inst.Amount
}

// TryParseInstructionWithdraw tries to parse the instruction as a 'withdraw'.
// ParseInstructionWithdraw tries to parse the instruction as a 'withdraw'.
// It returns nil if the instruction can't be parsed as a 'withdraw'.
func TryParseInstructionWithdrawSPL(instruction solana.CompiledInstruction) (*WithdrawSPLInstructionParams, error) {
func ParseInstructionWithdrawSPL(instruction solana.CompiledInstruction) (*WithdrawSPLInstructionParams, error) {
// try deserializing instruction as a 'withdraw'
inst := &WithdrawSPLInstructionParams{}
err := borsh.Deserialize(inst, instruction.Data)
Expand Down Expand Up @@ -326,9 +326,9 @@ func (inst *WhitelistInstructionParams) TokenAmount() uint64 {
return 0
}

// TryParseInstructionWhitelist tries to parse the instruction as a 'whitelist_spl_mint'.
// ParseInstructionWhitelist tries to parse the instruction as a 'whitelist_spl_mint'.
// It returns nil if the instruction can't be parsed as a 'whitelist_spl_mint'.
func TryParseInstructionWhitelist(instruction solana.CompiledInstruction) (*WhitelistInstructionParams, error) {
func ParseInstructionWhitelist(instruction solana.CompiledInstruction) (*WhitelistInstructionParams, error) {
// try deserializing instruction as a 'whitelist_spl_mint'
inst := &WhitelistInstructionParams{}
err := borsh.Deserialize(inst, instruction.Data)
Expand Down
6 changes: 3 additions & 3 deletions zetaclient/chains/evm/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (signer *Signer) SignOutboundFromCCTX(
} else if cctx.ProtocolContractVersion == crosschaintypes.ProtocolContractVersion_V2 {
// call sign outbound from cctx for v2 protocol contracts
return signer.SignOutboundFromCCTXV2(ctx, cctx, outboundData)
} else if IsSenderZetaChain(cctx, zetacoreClient) {
} else if IsPendingOutboundFromZetaChain(cctx, zetacoreClient) {
switch cctx.InboundParams.CoinType {
case coin.CoinType_Gas:
logger.Info().Msgf(
Expand Down Expand Up @@ -510,9 +510,9 @@ func (signer *Signer) BroadcastOutbound(
}
}

// IsSenderZetaChain checks if the sender chain is ZetaChain
// IsPendingOutboundFromZetaChain checks if the sender chain is ZetaChain and if status is PendingOutbound
// TODO(revamp): move to another package more general for cctx functions
func IsSenderZetaChain(
func IsPendingOutboundFromZetaChain(
cctx *crosschaintypes.CrossChainTx,
zetacoreClient interfaces.ZetacoreClient,
) bool {
Expand Down
8 changes: 4 additions & 4 deletions zetaclient/chains/solana/observer/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,16 @@ func ParseGatewayInstruction(
// parse the outbound instruction
switch coinType {
case coin.CoinType_Gas:
inst, err := contracts.TryParseInstructionWithdraw(instruction)
inst, err := contracts.ParseInstructionWithdraw(instruction)
if err != nil {
return contracts.TryParseInstructionExecute(instruction)
return contracts.ParseInstructionExecute(instruction)
}

return inst, err
case coin.CoinType_Cmd:
return contracts.TryParseInstructionWhitelist(instruction)
return contracts.ParseInstructionWhitelist(instruction)
case coin.CoinType_ERC20:
return contracts.TryParseInstructionWithdrawSPL(instruction)
return contracts.ParseInstructionWithdrawSPL(instruction)
default:
return nil, fmt.Errorf("unsupported outbound coin type %s", coinType)
}
Expand Down
6 changes: 3 additions & 3 deletions zetaclient/chains/solana/signer/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (signer *Signer) createAndSignMsgExecute(
// the produced signature is in the [R || S || V] format where V is 0 or 1.
signature, err := signer.TSS().Sign(ctx, msgHash[:], height, nonce, chain.ChainId)
if err != nil {
return nil, errors.Wrap(err, "Key-sign failed")
return nil, errors.Wrap(err, "key-sign failed")
}

// attach the signature and return
Expand Down Expand Up @@ -94,7 +94,7 @@ func (signer *Signer) signExecuteTx(ctx context.Context, msg contracts.MsgExecut
// get a recent blockhash
recent, err := signer.client.GetLatestBlockhash(ctx, rpc.CommitmentFinalized)
if err != nil {
return nil, errors.Wrap(err, "GetLatestBlockhash error")
return nil, errors.Wrap(err, "getLatestBlockhash error")
}

// create a transaction that wraps the instruction
Expand All @@ -109,7 +109,7 @@ func (signer *Signer) signExecuteTx(ctx context.Context, msg contracts.MsgExecut
solana.TransactionPayer(signer.relayerKey.PublicKey()),
)
if err != nil {
return nil, errors.Wrap(err, "NewTransaction error")
return nil, errors.Wrap(err, "newTransaction error")
}

// relayer signs the transaction
Expand Down
32 changes: 16 additions & 16 deletions zetaclient/chains/solana/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (signer *Signer) TryProcessOutbound(
tx = whitelistTx

case coin.CoinType_Gas:
if cctx.InboundParams.IsCrossChainCall && IsSenderZetaChain(cctx, zetacoreClient) {
if cctx.InboundParams.IsCrossChainCall && IsPendingOutboundFromZetaChain(cctx, zetacoreClient) {
executeTx, err := signer.prepareExecuteTx(ctx, cctx, height, logger)
if err != nil {
logger.Error().Err(err).Msgf("TryProcessOutbound: Fail to sign execute outbound")
Expand Down Expand Up @@ -274,13 +274,13 @@ func (signer *Signer) prepareWithdrawTx(
// sign gateway withdraw message by TSS
msg, err := signer.createAndSignMsgWithdraw(ctx, params, height, cancelTx)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "createAndSignMsgWithdraw error")
}

// sign the withdraw transaction by relayer key
tx, err := signer.signWithdrawTx(ctx, *msg)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "signWithdrawTx error")
}

return tx, nil
Expand Down Expand Up @@ -310,11 +310,11 @@ func (signer *Signer) prepareExecuteTx(

message, err := hex.DecodeString(cctx.RelayedMessage)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "decodeString %s error", cctx.RelayedMessage)
}
msg, err := contracts.DecodeExecuteMsg(message)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "decodeExecuteMsg %s error", cctx.RelayedMessage)
}

remainingAccounts := []*solana.AccountMeta{}
Expand All @@ -337,13 +337,13 @@ func (signer *Signer) prepareExecuteTx(
cancelTx,
)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "createAndSignMsgExecute error")
}

// sign the execute transaction by relayer key
tx, err := signer.signExecuteTx(ctx, *msgExecute)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "signExecuteTx error")
}

return tx, nil
Expand Down Expand Up @@ -374,7 +374,7 @@ func (signer *Signer) prepareWithdrawSPLTx(
// get mint details to get decimals
mint, err := signer.decodeMintAccountDetails(ctx, cctx.InboundParams.Asset)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "decodeMintAccountDetails error")
}

// sign gateway withdraw spl message by TSS
Expand All @@ -387,13 +387,13 @@ func (signer *Signer) prepareWithdrawSPLTx(
cancelTx,
)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "createAndSignMsgWithdrawSPL error")
}

// sign the withdraw transaction by relayer key
tx, err := signer.signWithdrawSPLTx(ctx, *msg)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "signWithdrawSPLTx error")
}

return tx, nil
Expand All @@ -412,25 +412,25 @@ func (signer *Signer) prepareWhitelistTx(

pk, err := solana.PublicKeyFromBase58(relayedMsg[1])
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "publicKeyFromBase58 %s error", relayedMsg[1])
}

seed := [][]byte{[]byte("whitelist"), pk.Bytes()}
whitelistEntryPDA, _, err := solana.FindProgramAddress(seed, signer.gatewayID)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "findProgramAddress error for seed %s", seed)
}

// sign gateway whitelist message by TSS
msg, err := signer.createAndSignMsgWhitelist(ctx, params, height, pk, whitelistEntryPDA)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "createAndSignMsgWhitelist error")
}

// sign the whitelist transaction by relayer key
tx, err := signer.signWhitelistTx(ctx, msg)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "signWhitelistTx error")
}

return tx, nil
Expand Down Expand Up @@ -495,9 +495,9 @@ func (signer *Signer) SetRelayerBalanceMetrics(ctx context.Context) {
metrics.RelayerKeyBalance.WithLabelValues(signer.Chain().Name).Set(solBalance)
}

// IsSenderZetaChain checks if the sender chain is ZetaChain
// IsPendingOutboundFromZetaChain checks if the sender chain is ZetaChain and if status is PendingOutbound
// TODO(revamp): move to another package more general for cctx functions
func IsSenderZetaChain(
func IsPendingOutboundFromZetaChain(
cctx *types.CrossChainTx,
zetacoreClient interfaces.ZetacoreClient,
) bool {
Expand Down
6 changes: 3 additions & 3 deletions zetaclient/chains/solana/signer/whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (signer *Signer) createAndSignMsgWhitelist(
// the produced signature is in the [R || S || V] format where V is 0 or 1.
signature, err := signer.TSS().Sign(ctx, msgHash[:], height, nonce, chain.ChainId)
if err != nil {
return nil, errors.Wrap(err, "Key-sign failed")
return nil, errors.Wrap(err, "key-sign failed")
}

// attach the signature and return
Expand Down Expand Up @@ -69,7 +69,7 @@ func (signer *Signer) signWhitelistTx(ctx context.Context, msg *contracts.MsgWhi
// get a recent blockhash
recent, err := signer.client.GetLatestBlockhash(ctx, rpc.CommitmentFinalized)
if err != nil {
return nil, errors.Wrap(err, "GetLatestBlockhash error")
return nil, errors.Wrap(err, "getLatestBlockhash error")
}

// create a transaction that wraps the instruction
Expand All @@ -84,7 +84,7 @@ func (signer *Signer) signWhitelistTx(ctx context.Context, msg *contracts.MsgWhi
solana.TransactionPayer(signer.relayerKey.PublicKey()),
)
if err != nil {
return nil, errors.Wrap(err, "NewTransaction error")
return nil, errors.Wrap(err, "newTransaction error")
}

// relayer signs the transaction
Expand Down
6 changes: 3 additions & 3 deletions zetaclient/chains/solana/signer/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (signer *Signer) createAndSignMsgWithdraw(
// the produced signature is in the [R || S || V] format where V is 0 or 1.
signature, err := signer.TSS().Sign(ctx, msgHash[:], height, nonce, chain.ChainId)
if err != nil {
return nil, errors.Wrap(err, "Key-sign failed")
return nil, errors.Wrap(err, "key-sign failed")
}

// attach the signature and return
Expand Down Expand Up @@ -80,7 +80,7 @@ func (signer *Signer) signWithdrawTx(ctx context.Context, msg contracts.MsgWithd
// get a recent blockhash
recent, err := signer.client.GetLatestBlockhash(ctx, rpc.CommitmentFinalized)
if err != nil {
return nil, errors.Wrap(err, "GetLatestBlockhash error")
return nil, errors.Wrap(err, "getLatestBlockhash error")
}

// create a transaction that wraps the instruction
Expand All @@ -95,7 +95,7 @@ func (signer *Signer) signWithdrawTx(ctx context.Context, msg contracts.MsgWithd
solana.TransactionPayer(signer.relayerKey.PublicKey()),
)
if err != nil {
return nil, errors.Wrap(err, "NewTransaction error")
return nil, errors.Wrap(err, "newTransaction error")
}

// relayer signs the transaction
Expand Down
6 changes: 3 additions & 3 deletions zetaclient/chains/solana/signer/withdraw_spl.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (signer *Signer) createAndSignMsgWithdrawSPL(
// the produced signature is in the [R || S || V] format where V is 0 or 1.
signature, err := signer.TSS().Sign(ctx, msgHash[:], height, nonce, chain.ChainId)
if err != nil {
return nil, errors.Wrap(err, "Key-sign failed")
return nil, errors.Wrap(err, "key-sign failed")
}

// attach the signature and return
Expand Down Expand Up @@ -113,7 +113,7 @@ func (signer *Signer) signWithdrawSPLTx(
// get a recent blockhash
recent, err := signer.client.GetLatestBlockhash(ctx, rpc.CommitmentFinalized)
if err != nil {
return nil, errors.Wrap(err, "GetLatestBlockhash error")
return nil, errors.Wrap(err, "getLatestBlockhash error")
}

// create a transaction that wraps the instruction
Expand All @@ -128,7 +128,7 @@ func (signer *Signer) signWithdrawSPLTx(
solana.TransactionPayer(signer.relayerKey.PublicKey()),
)
if err != nil {
return nil, errors.Wrap(err, "NewTransaction error")
return nil, errors.Wrap(err, "newTransaction error")
}

// relayer signs the transaction
Expand Down

0 comments on commit 463931d

Please sign in to comment.