Skip to content

Commit 8c67681

Browse files
rymncMitchTurner
andauthored
feat(gas_price_service): create runnable task for expensive background polling for da metadata (#2163)
> [!WARNING] > 🏗️ This PR is 2/3 of including block committer "da"ta in v1 of the gas price algo. We have a dependency on the api of the block committer, which will warrant tweaking of the `DaMetadataResponse` type. The next PR will hook it up with cli args 🚧 ## Linked Issues/PRs <!-- List of related issues/PRs --> - follow up to: #2155 - #2139 ## Description <!-- List of detailed changes --> - specified a Service that polls an ingestor at specified intervals to fetch the da metadata in the background - specified a "sync"/"non-expensive" api for the data, which marks it as stale/None after fetching it ## Checklist - [x] Breaking changes are clearly marked as such in the PR description and changelog - [x] New behavior is reflected in tests - [x] [The specification](https://github.com/FuelLabs/fuel-specs/) matches the implemented behavior (link update PR if changes are needed) ### Before requesting review - [x] I have reviewed the code myself - [x] I have created follow-up issues caused by this PR and linked them here ### After merging, notify other teams [Add or remove entries as needed] - [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/) - [ ] [Sway compiler](https://github.com/FuelLabs/sway/) - [ ] [Platform documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+) (for out-of-organization contributors, the person merging the PR will do this) - [ ] Someone else? --------- Co-authored-by: Mitchell Turner <[email protected]>
1 parent f308bae commit 8c67681

File tree

12 files changed

+426
-56
lines changed

12 files changed

+426
-56
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99
### Added
1010
- [2135](https://github.com/FuelLabs/fuel-core/pull/2135): Added metrics logging for number of blocks served over the p2p req/res protocol.
1111
- [2151](https://github.com/FuelLabs/fuel-core/pull/2151): Added limitations on gas used during dry_run in API.
12+
- [2163](https://github.com/FuelLabs/fuel-core/pull/2163): Added runnable task for fetching block committer data.
1213

1314
### Changed
1415

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/fuel-core/src/service/sub_services/algorithm_updater.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ use crate::{
1515

1616
use fuel_core_gas_price_service::{
1717
fuel_gas_price_updater::{
18+
da_source_adapter::{
19+
dummy_costs::DummyDaBlockCosts,
20+
DaBlockCostsProvider,
21+
DaBlockCostsSharedState,
22+
},
1823
fuel_core_storage_adapter::{
1924
storage::GasPriceMetadata,
2025
FuelL2BlockSource,
2126
GasPriceSettingsProvider,
2227
},
23-
fuel_da_source_adapter::FuelDaSource,
2428
Algorithm,
2529
AlgorithmUpdater,
2630
AlgorithmUpdaterV0,
@@ -35,6 +39,7 @@ use fuel_core_gas_price_service::{
3539
use fuel_core_services::{
3640
stream::BoxStream,
3741
RunnableService,
42+
Service,
3843
StateWatcher,
3944
};
4045
use fuel_core_storage::{
@@ -58,7 +63,7 @@ use fuel_core_types::{
5863
type Updater = FuelGasPriceUpdater<
5964
FuelL2BlockSource<ConsensusParametersProvider>,
6065
MetadataStorageAdapter,
61-
FuelDaSource,
66+
DaBlockCostsSharedState,
6267
>;
6368

6469
pub struct InitializeTask {
@@ -69,19 +74,13 @@ pub struct InitializeTask {
6974
pub on_chain_db: Database<OnChain, RegularStage<OnChain>>,
7075
pub block_stream: BoxStream<SharedImportResult>,
7176
pub shared_algo: SharedGasPriceAlgo<Algorithm>,
77+
pub da_block_costs_provider: DaBlockCostsProvider<DummyDaBlockCosts>,
7278
}
7379

7480
type MetadataStorageAdapter =
7581
StructuredStorage<Database<GasPriceDatabase, RegularStage<GasPriceDatabase>>>;
7682

77-
type Task = GasPriceService<
78-
Algorithm,
79-
FuelGasPriceUpdater<
80-
FuelL2BlockSource<ConsensusParametersProvider>,
81-
MetadataStorageAdapter,
82-
FuelDaSource,
83-
>,
84-
>;
83+
type Task = GasPriceService<Algorithm, Updater>;
8584

8685
impl InitializeTask {
8786
pub fn new(
@@ -99,6 +98,12 @@ impl InitializeTask {
9998
let default_metadata = get_default_metadata(&config, latest_block_height);
10099
let algo = get_best_algo(&gas_price_db, default_metadata)?;
101100
let shared_algo = SharedGasPriceAlgo::new_with_algorithm(algo);
101+
// there's no use of this source yet, so we can safely return an error
102+
let da_block_costs_source =
103+
DummyDaBlockCosts::new(Err(anyhow::anyhow!("Not used")));
104+
let da_block_costs_provider =
105+
DaBlockCostsProvider::new(da_block_costs_source, None);
106+
102107
let task = Self {
103108
config,
104109
genesis_block_height,
@@ -107,6 +112,7 @@ impl InitializeTask {
107112
on_chain_db,
108113
block_stream,
109114
shared_algo,
115+
da_block_costs_provider,
110116
};
111117
Ok(task)
112118
}
@@ -168,7 +174,13 @@ impl RunnableService for InitializeTask {
168174
self.gas_price_db,
169175
self.on_chain_db,
170176
self.block_stream,
177+
self.da_block_costs_provider.shared_state,
171178
)?;
179+
180+
self.da_block_costs_provider
181+
.service
182+
.start_and_await()
183+
.await?;
172184
let inner_service =
173185
GasPriceService::new(starting_height, updater, self.shared_algo).await;
174186
Ok(inner_service)
@@ -182,6 +194,7 @@ pub fn get_synced_gas_price_updater(
182194
mut gas_price_db: Database<GasPriceDatabase, RegularStage<GasPriceDatabase>>,
183195
on_chain_db: Database<OnChain, RegularStage<OnChain>>,
184196
block_stream: BoxStream<SharedImportResult>,
197+
da_block_costs: DaBlockCostsSharedState,
185198
) -> anyhow::Result<Updater> {
186199
let mut first_run = false;
187200
let latest_block_height: u32 = on_chain_db
@@ -217,7 +230,7 @@ pub fn get_synced_gas_price_updater(
217230
default_metadata.into(),
218231
l2_block_source,
219232
metadata_storage,
220-
FuelDaSource,
233+
da_block_costs,
221234
);
222235
Ok(updater)
223236
} else {
@@ -235,7 +248,7 @@ pub fn get_synced_gas_price_updater(
235248
latest_block_height.into(),
236249
l2_block_source,
237250
metadata_storage,
238-
FuelDaSource,
251+
da_block_costs,
239252
config.min_gas_price,
240253
config.gas_price_change_percent,
241254
config.gas_price_threshold_percent,

crates/services/gas_price_service/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fuel-core-types = { workspace = true, features = ["std"] }
1818
fuel-gas-price-algorithm = { workspace = true }
1919
futures = { workspace = true }
2020
num_enum = { workspace = true }
21+
reqwest = { workspace = true, features = ["json"] }
2122
serde = { workspace = true }
2223
strum = { workspace = true, features = ["derive"] }
2324
strum_macros = { workspace = true }

crates/services/gas_price_service/src/fuel_gas_price_updater.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ pub use fuel_gas_price_algorithm::{
2121
mod tests;
2222

2323
pub mod fuel_core_storage_adapter;
24-
pub mod fuel_da_source_adapter;
2524

26-
pub struct FuelGasPriceUpdater<L2, Metadata, DaSource> {
25+
pub mod da_source_adapter;
26+
27+
pub struct FuelGasPriceUpdater<L2, Metadata, DaBlockCosts> {
2728
inner: AlgorithmUpdater,
2829
l2_block_source: L2,
2930
metadata_storage: Metadata,
3031
#[allow(dead_code)]
31-
da_source: DaSource,
32+
da_block_costs: DaBlockCosts,
3233
}
3334

3435
#[derive(Debug, Clone, PartialEq)]
@@ -53,18 +54,18 @@ impl AlgorithmUpdater {
5354
}
5455
}
5556

56-
impl<L2, Metadata, DaSource> FuelGasPriceUpdater<L2, Metadata, DaSource> {
57+
impl<L2, Metadata, DaBlockCosts> FuelGasPriceUpdater<L2, Metadata, DaBlockCosts> {
5758
pub fn new(
5859
inner: AlgorithmUpdater,
5960
l2_block_source: L2,
6061
metadata_storage: Metadata,
61-
da_source: DaSource,
62+
da_block_costs: DaBlockCosts,
6263
) -> Self {
6364
Self {
6465
inner,
6566
l2_block_source,
6667
metadata_storage,
67-
da_source,
68+
da_block_costs,
6869
}
6970
}
7071
}
@@ -113,16 +114,15 @@ pub trait L2BlockSource: Send + Sync {
113114
async fn get_l2_block(&mut self, height: BlockHeight) -> Result<BlockInfo>;
114115
}
115116

116-
#[derive(Debug, Default)]
117-
pub struct DaCommitDetails {
117+
#[derive(Debug, Default, Clone, Eq, Hash, PartialEq)]
118+
pub struct DaBlockCosts {
118119
pub l2_block_range: core::ops::Range<u32>,
119120
pub blob_size_bytes: u32,
120-
pub blob_cost_wei: u32,
121-
pub partial_block_heights: Option<[u32; 2]>,
121+
pub blob_cost_wei: u128,
122122
}
123123

124-
pub trait DaCommitSource: Send + Sync {
125-
fn get_da_commit_details(&mut self) -> Result<Option<DaCommitDetails>>;
124+
pub trait GetDaBlockCosts: Send + Sync {
125+
fn get(&self) -> Result<Option<DaBlockCosts>>;
126126
}
127127

128128
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)]
@@ -206,16 +206,16 @@ pub trait MetadataStorage: Send + Sync {
206206
fn set_metadata(&mut self, metadata: UpdaterMetadata) -> Result<()>;
207207
}
208208

209-
impl<L2, Metadata, DaSource> FuelGasPriceUpdater<L2, Metadata, DaSource>
209+
impl<L2, Metadata, DaBlockCosts> FuelGasPriceUpdater<L2, Metadata, DaBlockCosts>
210210
where
211211
Metadata: MetadataStorage,
212-
DaSource: DaCommitSource,
212+
DaBlockCosts: GetDaBlockCosts,
213213
{
214214
pub fn init(
215215
target_block_height: BlockHeight,
216216
l2_block_source: L2,
217217
metadata_storage: Metadata,
218-
da_source: DaSource,
218+
da_block_costs: DaBlockCosts,
219219
min_exec_gas_price: u64,
220220
exec_gas_price_change_percent: u64,
221221
l2_block_fullness_threshold_percent: u64,
@@ -242,7 +242,7 @@ where
242242
inner,
243243
l2_block_source,
244244
metadata_storage,
245-
da_source,
245+
da_block_costs,
246246
};
247247
Ok(updater)
248248
}
@@ -306,12 +306,12 @@ where
306306
}
307307

308308
#[async_trait::async_trait]
309-
impl<L2, Metadata, DaSource> UpdateAlgorithm
310-
for FuelGasPriceUpdater<L2, Metadata, DaSource>
309+
impl<L2, Metadata, DaBlockCosts> UpdateAlgorithm
310+
for FuelGasPriceUpdater<L2, Metadata, DaBlockCosts>
311311
where
312312
L2: L2BlockSource,
313313
Metadata: MetadataStorage + Send + Sync,
314-
DaSource: DaCommitSource,
314+
DaBlockCosts: GetDaBlockCosts,
315315
{
316316
type Algorithm = Algorithm;
317317

0 commit comments

Comments
 (0)