diff --git a/crates/apollo_consensus_orchestrator/src/build_proposal.rs b/crates/apollo_consensus_orchestrator/src/build_proposal.rs index 9afa23cae04..7881c31dbf8 100644 --- a/crates/apollo_consensus_orchestrator/src/build_proposal.rs +++ b/crates/apollo_consensus_orchestrator/src/build_proposal.rs @@ -15,7 +15,7 @@ use apollo_batcher_types::batcher_types::{ use apollo_batcher_types::communication::{BatcherClient, BatcherClientError}; use apollo_consensus::types::{ProposalCommitment, Round}; use apollo_consensus_orchestrator_config::config::PricePerHeight; -use apollo_l1_gas_price_types::errors::{EthToStrkOracleClientError, L1GasPriceClientError}; +use apollo_l1_gas_price_types::errors::{L1GasPriceClientError, PriceOracleClientError}; use apollo_protobuf::consensus::{ BuildParam, CommitmentParts, @@ -94,7 +94,7 @@ pub(crate) enum BuildProposalError { #[error("Failed to send proposal part: {0}")] SendError(String), #[error("EthToStrkOracle error: {0}")] - EthToStrkOracle(#[from] EthToStrkOracleClientError), + EthToStrkOracle(#[from] PriceOracleClientError), #[error("L1GasPriceProvider error: {0}")] L1GasPriceProvider(#[from] L1GasPriceClientError), #[error("Proposal interrupted.")] diff --git a/crates/apollo_consensus_orchestrator/src/sequencer_consensus_context_test.rs b/crates/apollo_consensus_orchestrator/src/sequencer_consensus_context_test.rs index 750c64c0d24..e66ef850d78 100644 --- a/crates/apollo_consensus_orchestrator/src/sequencer_consensus_context_test.rs +++ b/crates/apollo_consensus_orchestrator/src/sequencer_consensus_context_test.rs @@ -22,9 +22,9 @@ use apollo_consensus_orchestrator_config::config::{ PricePerHeight, }; use apollo_l1_gas_price_types::errors::{ - EthToStrkOracleClientError, L1GasPriceClientError, L1GasPriceProviderError, + PriceOracleClientError, }; use apollo_l1_gas_price_types::{MockL1GasPriceProviderClient, PriceInfo}; use apollo_protobuf::consensus::{ @@ -852,8 +852,8 @@ async fn oracle_fails_on_startup(#[case] l1_oracle_failure: bool) { }) }); l1_prices_oracle_client.expect_get_eth_to_fri_rate().times(1).return_once(|_| { - Err(L1GasPriceClientError::EthToStrkOracleClientError( - EthToStrkOracleClientError::MissingFieldError("".to_string(), "".to_string()), + Err(L1GasPriceClientError::PriceOracleClientError( + PriceOracleClientError::MissingFieldError("".to_string(), "".to_string()), )) }); deps.l1_gas_price_provider = l1_prices_oracle_client; @@ -951,8 +951,8 @@ async fn oracle_fails_on_second_block(#[case] l1_oracle_failure: bool) { .return_once(|_| Ok(ETH_TO_FRI_RATE)); // Set the eth_to_fri_rate to fail on second block. l1_prices_oracle_client.expect_get_eth_to_fri_rate().times(1).return_once(|_| { - Err(L1GasPriceClientError::EthToStrkOracleClientError( - EthToStrkOracleClientError::MissingFieldError("".to_string(), "".to_string()), + Err(L1GasPriceClientError::PriceOracleClientError( + PriceOracleClientError::MissingFieldError("".to_string(), "".to_string()), )) }); deps.l1_gas_price_provider = l1_prices_oracle_client; diff --git a/crates/apollo_consensus_orchestrator/src/validate_proposal.rs b/crates/apollo_consensus_orchestrator/src/validate_proposal.rs index af0ac46786b..e806465ae9e 100644 --- a/crates/apollo_consensus_orchestrator/src/validate_proposal.rs +++ b/crates/apollo_consensus_orchestrator/src/validate_proposal.rs @@ -17,7 +17,7 @@ use apollo_batcher_types::batcher_types::{ use apollo_batcher_types::communication::{BatcherClient, BatcherClientError}; use apollo_batcher_types::errors::BatcherError; use apollo_consensus::types::ProposalCommitment; -use apollo_l1_gas_price_types::errors::{EthToStrkOracleClientError, L1GasPriceClientError}; +use apollo_l1_gas_price_types::errors::{L1GasPriceClientError, PriceOracleClientError}; use apollo_l1_gas_price_types::L1GasPriceProviderClient; use apollo_protobuf::consensus::{ProposalFin, ProposalInit, ProposalPart, TransactionBatch}; use apollo_state_sync_types::communication::SharedStateSyncClient; @@ -111,7 +111,7 @@ pub(crate) enum ValidateProposalError { #[error("Failed to send commitment to consensus: {0}")] SendError(ProposalCommitment), #[error("EthToStrkOracle error: {0}")] - EthToStrkOracle(#[from] EthToStrkOracleClientError), + EthToStrkOracle(#[from] PriceOracleClientError), #[error("L1GasPriceProvider error: {0}")] L1GasPriceProvider(#[from] L1GasPriceClientError), #[error("ProposalInit conversion error: {0}")] diff --git a/crates/apollo_l1_gas_price/src/eth_to_strk_oracle.rs b/crates/apollo_l1_gas_price/src/eth_to_strk_oracle.rs index 456d6814be1..8bd7a2fa466 100644 --- a/crates/apollo_l1_gas_price/src/eth_to_strk_oracle.rs +++ b/crates/apollo_l1_gas_price/src/eth_to_strk_oracle.rs @@ -6,7 +6,7 @@ use std::time::Duration; use apollo_config::secrets::Sensitive; use apollo_l1_gas_price_config::config::EthToStrkOracleConfig; -use apollo_l1_gas_price_types::errors::EthToStrkOracleClientError; +use apollo_l1_gas_price_types::errors::PriceOracleClientError; use apollo_l1_gas_price_types::EthToStrkOracleClientTrait; use apollo_metrics::metrics::set_unix_now_seconds; use async_trait::async_trait; @@ -52,7 +52,7 @@ pub struct UrlAndHeaderMap { pub headers: Sensitive, } -type PriceQuery = AbortOnDropHandle>; +type PriceQuery = AbortOnDropHandle>; /// Client for interacting with the eth to strk Oracle API. #[derive(Clone, Debug)] @@ -101,7 +101,7 @@ impl EthToStrkOracleClient { fn spawn_query( &self, quantized_timestamp: u64, - ) -> AbortOnDropHandle> { + ) -> AbortOnDropHandle> { assert!( self.config.lag_interval_seconds > 0, "lag_interval_seconds should be greater than 0" @@ -127,7 +127,7 @@ impl EthToStrkOracleClient { .await?; let body = response.text().await?; let rate = resolve_query(body)?; - Ok::<_, EthToStrkOracleClientError>(rate) + Ok::<_, PriceOracleClientError>(rate) }) .await; @@ -148,40 +148,35 @@ impl EthToStrkOracleClient { ETH_TO_STRK_ERROR_COUNT.increment(1); } warn!("All {list_len} URLs in the list failed for timestamp {adjusted_timestamp}"); - Err(EthToStrkOracleClientError::AllUrlsFailedError(adjusted_timestamp, initial_index)) + Err(PriceOracleClientError::AllUrlsFailedError(adjusted_timestamp, initial_index)) }; AbortOnDropHandle::new(tokio::spawn(future)) } } -fn resolve_query(body: String) -> Result { +fn resolve_query(body: String) -> Result { let Ok(json): Result = serde_json::from_str(&body) else { - return Err(EthToStrkOracleClientError::ParseError(format!( - "Failed to parse JSON: {body}" - ))); + return Err(PriceOracleClientError::ParseError(format!("Failed to parse JSON: {body}"))); }; // Extract price from API response. Also returns MissingFieldError if value is not a string. let price = match json.get("price").and_then(|v| v.as_str()) { Some(price) => price, None => { - return Err(EthToStrkOracleClientError::MissingFieldError("price".to_string(), body)); + return Err(PriceOracleClientError::MissingFieldError("price".to_string(), body)); } }; let rate = u128::from_str_radix(price.trim_start_matches("0x"), 16).map_err(|e| { - EthToStrkOracleClientError::ParseError(format!("Failed to parse price {price}: {e}")) + PriceOracleClientError::ParseError(format!("Failed to parse price {price}: {e}")) })?; // Extract decimals from API response. Also returns MissingFieldError if value is not a number. let decimals = match json.get("decimals").and_then(|v| v.as_u64()) { Some(decimals) => decimals, None => { - return Err(EthToStrkOracleClientError::MissingFieldError( - "decimals".to_string(), - body, - )); + return Err(PriceOracleClientError::MissingFieldError("decimals".to_string(), body)); } }; if decimals != ETH_TO_STRK_QUANTIZATION { - return Err(EthToStrkOracleClientError::InvalidDecimalsError( + return Err(PriceOracleClientError::InvalidDecimalsError( ETH_TO_STRK_QUANTIZATION, decimals, )); @@ -198,7 +193,7 @@ impl EthToStrkOracleClientTrait for EthToStrkOracleClient { /// - `price`: a hexadecimal string representing the price. /// - `decimals`: a `u64` value, must be equal to `ETH_TO_STRK_QUANTIZATION`. #[instrument(skip(self))] - async fn eth_to_fri_rate(&self, timestamp: u64) -> Result { + async fn eth_to_fri_rate(&self, timestamp: u64) -> Result { const NUMBER_OF_TIMESTAMPS_BACK: u64 = 1; let quantized_timestamp = (timestamp - self.config.lag_interval_seconds) .checked_div(self.config.lag_interval_seconds) @@ -229,7 +224,7 @@ impl EthToStrkOracleClientTrait for EthToStrkOracleClient { return Ok(*rate); } // If not, return a query not ready error. - return Err(EthToStrkOracleClientError::QueryNotReadyError(timestamp)); + return Err(PriceOracleClientError::QueryNotReadyError(timestamp)); } let result = handle.now_or_never().expect("Handle must be finished if we got here"); let rate = match result { @@ -245,7 +240,7 @@ impl EthToStrkOracleClientTrait for EthToStrkOracleClient { ETH_TO_STRK_ERROR_COUNT.increment(1); // Must remove failed query from the cache, to avoid re-polling it. queries.pop(&quantized_timestamp); - return Err(EthToStrkOracleClientError::JoinError(e.to_string())); + return Err(PriceOracleClientError::JoinError(e.to_string())); } }; diff --git a/crates/apollo_l1_gas_price/src/eth_to_strk_oracle_test.rs b/crates/apollo_l1_gas_price/src/eth_to_strk_oracle_test.rs index 947473602ab..ffe8dea18b6 100644 --- a/crates/apollo_l1_gas_price/src/eth_to_strk_oracle_test.rs +++ b/crates/apollo_l1_gas_price/src/eth_to_strk_oracle_test.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use std::time::Duration; use apollo_config::converters::UrlAndHeaders; -use apollo_l1_gas_price_types::errors::EthToStrkOracleClientError; +use apollo_l1_gas_price_types::errors::PriceOracleClientError; use apollo_l1_gas_price_types::EthToStrkOracleClientTrait; use mockito::{Mock, ServerGuard}; use serde_json::json; @@ -211,8 +211,8 @@ async fn eth_to_fri_rate_two_urls() { loop { match client.eth_to_fri_rate(TIMESTAMP2).await { Ok(_) => panic!("Both servers should be returning bad JSON!"), - Err(EthToStrkOracleClientError::QueryNotReadyError(_)) => {} - Err(EthToStrkOracleClientError::AllUrlsFailedError(_, index)) => { + Err(PriceOracleClientError::QueryNotReadyError(_)) => {} + Err(PriceOracleClientError::AllUrlsFailedError(_, index)) => { assert!(index == 1, "Last error should be index 1 (server2)."); break; // This is the expected error, since server1 and 2 returned bad JSON. } diff --git a/crates/apollo_l1_gas_price/src/l1_gas_price_provider.rs b/crates/apollo_l1_gas_price/src/l1_gas_price_provider.rs index 4983a0ee354..940299c2086 100644 --- a/crates/apollo_l1_gas_price/src/l1_gas_price_provider.rs +++ b/crates/apollo_l1_gas_price/src/l1_gas_price_provider.rs @@ -188,7 +188,7 @@ impl L1GasPriceProvider { self.eth_to_strk_oracle_client .eth_to_fri_rate(timestamp) .await - .map_err(L1GasPriceProviderError::EthToStrkOracleClientError) + .map_err(L1GasPriceProviderError::PriceOracleClientError) } } diff --git a/crates/apollo_l1_gas_price_types/src/errors.rs b/crates/apollo_l1_gas_price_types/src/errors.rs index 844b741e996..2d8efeadf76 100644 --- a/crates/apollo_l1_gas_price_types/src/errors.rs +++ b/crates/apollo_l1_gas_price_types/src/errors.rs @@ -18,7 +18,7 @@ pub enum L1GasPriceProviderError { )] StaleL1GasPricesError { current_timestamp: u64, last_valid_price_timestamp: u64 }, #[error(transparent)] - EthToStrkOracleClientError(#[from] EthToStrkOracleClientError), + PriceOracleClientError(#[from] PriceOracleClientError), } #[derive(Clone, Debug, Error)] @@ -28,11 +28,11 @@ pub enum L1GasPriceClientError { #[error(transparent)] L1GasPriceProviderError(#[from] L1GasPriceProviderError), #[error(transparent)] - EthToStrkOracleClientError(#[from] EthToStrkOracleClientError), + PriceOracleClientError(#[from] PriceOracleClientError), } #[derive(Clone, Debug, Error, Serialize, Deserialize, PartialEq, Eq)] -pub enum EthToStrkOracleClientError { +pub enum PriceOracleClientError { #[error("Join error: {0}")] JoinError(String), #[error("Request error: {0}")] @@ -49,8 +49,8 @@ pub enum EthToStrkOracleClientError { AllUrlsFailedError(u64, usize), } -impl From for EthToStrkOracleClientError { +impl From for PriceOracleClientError { fn from(value: reqwest::Error) -> Self { - EthToStrkOracleClientError::RequestError(value.to_string()) + PriceOracleClientError::RequestError(value.to_string()) } } diff --git a/crates/apollo_l1_gas_price_types/src/lib.rs b/crates/apollo_l1_gas_price_types/src/lib.rs index 5a45def382e..9096068a274 100644 --- a/crates/apollo_l1_gas_price_types/src/lib.rs +++ b/crates/apollo_l1_gas_price_types/src/lib.rs @@ -12,7 +12,7 @@ use apollo_infra::{ }; use apollo_metrics::generate_permutation_labels; use async_trait::async_trait; -use errors::{EthToStrkOracleClientError, L1GasPriceClientError, L1GasPriceProviderError}; +use errors::{L1GasPriceClientError, L1GasPriceProviderError, PriceOracleClientError}; #[cfg(any(feature = "testing", test))] use mockall::automock; use papyrus_base_layer::L1BlockNumber; @@ -106,7 +106,7 @@ pub trait L1GasPriceProviderClient: Send + Sync { #[async_trait] pub trait EthToStrkOracleClientTrait: Send + Sync + Debug { /// Fetches the eth to fri rate for a given timestamp. - async fn eth_to_fri_rate(&self, timestamp: u64) -> Result; + async fn eth_to_fri_rate(&self, timestamp: u64) -> Result; } #[async_trait]