Skip to content
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

chore(gas_price_service): move algorithm_updater to fuel-core-gas-price-service #2246

Merged
merged 22 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5702371
chore(gas_price_service): define port for gas price db lookups
rymnc Sep 19, 2024
ac699b9
fix: pass metadata by ref
rymnc Sep 20, 2024
1c296b4
Merge branch 'master' into chore/gas-price-service-ports-p2
MitchTurner Sep 23, 2024
100b5b8
chore: use structured storage strat
rymnc Sep 23, 2024
9575a21
chore: rollback centrally
rymnc Sep 23, 2024
e5f5d92
fix: dont sync if nothing in onchain db
rymnc Sep 23, 2024
b2aa337
test: swallow error for soft rollback
rymnc Sep 23, 2024
2953019
fix: log warning if rollback failed
rymnc Sep 23, 2024
96e52c2
chore(gas_price_service): remove dependency on Config from fuel-core
rymnc Sep 20, 2024
ed5c8b4
chore(gas_price_service): use port for GasPriceSettings instead of co…
rymnc Sep 24, 2024
62343d7
fix: retain test
rymnc Sep 24, 2024
d51d494
chore: add comment
rymnc Sep 24, 2024
417459d
fix: remove impl for Database
rymnc Sep 24, 2024
2e6a9d3
fix: docstring
rymnc Sep 24, 2024
64818a6
fix: improved comment for GasPriceData
rymnc Sep 24, 2024
986ef13
Merge branch 'master' into chore/gas-price-service-ports-p2
xgreenx Sep 25, 2024
a1dd833
Merge branch 'chore/gas-price-service-ports-p2' into chore/gas-price-…
rymnc Sep 25, 2024
0e3cc6f
Merge branch 'chore/gas-price-service-ports-p3' into chore/gas-price-…
rymnc Sep 25, 2024
42b3550
fix: lint
rymnc Sep 25, 2024
9cdc1ee
chore(gas_price_servie): move algorithm_updater to fuel-core-gas-pric…
rymnc Sep 24, 2024
d5a5e0b
Merge branch 'master' into chore/gas-price-service-ports-p5
rymnc Sep 25, 2024
c6f6871
Merge branch 'master' into chore/gas-price-service-ports-p5
rymnc Sep 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions crates/fuel-core/src/combined_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,21 @@ impl CombinedDatabase {

Ok(())
}

pub fn sync_aux_db_heights<S>(&self, shutdown_listener: &mut S) -> anyhow::Result<()>
where
S: ShutdownListener,
{
if let Some(on_chain_height) = self.on_chain().latest_height_from_metadata()? {
// todo(https://github.com/FuelLabs/fuel-core/issues/2239): This is a temporary fix
let res = self.rollback_to(on_chain_height, shutdown_listener);
if res.is_err() {
tracing::warn!("Failed to rollback auxiliary databases to on-chain database height: {:?}", res);
}
};

Ok(())
}
}

