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

feat(cast): implement auto gas price adjustment for stuck transactions in cast send #9147

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

leovct
Copy link
Contributor

@leovct leovct commented Oct 19, 2024

Motivation

Closes #4454

Solution

Implement a new flag called --bump-fee, in cast send, to automatically bump transactions gas price. The idea is to be able to automatically replace stuck transactions during busy network times. Instead of manually adjusting the gas price, the user can specify the --bump-fee flag and cast will automatically adjust the gas price to replace the transaction.

The following safeguards have been implemented:

  • A gas price bump limit percentage can be set by the user, by default it it set to 150%. It represents the maximum total percentage increase allowed for gas price. For example, a value of 150 means the gas price will never exceed 150% of the original price (1.5 times the initial price).
  • A maximum number of gas price bumps can also be set by the user, by default set to 3.

The gas price increment is also configurable. By default, it is set to 10%, meaning that the gas price will be increased by 10% of the original gas price on each retry.

@leovct leovct changed the title feat(cast): implement auto gas price adjustment for stuck transactions feat(cast): implement auto gas price adjustment for stuck transactions in cast send Oct 19, 2024
@leovct leovct marked this pull request as ready for review October 19, 2024 23:22
Copy link
Member

@klkvr klkvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! just nits for now

so basically --bump-fee is supposed to determine the minimal gas price required to replace the pending transaction once.

I'm wondering if there are any easier ways to do this? e.g there's eth_getTransactionBySenderAndNonce which didn't get wide adoption yet unfortunately, not sure if there's something similar we could use

crates/cast/bin/cmd/send.rs Outdated Show resolved Hide resolved
crates/cast/bin/cmd/send.rs Show resolved Hide resolved
crates/cast/bin/cmd/send.rs Outdated Show resolved Hide resolved
crates/cast/bin/cmd/send.rs Outdated Show resolved Hide resolved
@leovct
Copy link
Contributor Author

leovct commented Oct 22, 2024

I removed the bump gas limit percentage in favour of a simpler bump gas limit. It would be great to use eth_getTransactionBySenderAndNonce to retrieve the tx and the base fee from here. Since I can't use that at the moment, I'm always iterating from the initial base fee and thus the percentage calculation was wrong.

@leovct leovct force-pushed the feat/cast-send-bump-gas-price-stuck-txs branch from 180ee20 to 96bbea7 Compare October 23, 2024 14:26
@leovct leovct requested a review from klkvr October 24, 2024 08:01
crates/cast/bin/cmd/send.rs Outdated Show resolved Hide resolved
crates/cast/bin/cmd/send.rs Outdated Show resolved Hide resolved
let mut retry_count = 0;
loop {
let mut new_tx = tx.clone();
new_tx.gas_price = Some(current_gas_price);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what's the best strategy here, but wondering if we should also bump the priority fee somehow?

@leovct leovct force-pushed the feat/cast-send-bump-gas-price-stuck-txs branch from f06c626 to 5ff1422 Compare November 6, 2024 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

cast send: add --bump-fee flag that resends with iteratively increasing gas price
2 participants