From 24cada3c3e04391345da243b17352389c958273c Mon Sep 17 00:00:00 2001 From: Guy Nir Date: Mon, 27 Jan 2025 16:33:57 +0200 Subject: [PATCH] feat(starknet_l1_provider): add the trait interface for L1 gas price provider --- .../src/l1_gas_price_provider.rs | 31 +++++++++++++++++++ crates/starknet_l1_provider/src/lib.rs | 1 + 2 files changed, 32 insertions(+) create mode 100644 crates/starknet_l1_provider/src/l1_gas_price_provider.rs diff --git a/crates/starknet_l1_provider/src/l1_gas_price_provider.rs b/crates/starknet_l1_provider/src/l1_gas_price_provider.rs new file mode 100644 index 00000000000..d169582bd6d --- /dev/null +++ b/crates/starknet_l1_provider/src/l1_gas_price_provider.rs @@ -0,0 +1,31 @@ +use starknet_api::block::{BlockNumber, BlockTimestamp}; +use thiserror::Error; + +// TODO(guyn): both these constants need to go into VersionedConstants. +pub const MEAN_NUMBER_OF_BLOCKS: u64 = 300; +pub const LAG_MARGIN_SECONDS: u64 = 60; + +// TODO(guyn, Gilad): consider moving this to starknet_l1_provider_types/lib.rs? +// This is an interface that allows sharing the provider with the scraper across threads. +pub trait L1GasPriceProviderClient: Send + Sync { + fn add_price_info( + &self, + height: BlockNumber, + timestamp: BlockTimestamp, + gas_price: u128, + data_gas_price: u128, + ) -> Result<(), L1GasPriceProviderError>; + + fn get_price_info( + &self, + timestamp: BlockTimestamp, + ) -> Result<(u128, u128), L1GasPriceProviderError>; +} + +#[derive(Clone, Debug, Error)] +pub enum L1GasPriceProviderError { + #[error("Failed to add price info: {0}")] + AddPriceInfoError(String), + #[error("Failed to get price info: {0}")] + GetPriceInfoError(String), +} diff --git a/crates/starknet_l1_provider/src/lib.rs b/crates/starknet_l1_provider/src/lib.rs index c78df376c86..d616abf0784 100644 --- a/crates/starknet_l1_provider/src/lib.rs +++ b/crates/starknet_l1_provider/src/lib.rs @@ -2,6 +2,7 @@ pub mod bootstrapper; use papyrus_config::converters::deserialize_float_seconds_to_duration; pub mod communication; +pub mod l1_gas_price_provider; pub mod l1_provider; pub mod l1_scraper; pub mod soft_delete_index_map;