-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix(api): Improve estimation for gas_per_pubdata_limit #3475
base: main
Are you sure you want to change the base?
Conversation
// Given that we scale overall fee, we should also scale the limit for gas per pubdata price that user agrees to. | ||
// However, we should not exceed the limit that was provided by the user in the initial request. | ||
let gas_per_pubdata_limit = std::cmp::min( | ||
((self.gas_per_pubdata_byte as f64 * estimated_fee_scale_factor) as u64).into(), | ||
self.transaction.gas_per_pubdata_byte_limit(), | ||
); |
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.
While it should work as a quick fix I think the problem is more deep.
estimated_fee_scale_factor
is set from config var estimate_gas_scale_factor
/// The factor by which to scale the gasLimit
we also have gas_price_scale_factor
/// The multiplier to use when suggesting gas price
Latter is used in ApiFeeInputProvider
but the problem is that provider returns and uses that factor for {fair_l2_gas_price, fair_pubdata_price} while gas_per_pubdata = ceil(fair_pubdata_price / fair_l2_gas_price)
so factor is not used for gas_per_pubdata
. IMO we should rework fee provider so it's responsible for providing gas_per_pubdata
estimate.
Also, not sure about it but it seems if compute_overhead_part=1.0 then gas_price_scale_factor
has more effect on fair_l2_gas_price
than fair_pubdata_price
effectively decreasing gas_per_pubdata
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.
Agree, but not sure who/when will be able to tackle this in depth.
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.
Dumb question: Do I understand correctly that the changed logic influences zks_estimateFee
output only? (There are 2 other uses of gas estimation, eth_estimateGas
and zks_estimateL1ToL2Gas
, but they both seem to output only Fee.gas_limit
.) If so, gas_per_pubdata_limit
is overwritten before estimation to a hard-coded value (50,000); is this fine?
zksync-era/core/node/api_server/src/web3/namespaces/zks.rs
Lines 81 to 84 in c156e79
tx.common_data.fee.max_priority_fee_per_gas = 0u64.into(); | |
tx.common_data.fee.gas_per_pubdata_limit = U256::from(DEFAULT_L2_TX_GAS_PER_PUBDATA_BYTE); | |
self.estimate_fee(tx.into(), block_args, state_override) | |
.await |
It sort of contradicts "we should not exceed the limit that was provided by the user in the initial request", since the value provided by the user is ignored.
Yes.
Huh, that's both fine and not fine. I would expect |
Fixes the
gas_per_pubdata_limit
field calculation. Right now, we provide the value we get from deriving the existing batch input, which is most likely lower than limit provided in fee estimation request.Given that we scale the overall fee, it should be safe to scale the limit as well, as long as we don't go beyond the limit supplied in the tx.
Providing the limit as-is without scaling can be very flaky: transaction risks to be left in the mempool over minor
gas_per_pubdata
changes.