Skip to content

Conversation

@MartinquaXD
Copy link
Contributor

@MartinquaXD MartinquaXD commented Dec 2, 2025

Description

With the recent gnosis chain issues we saw a lot of issues with replacing transactions. Additionally it was not very easy to understand what went wrong due to insufficient logging. This PR addresses both issues.

Changes

Logic:

  • compute a fresh gas price before submitting the settlement
  • always check if there is a pending tx we have to replace and pick the gas price accordingly
  • simple mempool specific logic is in the infra module
  • pricing decisions happen in the domain module
  • slightly bump the theoretical minimum of 12.5% gas price increase per block to 30% to avoid numerical issues for tiny gas prices like on gnosis chain

Logging:

  • always log success / failure directly in the submit() function
  • on error also try to fetch the current pending tx (in case our submission failed because there was a higher priced pending tx in the mempool)
  • log many intermediate gas prices for understanding the final results of non-trivial pricing decisions

How to test

TODO

@MartinquaXD MartinquaXD changed the title Compute tx replacement gas price based on mempool Better tx replacement logic for solution submission Dec 4, 2025
@MartinquaXD MartinquaXD marked this pull request as ready for review December 4, 2025 15:47
@MartinquaXD MartinquaXD requested a review from a team as a code owner December 4, 2025 15:47
/// pending transaction at the same nonce.
const GAS_PRICE_BUMP: f64 = 1.125;
/// pending transaction at the same nonce. The correct factor is actually
/// 1.25 but to avoid rounding issues on chains with very low gas prices
Copy link
Contributor

@fafk fafk Dec 5, 2025

Choose a reason for hiding this comment

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

1.25 or 1.125 as it was? Where's the correct number coming from? 🤔

let submission_block = self.ethereum.current_block().borrow().number;
let blocks_until_deadline = submission_deadline.saturating_sub(submission_block);
let estimated_gas_price =
current_gas_price * GAS_PRICE_BUMP.powi(blocks_until_deadline as i32);
Copy link
Contributor

Choose a reason for hiding this comment

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

This might get pretty aggressive on chains with low block time, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, this exponential progression can go crazy pretty fast. It seems like the GAS_PRICE_BUMP needs to be configurable, then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We already had this logic before this PR. In fact we currently apply this multiplication logic in 2 places. Will update the PR to move all the magic gas multiplication logic into 1 file.

@MartinquaXD MartinquaXD marked this pull request as draft December 5, 2025 10:50
@MartinquaXD MartinquaXD marked this pull request as ready for review December 8, 2025 14:29
Comment on lines -183 to -189
tracing::info!(
settle_tx_hash = ?hash,
deadline = submission_deadline,
current_block = block.number,
?cancellation_tx_hash,
"tx not confirmed in time, cancelling",
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this log not needed anymore?

Copy link
Contributor

@squadgazzz squadgazzz left a comment

Choose a reason for hiding this comment

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

Very nice! It should help to mitigate some of the nonce issues.

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.

4 participants