-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(en): more correct fees algorithm for external-node #3487
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
Changes from 6 commits
79e9222
290733a
1ec2c3a
1f158e3
caf9a72
b7e2066
306d5b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,9 @@ use std::{ | |
| }; | ||
|
|
||
| use tokio::sync::watch::Receiver; | ||
| use zksync_types::fee_model::FeeParams; | ||
| use zksync_types::fee_model::{ | ||
| BatchFeeInput, FeeModelConfigV1, FeeParams, FeeParamsV1, FeeParamsV2, | ||
| }; | ||
| use zksync_web3_decl::{ | ||
| client::{DynClient, L2}, | ||
| error::ClientRpcContext, | ||
|
|
@@ -25,13 +27,15 @@ const SLEEP_INTERVAL: Duration = Duration::from_secs(5); | |
| pub struct MainNodeFeeParamsFetcher { | ||
| client: Box<DynClient<L2>>, | ||
| main_node_fee_params: RwLock<FeeParams>, | ||
| main_node_batch_fee_input: RwLock<Option<BatchFeeInput>>, | ||
| } | ||
|
|
||
| impl MainNodeFeeParamsFetcher { | ||
| pub fn new(client: Box<DynClient<L2>>) -> Self { | ||
| Self { | ||
| client: client.for_component("fee_params_fetcher"), | ||
| main_node_fee_params: RwLock::new(FeeParams::sensible_v1_default()), | ||
| main_node_batch_fee_input: RwLock::new(None), | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -58,6 +62,28 @@ impl MainNodeFeeParamsFetcher { | |
| }; | ||
| *self.main_node_fee_params.write().unwrap() = main_node_fee_params; | ||
|
|
||
| let fetch_result = self | ||
| .client | ||
| .get_batch_fee_input() | ||
| .rpc_context("get_batch_fee_input") | ||
| .await; | ||
| let main_node_fee_params = match fetch_result { | ||
| Ok(price) => price, | ||
| Err(err) => { | ||
| tracing::warn!("Unable to get the batch fee input: {}", err); | ||
| // A delay to avoid spamming the main node with requests. | ||
| if tokio::time::timeout(SLEEP_INTERVAL, stop_receiver.changed()) | ||
| .await | ||
| .is_ok() | ||
| { | ||
| break; | ||
| } | ||
| continue; | ||
| } | ||
| }; | ||
| *self.main_node_batch_fee_input.write().unwrap() = | ||
| Some(BatchFeeInput::PubdataIndependent(main_node_fee_params)); | ||
|
|
||
| if tokio::time::timeout(SLEEP_INTERVAL, stop_receiver.changed()) | ||
| .await | ||
| .is_ok() | ||
|
|
@@ -73,6 +99,27 @@ impl MainNodeFeeParamsFetcher { | |
|
|
||
| impl BatchFeeModelInputProvider for MainNodeFeeParamsFetcher { | ||
| fn get_fee_model_params(&self) -> FeeParams { | ||
| *self.main_node_fee_params.read().unwrap() | ||
| let fee_params = *self.main_node_fee_params.read().unwrap(); | ||
| let batch_fee_input = *self.main_node_batch_fee_input.read().unwrap(); | ||
| if batch_fee_input.is_none() { | ||
| return fee_params; | ||
| } | ||
| let batch_fee_input = batch_fee_input.unwrap(); | ||
| match fee_params { | ||
| FeeParams::V1(..) => FeeParams::V1(FeeParamsV1 { | ||
| config: FeeModelConfigV1 { | ||
| minimal_l2_gas_price: batch_fee_input.fair_l2_gas_price(), | ||
| }, | ||
| l1_gas_price: batch_fee_input.l1_gas_price(), | ||
| }), | ||
| FeeParams::V2(params) => { | ||
| return FeeParams::V2(FeeParamsV2::new( | ||
| params.config(), | ||
| batch_fee_input.l1_gas_price(), | ||
| batch_fee_input.fair_pubdata_price(), | ||
| params.conversion_ratio(), | ||
| )); | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need all of this logic? Can't we just override |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.