-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bump legacy gas implementation to the Suggested Price Estimator #11805
Add bump legacy gas implementation to the Suggested Price Estimator #11805
Conversation
I see that you haven't updated any CHANGELOG files. Would it make sense to do so? |
2db9cff
to
6e2cc86
Compare
6e2cc86
to
0abe662
Compare
ae35326
to
9c576ad
Compare
// Add a buffer on top of the gas price returned by the RPC. | ||
// Bump logic when using the suggested gas price from an RPC is realistically only needed when there is increased volatility in gas price. | ||
// This buffer is a precaution to increase the chance of getting this tx on chain | ||
bufferedPrice := fee.MaxBumpedFee(newGasPrice.ToInt(), o.cfg.BumpPercent(), o.cfg.BumpMin().ToInt()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a weird thing to do here. Suggested estimator is supposed to only fetch what the RPC suggests. Although bumping seems good on paper it comes with a few drawbacks. On specific chains, the buffer needs to be disabled as it will mess up the tx inclusion unless you post exactly what the RPC suggests (i.e. Fantom, Klaytn). For chains that do want to enable this, we just rely on the same configs from the block history estimator, which might not be entirely applicable here. SCALE would have to figure those values out for existing and new chains.
Side note: if we keep the buffer feature, we would have to update BumpPercent
description in the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to disable this buffering behavior by setting BumpThreshold = 0
?
I think most chains (except for Fantom) that use Suggested estimator has this set in their config, for example (Klaytn, Metis).
So we can make sure that the Suggested behavior is the same by setting the BumpThreshold
as needed.
We can set this for Fantom to ensure backward compatibility.
+1 on updating the docs as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting BumpThreshold = 0
should disable bumping all together in the Confirmer so don't think this should be an issue for Klaytn
or Metis
.
I've updated the docs for BumpPercent
but worried that it requires too much knowledge of our gas estimator implementation to understand. Let me know if you have had something else in mind. I also found references to a couple related configs GasBumpPercent
and GasBumpWei
that seem legacy. I replaced them with BumpPercent
and BumpMin
to clean them up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default for SuggestedPrice, we already have BumpThreshold = 0
So bumping is OFF by default.
Whoever goes and changes that to enabled, must also understand that the bumpPercentrage and BumpMin will also apply to this estimator's bumping logic.
I think this is reasonable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default for SuggestedPrice, we already have BumpThreshold = 0
@prashantkumar1982 where is this logic set? Looking at the config docs the BumpThreshold
default seems to be 3 so it will not be off by default for FTM .
https://github.com/smartcontractkit/chainlink/blob/develop/docs/CONFIG.md#bumpthreshold
0e36b91
to
0996152
Compare
return nil, 0, errors.New("bump gas is not supported for this chain") | ||
// Refresh the gas price in case the current one has gone stale. | ||
// The only reason bumping logic would be called on the SuggestedPriceEstimator is if there was a significant price spike | ||
// between the last price update and when the tx was submitted. Refreshing the price helps ensure the latest market changes are accounted for. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add some comments describing how bumping makes use of the RPC call, and bump% and bumpMin settings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the comments in the latest commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Just minor comment request
@@ -45,14 +46,17 @@ func printGetLegacyGas(ctx context.Context, e gas.EvmEstimator, calldata []byte, | |||
} | |||
|
|||
const max = 50_000_000 | |||
const bumpPercent = 20 | |||
|
|||
var bumpMin = assets.NewWei(big.NewInt(5_000_000_000)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did we come up with this number? This seems very high for Arbitrum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the Arbitrum configs don't have BumpPercent
or BumpMin
set I set these using the ones in the fallback.toml. If this seems wrong, I could run it by the Ship pod. Although I don't think these values will be used. The script is only calling GetLegacyGas
on the estimator that we're creating with this config which doesn't add the buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for the reader it would be better to either remove them completely or use some values that make sense based on the Arbitrum configs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I've removed them so they don't cause any confusion
} else if err != nil { | ||
return | ||
} | ||
if newGasPrice != nil && newGasPrice.Cmp(maxGasPriceWei) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to return error here, we can let it cap on the max price down below. Just add a log below if the price gets capped so we get alerted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we only want to cap at the max gas price if the price from the RPC is still lower than the max. In that scenario, we'd still be using a price that's equal or above the one recommended by the RPC. This clause checks if the price from the RPC is higher than the max gas price. If it is then capping at the max gas price would submit a tx below the recommended price which wouldn't succeed. I was thinking to treat this the same as the other estimators that have bumped past the max and return an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So here our maxGasPriceWei is lower than what the chain recommends.
Either we hard error, or keep bumping at maxGasPrice.
I think hard error might be better, to get NOP's attention to the bad config, instead of masking that error, and sending a Tx that we know is underpriced.
I see this as a bad configuration by the NOP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see some overlap between the BumpLegacyGas
method we added and the gasPriceWithBuffer
on the Arbitrum Estimator. gasPriceWithBuffer
was implemented to solve the issue BumpLegacyGas
is fixing. Perhaps it would make sense to combine them and have the arbitrum estimator bump as well and utilize the bumped price of the suggested estimator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change may make more sense with the gas estimator refactor proposal. The gasPriceWithBuffer
method is adding to the gas price in the GetLegacyGas
method since we retry with a new estimation for the L2 FeeOutOfValidRange
error. We can remove the need for gasPriceWithBuffer
and use the SuggestedPriceEstimator
bump logic once this error is consolidated with Underpriced
. We could then just use configs to achieve the same thing as the 50% buffer.
SonarQube Quality Gate |
@@ -13,6 +13,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
|
|||
- `chainlink health` CLI command and HTML `/health` endpoint, to provide human-readable views of the underlying JSON health data. | |||
- New job type `stream` to represent streamspecs. This job type is not yet used anywhere but will be required for Data Streams V1. | |||
- Environment variables `CL_MEDIAN_ENV`, `CL_SOLANA_ENV`, and `CL_STARKNET_ENV` for setting environment variables in LOOP Plugins with an `.env` file. | |||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a bad merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was from resolving a merge conflict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please spot check all chains here, and make sure to set BumpThreshold=0 everywhere as a default setting to go with your PR?
Later, we can go and manually enable it on chains that we want explicitly.
This way we don't accidentally enable gas bumping on any chain.
I just double checked all of the configs and Fantom is the only chain using |
The
SuggestedPriceEstimator
provides a gas price from theeth_gasPrice
RPC call. The price returned should not require bumping but there is a chance that prices spike between the call to the estimator and the tx submission. If that's the case, the confirmer would need a new price to rebroadcast but the previous implementation did not support this. This change enables theSuggestedPriceEstimator
to return a new gas price for a tx using theBumpLegacyGas
method. Its implementation forces a refresh of the stored gas price and returns the latest value if it is equal or higher to the previous attempt's gas price.