From 49d641bbac9c42280a391111d100de29e741219b Mon Sep 17 00:00:00 2001 From: Lucas Bertrand Date: Thu, 3 Oct 2024 11:04:44 +0200 Subject: [PATCH] fix(zetaclient): tolerate priorityFee > gasFee (#2955) * Fix priority fees edge case * Address PR comments * add some context comment * comment --------- Co-authored-by: Dmitry S <11892559+swift1337@users.noreply.github.com> --- zetaclient/chains/evm/signer/gas.go | 11 ++++++++++- zetaclient/chains/evm/signer/gas_test.go | 13 ++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/zetaclient/chains/evm/signer/gas.go b/zetaclient/chains/evm/signer/gas.go index 540302b91c..6727758edd 100644 --- a/zetaclient/chains/evm/signer/gas.go +++ b/zetaclient/chains/evm/signer/gas.go @@ -92,7 +92,16 @@ func gasFromCCTX(cctx *types.CrossChainTx, logger zerolog.Logger) (Gas, error) { case err != nil: return Gas{}, errors.Wrap(err, "unable to parse priorityFee") case gasPrice.Cmp(priorityFee) == -1: - return Gas{}, fmt.Errorf("gasPrice (%d) is less than priorityFee (%d)", gasPrice.Int64(), priorityFee.Int64()) + logger.Warn(). + Str("cctx.initial_priority_fee", priorityFee.String()). + Str("cctx.forced_priority_fee", gasPrice.String()). + Msg("gasPrice is less than priorityFee, setting priorityFee = gasPrice") + + // this should in theory never happen, but this reported bug might be a cause: https://github.com/zeta-chain/node/issues/2954 + // in this case we lower the priorityFee to the gasPrice to ensure the transaction is valid + // the only potential issue is the transaction might not cover the baseFee + // the gas stability pool mechanism help to mitigate this issue + priorityFee = big.NewInt(0).Set(gasPrice) } return Gas{ diff --git a/zetaclient/chains/evm/signer/gas_test.go b/zetaclient/chains/evm/signer/gas_test.go index 71bbf97b5d..aa9a683b37 100644 --- a/zetaclient/chains/evm/signer/gas_test.go +++ b/zetaclient/chains/evm/signer/gas_test.go @@ -98,9 +98,16 @@ func TestGasFromCCTX(t *testing.T) { errorContains: "unable to parse priorityFee: big.Int is negative", }, { - name: "gasPrice is less than priorityFee", - cctx: makeCCTX(123_000, gwei(4).String(), gwei(5).String()), - errorContains: "gasPrice (4000000000) is less than priorityFee (5000000000)", + name: "gasPrice is less than priorityFee", + cctx: makeCCTX(123_000, gwei(4).String(), gwei(5).String()), + assert: func(t *testing.T, g Gas) { + assert.False(t, g.isLegacy()) + assertGasEquals(t, Gas{ + Limit: 123_000, + Price: gwei(4), + PriorityFee: gwei(4), + }, g) + }, }, { name: "gasPrice is invalid",