Skip to content
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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

pxrl
Copy link
Contributor

@pxrl pxrl commented Feb 25, 2025

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)

…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) {
Copy link
Contributor Author

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;
Copy link
Contributor Author

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");
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant