-
Notifications
You must be signed in to change notification settings - Fork 2.9k
chore(gas_price_service): refactor gas price service #2192
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 3 commits
9ccc343
6cf9248
f0ad83a
f0bbf49
2f33f7b
00e0d06
d68b02d
69651a5
911c06f
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 |
|---|---|---|
|
|
@@ -24,12 +24,9 @@ pub mod fuel_core_storage_adapter; | |
|
|
||
| pub mod da_source_adapter; | ||
|
|
||
| pub struct FuelGasPriceUpdater<L2, Metadata, DaBlockCosts> { | ||
| pub struct FuelGasPriceUpdater<Metadata> { | ||
|
Member
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. Hmm. I'm not sure how much we are actually gaining from this. I was kinda thinking that we could get rid of the But I don't think the This approach commits us to a specific trait interface with l2_block: BlockInfo,
da_block_costs: Option<DaBlockCosts>,whereas before the
Member
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. We are going to want to add another value here soon with this issue: Should the trait change or the internal implementation. I think maybe the implementation.
Member
Author
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. okay. then I would propose to move the L2 source and DA back into the
Member
Author
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. (it also means we turn |
||
| inner: AlgorithmUpdater, | ||
| l2_block_source: L2, | ||
| metadata_storage: Metadata, | ||
| #[allow(dead_code)] | ||
| da_block_costs: DaBlockCosts, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq)] | ||
|
|
@@ -54,29 +51,23 @@ impl AlgorithmUpdater { | |
| } | ||
| } | ||
|
|
||
| impl<L2, Metadata, DaBlockCosts> FuelGasPriceUpdater<L2, Metadata, DaBlockCosts> { | ||
| pub fn new( | ||
| inner: AlgorithmUpdater, | ||
| l2_block_source: L2, | ||
| metadata_storage: Metadata, | ||
| da_block_costs: DaBlockCosts, | ||
| ) -> Self { | ||
| impl<Metadata> FuelGasPriceUpdater<Metadata> { | ||
| pub fn new(inner: AlgorithmUpdater, metadata_storage: Metadata) -> Self { | ||
| Self { | ||
| inner, | ||
| l2_block_source, | ||
| metadata_storage, | ||
| da_block_costs, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, thiserror::Error)] | ||
| pub enum Error { | ||
| #[error("Failed to find L2 block at height {block_height:?}: {source_error:?}")] | ||
| CouldNotFetchL2Block { | ||
| block_height: BlockHeight, | ||
| source_error: anyhow::Error, | ||
| }, | ||
| #[error("Failed to find L2 block: {source_error:?}")] | ||
| CouldNotFetchL2Block { source_error: anyhow::Error }, | ||
| #[error("Failed to compute: {source_error:?}")] | ||
| MathError { source_error: anyhow::Error }, | ||
| #[error("No Mint transaction in block")] | ||
| NoMintTx, | ||
| #[error("Failed to find DA records: {0:?}")] | ||
| CouldNotFetchDARecord(anyhow::Error), | ||
| #[error("Failed to retrieve updater metadata: {source_error:?}")] | ||
|
|
@@ -111,7 +102,7 @@ pub enum BlockInfo { | |
| } | ||
| #[async_trait::async_trait] | ||
| pub trait L2BlockSource: Send + Sync { | ||
| async fn get_l2_block(&mut self, height: BlockHeight) -> Result<BlockInfo>; | ||
| async fn get_l2_block(&mut self) -> Result<BlockInfo>; | ||
| } | ||
|
|
||
| #[derive(Debug, Default, Clone, Eq, Hash, PartialEq)] | ||
|
|
@@ -121,10 +112,6 @@ pub struct DaBlockCosts { | |
| pub blob_cost_wei: u128, | ||
| } | ||
|
|
||
| pub trait GetDaBlockCosts: Send + Sync { | ||
| fn get(&self) -> Result<Option<DaBlockCosts>>; | ||
| } | ||
|
|
||
| #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] | ||
| pub enum UpdaterMetadata { | ||
| V0(V0Metadata), | ||
|
|
@@ -206,16 +193,13 @@ pub trait MetadataStorage: Send + Sync { | |
| fn set_metadata(&mut self, metadata: UpdaterMetadata) -> Result<()>; | ||
| } | ||
|
|
||
| impl<L2, Metadata, DaBlockCosts> FuelGasPriceUpdater<L2, Metadata, DaBlockCosts> | ||
| impl<Metadata> FuelGasPriceUpdater<Metadata> | ||
| where | ||
| Metadata: MetadataStorage, | ||
| DaBlockCosts: GetDaBlockCosts, | ||
| { | ||
| pub fn init( | ||
| target_block_height: BlockHeight, | ||
| l2_block_source: L2, | ||
| metadata_storage: Metadata, | ||
| da_block_costs: DaBlockCosts, | ||
| min_exec_gas_price: u64, | ||
| exec_gas_price_change_percent: u64, | ||
| l2_block_fullness_threshold_percent: u64, | ||
|
|
@@ -240,9 +224,7 @@ where | |
| }; | ||
| let updater = Self { | ||
| inner, | ||
| l2_block_source, | ||
| metadata_storage, | ||
| da_block_costs, | ||
| }; | ||
| Ok(updater) | ||
| } | ||
|
|
@@ -266,6 +248,7 @@ where | |
| height: u32, | ||
| gas_used: u64, | ||
| block_gas_capacity: u64, | ||
| _da_block_costs: Option<DaBlockCosts>, | ||
| ) -> anyhow::Result<()> { | ||
| let capacity = self.validate_block_gas_capacity(block_gas_capacity)?; | ||
|
|
||
|
|
@@ -287,6 +270,7 @@ where | |
| async fn apply_block_info_to_gas_algorithm( | ||
| &mut self, | ||
| l2_block: BlockInfo, | ||
| da_block_costs: Option<DaBlockCosts>, | ||
| ) -> anyhow::Result<()> { | ||
| match l2_block { | ||
| BlockInfo::GenesisBlock => { | ||
|
|
@@ -297,37 +281,37 @@ where | |
| gas_used, | ||
| block_gas_capacity, | ||
| } => { | ||
| self.handle_normal_block(height, gas_used, block_gas_capacity) | ||
| .await?; | ||
| self.handle_normal_block( | ||
| height, | ||
| gas_used, | ||
| block_gas_capacity, | ||
| da_block_costs, | ||
| ) | ||
| .await?; | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[async_trait::async_trait] | ||
| impl<L2, Metadata, DaBlockCosts> UpdateAlgorithm | ||
| for FuelGasPriceUpdater<L2, Metadata, DaBlockCosts> | ||
| impl<Metadata> UpdateAlgorithm for FuelGasPriceUpdater<Metadata> | ||
| where | ||
| L2: L2BlockSource, | ||
| Metadata: MetadataStorage + Send + Sync, | ||
| DaBlockCosts: GetDaBlockCosts, | ||
| { | ||
| type Algorithm = Algorithm; | ||
|
|
||
| fn start(&self, _for_block: BlockHeight) -> Self::Algorithm { | ||
| self.inner.algorithm() | ||
| } | ||
|
|
||
| async fn next(&mut self) -> anyhow::Result<Self::Algorithm> { | ||
| let l2_block_res = self | ||
| .l2_block_source | ||
| .get_l2_block(self.inner.l2_block_height()) | ||
| .await; | ||
| tracing::info!("Received L2 block result: {:?}", l2_block_res); | ||
| let l2_block = l2_block_res?; | ||
|
|
||
| self.apply_block_info_to_gas_algorithm(l2_block).await?; | ||
| async fn next( | ||
| &mut self, | ||
| l2_block: BlockInfo, | ||
| da_block_costs: Option<DaBlockCosts>, | ||
| ) -> anyhow::Result<Self::Algorithm> { | ||
| self.apply_block_info_to_gas_algorithm(l2_block, da_block_costs) | ||
| .await?; | ||
|
|
||
| Ok(self.inner.algorithm()) | ||
| } | ||
|
|
||
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.
I think that most of the logic of this function should live inside the service itself. Only a small part of the
sync_metadata_storage_with_on_chain_storagelogic related to the on-chain database should live hereThere 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.
I agree ~ this is part of the follow up PR though, which sunsets
InitializeTaskappropriately.