-
Notifications
You must be signed in to change notification settings - Fork 58
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
[WIP] improve(TransactionUtils): Simple priority scaler for replacement transactions #2126
base: master
Are you sure you want to change the base?
Conversation
…nsactions If transaction submission fails and the word "underpriced" is found in the error message, request that the priority fee be increased on the subsequent retry. This isn't foolproof but is cheap to try and makes sense as an initial step towards successfully submitting replacement transactions during gas price spikes.
@@ -88,6 +90,15 @@ export async function runTransaction( | |||
await contract.populateTransaction[method](...(args as Array<unknown>), { value }) | |||
); | |||
|
|||
// Bump the priority fee by 20% to try to successfully replace a pending transaction. | |||
// Success is not guaranteed since the bot does not know the gas price of the transaction it is trying to replace. | |||
if (bumpGas && gas.maxPriorityFeePerGas) { |
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.
Legacy transactions are currently ignored since issues have only been seen on eip-1559 chains. It would make sense to scale legacy transactions though.
// Bump the priority fee incrementally on each retry to try to successfully replace a pending transaction. | ||
// Success is not guaranteed since the bot does not know the gas price of the transaction it is trying to replace. | ||
if (bumpGas && gas.maxPriorityFeePerGas) { | ||
const priorityScaler = 1.1 + (1 + DEFAULT_RETRIES - Math.min(retriesRemaining, DEFAULT_RETRIES)) / 10; |
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.
At least some aspect of this scaler should probably be configurable.
@@ -118,7 +132,8 @@ export async function runTransaction( | |||
retriesRemaining, | |||
}); | |||
|
|||
return await runTransaction(logger, contract, method, args, value, gasLimit, null, retriesRemaining); | |||
const bumpGas = isEthersError(error) && error.message.toLowerCase().includes("underpriced"); |
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.
todo: link up more cleanly with the provider layer. The provider layer should be able to explicitly identify these cases and tag them with a code we can evaluate.
If transaction submission fails and the word "underpriced" is found in the error message, request that the current estimated priority fee be increased on the subsequent retry.
This isn't foolproof but is cheap to try and makes sense as an initial step towards successfully submitting replacement transactions during gas price spikes.
This can be improved at least by aligning with the provider layer to supply an objective code that indicates an underpriced transaction, rather than having to rely on string matching. It would additionally be beneficial to be able to source the actual gas price of for other transactions with the same nonce. This however involves additional RPC queries.
(PR is WIP and will be iterated on)