madara
madara copied to clipboard
feat: Return fee estimate that make sense
Feature Request
Describe the Feature Request
Right now all our fee estimation methods return mocked/false values. We should fix that.
Describe Preferred Solution
simulate_transaction
#329 is still not fixed, but it can be now replace
.map(|x| FeeEstimate {
>>>> gas_price: FieldElement::from(10u128),
<<<< gas_price: fee_estimate.0.try_into().map_err(|_| StarknetRpcApiError::InternalServerError)?,
gas_consumed: FieldElement::from(x.1),
overall_fee: FieldElement::from(x.0),
unit: PriceUnit::Wei,
})
get_block
-like RPCs
Right now the code contains in multiple places:
// TODO: fill real prices
l1_gas_price: ResourcePrice { price_in_fri: Default::default(), price_in_wei: Default::default() },
Instead, get the price from the block header gas_prices
field, it contains eth_l1_gas_price
and strk_l1_gas_price
, which are the values we are looking for.
Estimate fee
Right now we are totally wrong on our fee estimation. We return (exec_info.actual_fee.0, *l1_gas_usage)
in crates/pallets/starknet/src/simulations.rs
as values for overal_fee
and gas_consumed
. That is not how the protocol is supposed to work: https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/fee-mechanism/
We should follow this specifications, for this we can take inspiration of the pathfinder implementation here: https://github.com/eqlabs/pathfinder/blob/main/crates/executor/src/estimate.rs#L12
Hey, I can pick this up
I am thinking of this logic to fetch the L1 gas price per block
- Create a new inherent to set_l1_gas_price similar to sequencer address
- Use the eth_config being created in service.rs here - https://github.com/apoorvsadana/madara/blob/main/crates/node/src/service.rs#L467-L467 outside
- In
create_inherent_data_providers
- https://github.com/apoorvsadana/madara/blob/main/crates/node/src/service.rs#L521-L521 fetch the gas price and push it into the inherent
wdyt?
In create_inherent_data_providers - https://github.com/apoorvsadana/madara/blob/main/crates/node/src/service.rs#L521-L521 fetch the gas price and push it into the inherent
Where will you be fetching the gas price from? Will you be doing some http request?
Wouldn't it be better to maintain an in-memory value last_observed_gas_price
and use it when needed?
Yes over an http request.
Where will the variable last_observed_gas_price
be exactly?
Won't it delay the block production by the time of the http request? It could be a some sort of global const in the crate? With a worker updating it
Won't it delay the block production by the time of the http request? It could be a some sort of global const in the crate? With a worker updating it
Hmm, fair point. So a worker updates some const every X seconds and the start of a new block, an inherent fetches the latest storage value and inserts it into the runtime?
Hmm, fair point. So a worker updates some const every X seconds and the start of a new block, an inherent fetches the latest storage value and inserts it into the runtime?
That is what I would say. The gas price is updated every eth block, no? We are listening to them anyway for messages, no? Or do we need to call some offchain oracle to get the price?
On eth, the gas price isn't a part of the block header afaik. It's just a metric based on the supply and demand.
Decentralizing this will be a terrible experience...
Why? The author node can set the l1_gas_price based however it likes, other nodes can reject it if they feel its incorrect (similar to the timestamp inherent)
Resolved with #1601