/// A trait for listening to shutdown signals.
Expand Down
1 change: 1 addition & 0 deletions crates/fuel-core/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl FuelService {

// initialize sub services
tracing::info!("Initializing sub services");
database.sync_aux_db_heights(shutdown_listener)?;
let (services, shared) = sub_services::init_sub_services(&config, database)?;

let sub_services = Arc::new(services);
Expand Down
36 changes: 34 additions & 2 deletions crates/fuel-core/src/service/adapters/gas_price_adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ use fuel_core_gas_price_service::{
Error as GasPriceError,
Result as GasPriceResult,
},
ports::L2Data,
ports::{
GasPriceData,
GasPriceServiceConfig,
L2Data,
},
};
use fuel_core_storage::{
transactional::HistoricalView,
Result as StorageResult,
};
use fuel_core_storage::Result as StorageResult;
use fuel_core_types::{
blockchain::{
block::Block,
Expand All @@ -23,6 +30,14 @@ use fuel_core_types::{
fuel_types::BlockHeight,
};

use crate::{
database::{
database_description::gas_price::GasPriceDatabase,
Database,
},
service::Config,
};

#[cfg(test)]
mod tests;

Expand All @@ -39,6 +54,23 @@ impl L2Data for OnChainIterableKeyValueView {
}
}

impl GasPriceData for Database<GasPriceDatabase> {
fn latest_height(&self) -> Option<BlockHeight> {
HistoricalView::latest_height(self)
}
}

impl From<Config> for GasPriceServiceConfig {
fn from(value: Config) -> Self {
GasPriceServiceConfig::new(
value.min_gas_price,
value.starting_gas_price,
value.gas_price_change_percent,
value.gas_price_threshold_percent,
)
}
}

impl GasPriceSettingsProvider for ConsensusParametersProvider {
fn settings(
&self,
Expand Down
5 changes: 2 additions & 3 deletions crates/fuel-core/src/service/sub_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use crate::{
};
#[allow(unused_imports)]
use fuel_core_gas_price_service::fuel_gas_price_updater::{
algorithm_updater,
fuel_core_storage_adapter::FuelL2BlockSource,
Algorithm,
AlgorithmV0,
Expand All @@ -64,8 +65,6 @@ use fuel_core_types::blockchain::primitives::DaBlockHeight;
use std::sync::Arc;
use tokio::sync::Mutex;

mod algorithm_updater;

pub type PoAService = fuel_core_poa::Service<
TxPoolAdapter,
BlockProducerAdapter,
Expand Down Expand Up @@ -201,7 +200,7 @@ pub fn init_sub_services(
let block_stream = importer_adapter.events_shared_result();

let gas_price_init = algorithm_updater::InitializeTask::new(
config.clone(),
config.clone().into(),
genesis_block_height,
settings,
block_stream,
Expand Down
22 changes: 10 additions & 12 deletions crates/services/gas_price_service/src/fuel_gas_price_updater.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
ports::MetadataStorage,
GasPriceAlgorithm,
UpdateAlgorithm,
};
Expand All @@ -22,6 +23,7 @@ mod tests;

pub mod fuel_core_storage_adapter;

pub mod algorithm_updater;
pub mod da_source_adapter;

pub struct FuelGasPriceUpdater<L2, Metadata, DaBlockCosts> {
Expand Down Expand Up @@ -200,12 +202,6 @@ impl From<AlgorithmUpdater> for UpdaterMetadata {
}
}

pub trait MetadataStorage: Send + Sync {
fn get_metadata(&self, block_height: &BlockHeight)
-> Result<Option<UpdaterMetadata>>;
fn set_metadata(&mut self, metadata: UpdaterMetadata) -> Result<()>;
}

impl<L2, Metadata, DaBlockCosts> FuelGasPriceUpdater<L2, Metadata, DaBlockCosts>
where
Metadata: MetadataStorage,
Expand All @@ -220,12 +216,13 @@ where
exec_gas_price_change_percent: u64,
l2_block_fullness_threshold_percent: u64,
) -> Result<Self> {
let old_metadata = metadata_storage.get_metadata(&target_block_height)?.ok_or(
Error::CouldNotInitUpdater(anyhow::anyhow!(
let old_metadata = metadata_storage
.get_metadata(&target_block_height)
.map_err(|err| Error::CouldNotInitUpdater(anyhow::anyhow!(err)))?
.ok_or(Error::CouldNotInitUpdater(anyhow::anyhow!(
"No metadata found for block height: {:?}",
target_block_height
)),
)?;
)))?;
let inner = match old_metadata {
UpdaterMetadata::V0(old) => {
let v0 = AlgorithmUpdaterV0::new(
Expand Down Expand Up @@ -256,8 +253,9 @@ where
}

async fn set_metadata(&mut self) -> anyhow::Result<()> {
let metadata = self.inner.clone().into();
self.metadata_storage
.set_metadata(self.inner.clone().into())
.set_metadata(&metadata)
.map_err(|err| anyhow!(err))
}

Expand Down Expand Up @@ -310,7 +308,7 @@ impl<L2, Metadata, DaBlockCosts> UpdateAlgorithm
for FuelGasPriceUpdater<L2, Metadata, DaBlockCosts>
where
L2: L2BlockSource,
Metadata: MetadataStorage + Send + Sync,
Metadata: MetadataStorage,
DaBlockCosts: GetDaBlockCosts,
{
type Algorithm = Algorithm;
Expand Down
Loading
Loading