From a9b0c93ae347cb7ede0b77d8a3f6405eabdeed83 Mon Sep 17 00:00:00 2001 From: Daniel Wasserman Date: Mon, 1 Apr 2024 14:03:20 -0500 Subject: [PATCH 1/4] Feat: set DefaultGasBumpPercentage to 10 --- ethergo/submitter/config/config.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ethergo/submitter/config/config.go b/ethergo/submitter/config/config.go index 676dcad8cb..1f1fd4c12e 100644 --- a/ethergo/submitter/config/config.go +++ b/ethergo/submitter/config/config.go @@ -57,7 +57,8 @@ const ( DefaultBumpIntervalSeconds = 30 // DefaultGasBumpPercentage is the default percentage to bump the gas price by. - DefaultGasBumpPercentage = 5 + // See: https://github.com/ethereum/go-ethereum/blob/8c5576b1ac89473c7ec15c9b03d1ca02e9499dcc/core/txpool/legacypool/legacypool.go#L146 + DefaultGasBumpPercentage = 10 // DefaultGasEstimate is the default gas estimate to use for transactions. DefaultGasEstimate = uint64(1200000) From 5300d7f9ce35dc1efb7db31f38e070c9410c23b4 Mon Sep 17 00:00:00 2001 From: Daniel Wasserman Date: Mon, 1 Apr 2024 14:28:55 -0500 Subject: [PATCH 2/4] Feat: bump fee cap in addition to tip cap --- ethergo/chain/gas/cmp.go | 11 +++++++++-- ethergo/submitter/submitter.go | 13 +++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ethergo/chain/gas/cmp.go b/ethergo/chain/gas/cmp.go index e0c2e3da9e..afb578e368 100644 --- a/ethergo/chain/gas/cmp.go +++ b/ethergo/chain/gas/cmp.go @@ -1,10 +1,11 @@ package gas import ( + "math/big" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/core/types" "github.com/synapsecns/sanguine/core" - "math/big" ) // CompareGas allows for gas comparisons between txes. In the case of an eip-1559 txOpts and a @@ -92,7 +93,13 @@ func bumpDynamicTxFees(opts *bind.TransactOpts, percentIncrease int, baseFee, ma logger.Warnf("new tip cap %s still less than fee cap %s + base fee %s, bumping tip not and not fee", newTipCap, maxPrice, baseFee) } - opts.GasFeeCap = maxPrice + newFeeCap := BumpByPercent(opts.GasFeeCap, percentIncrease) + if maxPrice.Cmp(newFeeCap) > 0 { + opts.GasFeeCap = newFeeCap + } else { + opts.GasFeeCap = maxPrice + logger.Warnf("new fee cap %s exceeds max price %s, using max price", newFeeCap, maxPrice) + } } // BumpByPercent bumps a gas price by a percentage. diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 371e18e9d1..54f45aecea 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -362,8 +362,17 @@ func (t *txSubmitterImpl) setGasPrice(ctx context.Context, client client.EVM, }() // TODO: cache both of these values + shouldBump := true if t.config.SupportsEIP1559(int(bigChainID.Uint64())) { - transactor.GasFeeCap = t.config.GetMaxGasPrice(chainID) + transactor.GasFeeCap, err = client.SuggestGasPrice(ctx) + if err != nil { + return fmt.Errorf("could not get gas price: %w", err) + } + // don't bump fee cap if we hit the max configured gas price + if transactor.GasFeeCap.Cmp(maxPrice) > 0 { + transactor.GasFeeCap = maxPrice + shouldBump = false + } transactor.GasTipCap, err = client.SuggestGasTipCap(ctx) if err != nil { @@ -378,7 +387,7 @@ func (t *txSubmitterImpl) setGasPrice(ctx context.Context, client client.EVM, t.applyBaseGasPrice(transactor, chainID) //nolint: nestif - if prevTx != nil { + if prevTx != nil && shouldBump { gasBlock, err := t.getGasBlock(ctx, client, chainID) if err != nil { span.AddEvent("could not get gas block", trace.WithAttributes(attribute.String("error", err.Error()))) From 9ed2dd0f81039e7145111942847708ed1ae2c870 Mon Sep 17 00:00:00 2001 From: Daniel Wasserman Date: Mon, 1 Apr 2024 14:36:38 -0500 Subject: [PATCH 3/4] Feat: traces --- ethergo/submitter/submitter.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 54f45aecea..f58cda07a3 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -358,6 +358,11 @@ func (t *txSubmitterImpl) setGasPrice(ctx context.Context, client client.EVM, transactor.GasFeeCap = maxPrice } + span.SetAttributes( + attribute.String("gas_price", bigPtrToString(transactor.GasPrice)), + attribute.String("gas_fee_cap", bigPtrToString(transactor.GasFeeCap)), + attribute.String("gas_tip_cap", bigPtrToString(transactor.GasTipCap)), + ) metrics.EndSpanWithErr(span, err) }() @@ -372,6 +377,7 @@ func (t *txSubmitterImpl) setGasPrice(ctx context.Context, client client.EVM, if transactor.GasFeeCap.Cmp(maxPrice) > 0 { transactor.GasFeeCap = maxPrice shouldBump = false + span.AddEvent("not bumping fee cap since max price is reached") } transactor.GasTipCap, err = client.SuggestGasTipCap(ctx) From 1256026e200d6ad3bd2ec3d399059c85bdb08769 Mon Sep 17 00:00:00 2001 From: Daniel Wasserman Date: Mon, 1 Apr 2024 16:42:23 -0500 Subject: [PATCH 4/4] Feat: only bump gas in setGasPrice on current nonce --- ethergo/submitter/chain_queue.go | 15 ++++++++++++--- ethergo/submitter/submitter_test.go | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ethergo/submitter/chain_queue.go b/ethergo/submitter/chain_queue.go index eb86852e58..ecd9cded83 100644 --- a/ethergo/submitter/chain_queue.go +++ b/ethergo/submitter/chain_queue.go @@ -84,7 +84,12 @@ func (t *txSubmitterImpl) chainPendingQueue(parentCtx context.Context, chainID * continue } - cq.bumpTX(gCtx, tx) + // should only bump the gas price if we are at current nonce + if tx.Nonce() == currentNonce { + cq.bumpTX(gCtx, tx, true) + } else { + cq.bumpTX(gCtx, tx, false) + } } cq.updateOldTxStatuses(gCtx) @@ -144,7 +149,7 @@ func (c *chainQueue) storeAndSubmit(ctx context.Context, calls []w3types.Caller, } // nolint: cyclop -func (c *chainQueue) bumpTX(parentCtx context.Context, ogTx db.TX) { +func (c *chainQueue) bumpTX(parentCtx context.Context, ogTx db.TX, bumpGasPrice bool) { c.g.Go(func() (err error) { if !c.isBumpIntervalElapsed(ogTx) { c.addToReprocessQueue(ogTx) @@ -171,7 +176,11 @@ func (c *chainQueue) bumpTX(parentCtx context.Context, ogTx db.TX) { transactor.Nonce = new(big.Int).SetUint64(tx.Nonce()) transactor.GasLimit = newGasEstimate - err = c.setGasPrice(ctx, c.client, transactor, c.chainID, ogTx.Transaction) + prevTx := ogTx.Transaction + if !bumpGasPrice { + prevTx = nil + } + err = c.setGasPrice(ctx, c.client, transactor, c.chainID, prevTx) if err != nil { return fmt.Errorf("could not set gas price: %w", err) } diff --git a/ethergo/submitter/submitter_test.go b/ethergo/submitter/submitter_test.go index c036158d22..b716165038 100644 --- a/ethergo/submitter/submitter_test.go +++ b/ethergo/submitter/submitter_test.go @@ -44,7 +44,7 @@ func (s *SubmitterSuite) TestSetGasPrice() { maxPrice := new(big.Int).Add(gasPrice, new(big.Int).SetUint64(1)) cfg.SetGlobalMaxGasPrice(maxPrice) - client.On(testsuite.GetFunctionName(client.SuggestGasPrice), mock.Anything).Twice().Return(gasPrice, nil) + client.On(testsuite.GetFunctionName(client.SuggestGasPrice), mock.Anything).Times(3).Return(gasPrice, nil) err = ts.SetGasPrice(s.GetTestContext(), client, transactor, chainID, nil) s.Require().NoError(err)