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

Set maxFeePerGas to gasCap #2295

Merged
merged 6 commits into from
Jan 22, 2024
Merged

Set maxFeePerGas to gasCap #2295

merged 6 commits into from
Jan 22, 2024

Conversation

fleupold
Copy link
Contributor

Description

Our gas estimation logic was written prior to EIP1559 which changed Ethereum's transaction fee mechanism from a "pay as bid" to a "truthful bidding" mechanism. Before, users would need to think

  1. How much they are maximally willing to pay for their transaction (1000 gwei by default for us)
  2. How much they should bid for transaction inclusion (dependent on current demand/supply)

They would always get charged 2.

Now, people only have to answer 1. and can rely on Ethereum's elastic base fee to make sure they are only getting charged as much as needed (the current base fee).

Priority fees remain a "pay as bid" part of the pricing, however those values tend to be very small (1-3 gwei) compared to the base fee (20-500 gwei).

This PR start to bid truthfully with regards to the maximum fee we are willing to pay. This simplifies a bunch of the solution submission logic as we now longer have to predict the maximum base fee in the future.

Changes

  • Always set maxFeePerGas to gas_price_cap

How to test

Run e2e test, see settlements are now submitted with very high cap.

Related Issues

Fixes #1874

@fleupold fleupold requested a review from a team as a code owner January 16, 2024 16:00
Copy link
Contributor

@sunce86 sunce86 left a comment

Choose a reason for hiding this comment

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

Are we gonna cleanup MAX_FEE_FACTOR in a follow up PR?

// Use the lowest max_fee_per_gas of all mempools as the max_fee_per_gas
let max_fee_per_gas = mempools
.iter()
.map(|mempool| eth::U256::from_f64_lossy(mempool.gas_price_cap))
Copy link
Contributor

Choose a reason for hiding this comment

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

gas_price_cap should be probably updated to U256, not related to this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fleupold
Copy link
Contributor Author

Are we gonna cleanup MAX_FEE_FACTOR in a follow up PR?

It's being remove as part of #2294

@@ -42,9 +43,16 @@ impl GasPriceEstimator {
mempool.additional_tip_percentage,
)
});
// Use the lowest max_fee_per_gas of all mempools as the max_fee_per_gas
Copy link
Contributor

Choose a reason for hiding this comment

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

Either the comment is wrong or you should be using .min(), no?

Suggested change
// Use the lowest max_fee_per_gas of all mempools as the max_fee_per_gas
// Use the highest max_fee_per_gas of all mempools as the max_fee_per_gas

@fleupold fleupold enabled auto-merge (squash) January 22, 2024 10:34
@fleupold fleupold merged commit 22a2c04 into main Jan 22, 2024
8 checks passed
@fleupold fleupold deleted the set_max_base_fee branch January 22, 2024 10:39
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2024
@fleupold
Copy link
Contributor Author

Turns out that this PR isn't having the desired effect yet, since we are overriding our maxFeePerGas value in the legacy submission with a fresh estimate (we only reuse the previously computed maxFeePerGas as a cap in that case).

async fn estimate_with_limits(
&self,
gas_limit: f64,
time_limit: Duration,
) -> Result<GasPrice1559> {
let mut estimate = self
.inner
.estimate_with_limits(gas_limit, time_limit)
.await?;
let additional_tip = self.max_additional_tip.min(
estimate.max_fee_per_gas.min(self.max_fee_per_gas)
* self.additional_tip_percentage_of_max_fee,
);
estimate.max_fee_per_gas =
(estimate.max_fee_per_gas + additional_tip).min(self.max_fee_per_gas);

Will change once we move to native solution submission

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

Successfully merging this pull request may close these issues.

Dynamically calculate MAX_FEE_FACTOR
3 participants