diff --git a/changelog.md b/changelog.md index 11d42fe638..fdcea170bc 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,10 @@ * [3671](https://github.com/zeta-chain/node/pull/3671) - use gas budget argument to refund TSS for Sui withdraw cost * [3699](https://github.com/zeta-chain/node/pull/3699) - use real gas usage for TON withdrawals +### Refactor + +* [3709](https://github.com/zeta-chain/node/pull/3709) - improve cctx error message for out of gas errors when creating outbound + ### Fixes * [3711](https://github.com/zeta-chain/node/pull/3711) - fix TON call_data parsing diff --git a/x/crosschain/keeper/cctx_utils.go b/x/crosschain/keeper/cctx_utils.go index 3fedf03cef..213f0d5c4b 100644 --- a/x/crosschain/keeper/cctx_utils.go +++ b/x/crosschain/keeper/cctx_utils.go @@ -27,7 +27,7 @@ func (k Keeper) SetObserverOutboundInfo(ctx sdk.Context, receiveChainID int64, c if !found { return cosmoserrors.Wrapf( types.ErrCannotFindReceiverNonce, - "identifiers: %s (chain %q)", cctx.LogIdentifierForCCTX(), chain.Name, + "chain name %s", chain.Name, ) } // SET nonce @@ -36,7 +36,7 @@ func (k Keeper) SetObserverOutboundInfo(ctx sdk.Context, receiveChainID int64, c if !found { return cosmoserrors.Wrapf( types.ErrCannotFindTSSKeys, - "identifiers: %s (chain %q)", cctx.LogIdentifierForCCTX(), chain.Name, + "chain name %s", chain.Name, ) } diff --git a/x/crosschain/keeper/gas_payment.go b/x/crosschain/keeper/gas_payment.go index 4f87f872e1..d0cb2911ef 100644 --- a/x/crosschain/keeper/gas_payment.go +++ b/x/crosschain/keeper/gas_payment.go @@ -134,10 +134,12 @@ func (k Keeper) PayGasNativeAndUpdateCctx( if outTxGasFee.GT(inputAmount) { return cosmoserrors.Wrap( types.ErrNotEnoughGas, - fmt.Sprintf("outTxGasFee(%s) more than available gas for tx (%s) | Identifiers : %s ", + fmt.Sprintf( + "unable to pay for outbound tx using gas token, outbound chain: %d, required: %s, available: %s", + chainID, outTxGasFee, inputAmount, - cctx.LogIdentifierForCCTX()), + ), ) } ctx.Logger().Info("Subtracting amount from inbound tx", "amount", inputAmount.String(), "fee", outTxGasFee.String()) @@ -223,10 +225,12 @@ func (k Keeper) PayGasInERC20AndUpdateCctx( if sdkmath.NewUintFromBigInt(feeInZRC20).GT(inputAmount) { return cosmoserrors.Wrap( types.ErrNotEnoughGas, - fmt.Sprintf("feeInZRC20(%s) more than available gas for tx (%s) | Identifiers : %s ", - feeInZRC20, + fmt.Sprintf( + "unable to pay for outbound tx using zrc20 token, outbound chain: %d, required: %s, available: %s", + chainID, + outTxGasFee, inputAmount, - cctx.LogIdentifierForCCTX()), + ), ) } newAmount := inputAmount.Sub(sdkmath.NewUintFromBigInt(feeInZRC20)) @@ -347,9 +351,8 @@ func (k Keeper) PayGasInZetaAndUpdateCctx( gasPrice, priorityFee, isFound := k.GetMedianGasValues(ctx, chainID) if !isFound { return cosmoserrors.Wrapf(types.ErrUnableToGetGasPrice, - "chain %d; identifiers %q", + "chain %d", chainID, - cctx.LogIdentifierForCCTX(), ) } // overpays gas price @@ -377,14 +380,17 @@ func (k Keeper) PayGasInZetaAndUpdateCctx( return cosmoserrors.Wrap(err, "PayGasInZetaAndUpdateCctx: unable to QueryUniswapV2RouterGetZetaAmountsIn") } feeInZeta := types.GetProtocolFee().Add(sdkmath.NewUintFromBigInt(outTxGasFeeInZeta)) + // reduce the amount of the outbound tx if feeInZeta.GT(zetaBurnt) { return cosmoserrors.Wrap( - types.ErrNotEnoughZetaBurnt, - fmt.Sprintf("feeInZeta(%s) more than zetaBurnt (%s) | Identifiers : %s ", - feeInZeta, + types.ErrNotEnoughGas, + fmt.Sprintf( + "unable to pay for outbound tx using zeta token, outbound chain: %d, required: %s, available: %s", + chainID, + outTxGasFee, zetaBurnt, - cctx.LogIdentifierForCCTX()), + ), ) } ctx.Logger().Info("Subtracting amount from inbound tx", diff --git a/x/crosschain/keeper/gas_payment_test.go b/x/crosschain/keeper/gas_payment_test.go index 9f91ffc8d1..2458d02007 100644 --- a/x/crosschain/keeper/gas_payment_test.go +++ b/x/crosschain/keeper/gas_payment_test.go @@ -642,6 +642,6 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { // set input amount lower than total zeta fee inputAmount := expectedFeeInZeta.Sub(math.NewUint(1)) err = k.PayGasInZetaAndUpdateCctx(ctx, chainID, &cctx, inputAmount, false) - require.ErrorIs(t, err, types.ErrNotEnoughZetaBurnt) + require.ErrorIs(t, err, types.ErrNotEnoughGas) }) } diff --git a/x/crosschain/types/keys.go b/x/crosschain/types/keys.go index c148744ecb..8e9b2a523a 100644 --- a/x/crosschain/types/keys.go +++ b/x/crosschain/types/keys.go @@ -82,21 +82,6 @@ func OutboundTrackerKey( return key } -func (m CrossChainTx) LogIdentifierForCCTX() string { - if len(m.OutboundParams) == 0 { - return fmt.Sprintf("%s-%d", m.InboundParams.Sender, m.InboundParams.SenderChainId) - } - i := len(m.OutboundParams) - 1 - outTx := m.OutboundParams[i] - return fmt.Sprintf( - "%s-%d-%d-%d", - m.InboundParams.Sender, - m.InboundParams.SenderChainId, - outTx.ReceiverChainId, - outTx.TssNonce, - ) -} - func FinalizedInboundKey(inboundHash string, chainID int64, eventIndex uint64) string { return fmt.Sprintf("%d-%s-%d", chainID, inboundHash, eventIndex) }