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): define port for GasPriceDatabase #2226

Closed
wants to merge 15 commits into from
Closed
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. We definitely want to throw an error if this fails.

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
61 changes: 59 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 @@ -5,15 +5,29 @@ use crate::{
use fuel_core_gas_price_service::{
fuel_gas_price_updater::{
fuel_core_storage_adapter::{
storage::GasPriceMetadata,
GasPriceSettings,
GasPriceSettingsProvider,
},
Error as GasPriceError,
Result as GasPriceResult,
UpdaterMetadata,
},
ports::L2Data,
ports::{
GasPriceData,
L2Data,
MetadataStorage,
},
};
use fuel_core_storage::{
transactional::{
HistoricalView,
WriteTransaction,
},
Result as StorageResult,
StorageAsMut,
StorageAsRef,
};
use fuel_core_storage::Result as StorageResult;
use fuel_core_types::{
blockchain::{
block::Block,
Expand All @@ -23,6 +37,11 @@ use fuel_core_types::{
fuel_types::BlockHeight,
};

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

#[cfg(test)]
mod tests;

Expand All @@ -39,6 +58,44 @@ impl L2Data for OnChainIterableKeyValueView {
}
}

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

impl MetadataStorage for Database<GasPriceDatabase> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to duplicate the implementation here instead of deriving the blanket implementation from gas price service crate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 417459d

fn get_metadata(
&self,
block_height: &BlockHeight,
) -> GasPriceResult<Option<UpdaterMetadata>> {
let metadata = self
.storage::<GasPriceMetadata>()
.get(block_height)
.map_err(|err| GasPriceError::CouldNotFetchMetadata {
source_error: err.into(),
})?;
Ok(metadata.map(|inner| inner.into_owned()))
}

fn set_metadata(&mut self, metadata: &UpdaterMetadata) -> GasPriceResult<()> {
let block_height = metadata.l2_block_height();
let mut tx = self.write_transaction();
tx.storage_as_mut::<GasPriceMetadata>()
.insert(&block_height, metadata)
.map_err(|err| GasPriceError::CouldNotSetMetadata {
block_height,
source_error: err.into(),
})?;
tx.commit()
.map_err(|err| GasPriceError::CouldNotSetMetadata {
block_height,
source_error: err.into(),
})?;
Ok(())
}
}

impl GasPriceSettingsProvider for ConsensusParametersProvider {
fn settings(
&self,
Expand Down
Loading
Loading