Skip to content

Commit 36d4d38

Browse files
apollo_l1_gas_price_types: rename EthToStrkOracleClientError to PriceOracleClientError
1 parent 4c8cddc commit 36d4d38

8 files changed

Lines changed: 34 additions & 39 deletions

File tree

crates/apollo_consensus_orchestrator/src/build_proposal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use apollo_batcher_types::batcher_types::{
1515
use apollo_batcher_types::communication::{BatcherClient, BatcherClientError};
1616
use apollo_consensus::types::{ProposalCommitment, Round};
1717
use apollo_consensus_orchestrator_config::config::PricePerHeight;
18-
use apollo_l1_gas_price_types::errors::{EthToStrkOracleClientError, L1GasPriceClientError};
18+
use apollo_l1_gas_price_types::errors::{L1GasPriceClientError, PriceOracleClientError};
1919
use apollo_protobuf::consensus::{
2020
BuildParam,
2121
CommitmentParts,
@@ -94,7 +94,7 @@ pub(crate) enum BuildProposalError {
9494
#[error("Failed to send proposal part: {0}")]
9595
SendError(String),
9696
#[error("EthToStrkOracle error: {0}")]
97-
EthToStrkOracle(#[from] EthToStrkOracleClientError),
97+
EthToStrkOracle(#[from] PriceOracleClientError),
9898
#[error("L1GasPriceProvider error: {0}")]
9999
L1GasPriceProvider(#[from] L1GasPriceClientError),
100100
#[error("Proposal interrupted.")]

crates/apollo_consensus_orchestrator/src/sequencer_consensus_context_test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ use apollo_consensus_orchestrator_config::config::{
2121
PricePerHeight,
2222
};
2323
use apollo_l1_gas_price_types::errors::{
24-
EthToStrkOracleClientError,
2524
L1GasPriceClientError,
2625
L1GasPriceProviderError,
26+
PriceOracleClientError,
2727
};
2828
use apollo_l1_gas_price_types::{MockL1GasPriceProviderClient, PriceInfo};
2929
use apollo_protobuf::consensus::{
@@ -755,8 +755,8 @@ async fn oracle_fails_on_startup(#[case] l1_oracle_failure: bool) {
755755
})
756756
});
757757
l1_prices_oracle_client.expect_get_eth_to_fri_rate().times(1).return_once(|_| {
758-
Err(L1GasPriceClientError::EthToStrkOracleClientError(
759-
EthToStrkOracleClientError::MissingFieldError("".to_string(), "".to_string()),
758+
Err(L1GasPriceClientError::PriceOracleClientError(
759+
PriceOracleClientError::MissingFieldError("".to_string(), "".to_string()),
760760
))
761761
});
762762
deps.l1_gas_price_provider = l1_prices_oracle_client;
@@ -854,8 +854,8 @@ async fn oracle_fails_on_second_block(#[case] l1_oracle_failure: bool) {
854854
.return_once(|_| Ok(ETH_TO_FRI_RATE));
855855
// Set the eth_to_fri_rate to fail on second block.
856856
l1_prices_oracle_client.expect_get_eth_to_fri_rate().times(1).return_once(|_| {
857-
Err(L1GasPriceClientError::EthToStrkOracleClientError(
858-
EthToStrkOracleClientError::MissingFieldError("".to_string(), "".to_string()),
857+
Err(L1GasPriceClientError::PriceOracleClientError(
858+
PriceOracleClientError::MissingFieldError("".to_string(), "".to_string()),
859859
))
860860
});
861861
deps.l1_gas_price_provider = l1_prices_oracle_client;

crates/apollo_consensus_orchestrator/src/validate_proposal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use apollo_batcher_types::batcher_types::{
1717
use apollo_batcher_types::communication::{BatcherClient, BatcherClientError};
1818
use apollo_batcher_types::errors::BatcherError;
1919
use apollo_consensus::types::ProposalCommitment;
20-
use apollo_l1_gas_price_types::errors::{EthToStrkOracleClientError, L1GasPriceClientError};
20+
use apollo_l1_gas_price_types::errors::{L1GasPriceClientError, PriceOracleClientError};
2121
use apollo_l1_gas_price_types::L1GasPriceProviderClient;
2222
use apollo_protobuf::consensus::{ProposalFin, ProposalInit, ProposalPart, TransactionBatch};
2323
use apollo_state_sync_types::communication::SharedStateSyncClient;
@@ -111,7 +111,7 @@ pub(crate) enum ValidateProposalError {
111111
#[error("Failed to send commitment to consensus: {0}")]
112112
SendError(ProposalCommitment),
113113
#[error("EthToStrkOracle error: {0}")]
114-
EthToStrkOracle(#[from] EthToStrkOracleClientError),
114+
EthToStrkOracle(#[from] PriceOracleClientError),
115115
#[error("L1GasPriceProvider error: {0}")]
116116
L1GasPriceProvider(#[from] L1GasPriceClientError),
117117
#[error("ProposalInit conversion error: {0}")]

crates/apollo_l1_gas_price/src/eth_to_strk_oracle.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::time::Duration;
66

77
use apollo_config::secrets::Sensitive;
88
use apollo_l1_gas_price_config::config::EthToStrkOracleConfig;
9-
use apollo_l1_gas_price_types::errors::EthToStrkOracleClientError;
9+
use apollo_l1_gas_price_types::errors::PriceOracleClientError;
1010
use apollo_l1_gas_price_types::EthToStrkOracleClientTrait;
1111
use apollo_metrics::metrics::set_unix_now_seconds;
1212
use async_trait::async_trait;
@@ -52,7 +52,7 @@ pub struct UrlAndHeaderMap {
5252
pub headers: Sensitive<HeaderMap>,
5353
}
5454

55-
type PriceQuery = AbortOnDropHandle<Result<u128, EthToStrkOracleClientError>>;
55+
type PriceQuery = AbortOnDropHandle<Result<u128, PriceOracleClientError>>;
5656

5757
/// Client for interacting with the eth to strk Oracle API.
5858
#[derive(Clone, Debug)]
@@ -101,7 +101,7 @@ impl EthToStrkOracleClient {
101101
fn spawn_query(
102102
&self,
103103
quantized_timestamp: u64,
104-
) -> AbortOnDropHandle<Result<u128, EthToStrkOracleClientError>> {
104+
) -> AbortOnDropHandle<Result<u128, PriceOracleClientError>> {
105105
assert!(
106106
self.config.lag_interval_seconds > 0,
107107
"lag_interval_seconds should be greater than 0"
@@ -127,7 +127,7 @@ impl EthToStrkOracleClient {
127127
.await?;
128128
let body = response.text().await?;
129129
let rate = resolve_query(body)?;
130-
Ok::<_, EthToStrkOracleClientError>(rate)
130+
Ok::<_, PriceOracleClientError>(rate)
131131
})
132132
.await;
133133

@@ -148,40 +148,35 @@ impl EthToStrkOracleClient {
148148
ETH_TO_STRK_ERROR_COUNT.increment(1);
149149
}
150150
warn!("All {list_len} URLs in the list failed for timestamp {adjusted_timestamp}");
151-
Err(EthToStrkOracleClientError::AllUrlsFailedError(adjusted_timestamp, initial_index))
151+
Err(PriceOracleClientError::AllUrlsFailedError(adjusted_timestamp, initial_index))
152152
};
153153
AbortOnDropHandle::new(tokio::spawn(future))
154154
}
155155
}
156156

157-
fn resolve_query(body: String) -> Result<u128, EthToStrkOracleClientError> {
157+
fn resolve_query(body: String) -> Result<u128, PriceOracleClientError> {
158158
let Ok(json): Result<serde_json::Value, _> = serde_json::from_str(&body) else {
159-
return Err(EthToStrkOracleClientError::ParseError(format!(
160-
"Failed to parse JSON: {body}"
161-
)));
159+
return Err(PriceOracleClientError::ParseError(format!("Failed to parse JSON: {body}")));
162160
};
163161
// Extract price from API response. Also returns MissingFieldError if value is not a string.
164162
let price = match json.get("price").and_then(|v| v.as_str()) {
165163
Some(price) => price,
166164
None => {
167-
return Err(EthToStrkOracleClientError::MissingFieldError("price".to_string(), body));
165+
return Err(PriceOracleClientError::MissingFieldError("price".to_string(), body));
168166
}
169167
};
170168
let rate = u128::from_str_radix(price.trim_start_matches("0x"), 16).map_err(|e| {
171-
EthToStrkOracleClientError::ParseError(format!("Failed to parse price {price}: {e}"))
169+
PriceOracleClientError::ParseError(format!("Failed to parse price {price}: {e}"))
172170
})?;
173171
// Extract decimals from API response. Also returns MissingFieldError if value is not a number.
174172
let decimals = match json.get("decimals").and_then(|v| v.as_u64()) {
175173
Some(decimals) => decimals,
176174
None => {
177-
return Err(EthToStrkOracleClientError::MissingFieldError(
178-
"decimals".to_string(),
179-
body,
180-
));
175+
return Err(PriceOracleClientError::MissingFieldError("decimals".to_string(), body));
181176
}
182177
};
183178
if decimals != ETH_TO_STRK_QUANTIZATION {
184-
return Err(EthToStrkOracleClientError::InvalidDecimalsError(
179+
return Err(PriceOracleClientError::InvalidDecimalsError(
185180
ETH_TO_STRK_QUANTIZATION,
186181
decimals,
187182
));
@@ -198,7 +193,7 @@ impl EthToStrkOracleClientTrait for EthToStrkOracleClient {
198193
/// - `price`: a hexadecimal string representing the price.
199194
/// - `decimals`: a `u64` value, must be equal to `ETH_TO_STRK_QUANTIZATION`.
200195
#[instrument(skip(self))]
201-
async fn eth_to_fri_rate(&self, timestamp: u64) -> Result<u128, EthToStrkOracleClientError> {
196+
async fn eth_to_fri_rate(&self, timestamp: u64) -> Result<u128, PriceOracleClientError> {
202197
const NUMBER_OF_TIMESTAMPS_BACK: u64 = 1;
203198
let quantized_timestamp = (timestamp - self.config.lag_interval_seconds)
204199
.checked_div(self.config.lag_interval_seconds)
@@ -229,7 +224,7 @@ impl EthToStrkOracleClientTrait for EthToStrkOracleClient {
229224
return Ok(*rate);
230225
}
231226
// If not, return a query not ready error.
232-
return Err(EthToStrkOracleClientError::QueryNotReadyError(timestamp));
227+
return Err(PriceOracleClientError::QueryNotReadyError(timestamp));
233228
}
234229
let result = handle.now_or_never().expect("Handle must be finished if we got here");
235230
let rate = match result {
@@ -245,7 +240,7 @@ impl EthToStrkOracleClientTrait for EthToStrkOracleClient {
245240
ETH_TO_STRK_ERROR_COUNT.increment(1);
246241
// Must remove failed query from the cache, to avoid re-polling it.
247242
queries.pop(&quantized_timestamp);
248-
return Err(EthToStrkOracleClientError::JoinError(e.to_string()));
243+
return Err(PriceOracleClientError::JoinError(e.to_string()));
249244
}
250245
};
251246

crates/apollo_l1_gas_price/src/eth_to_strk_oracle_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::BTreeMap;
22
use std::time::Duration;
33

44
use apollo_config::converters::UrlAndHeaders;
5-
use apollo_l1_gas_price_types::errors::EthToStrkOracleClientError;
5+
use apollo_l1_gas_price_types::errors::PriceOracleClientError;
66
use apollo_l1_gas_price_types::EthToStrkOracleClientTrait;
77
use mockito::{Mock, ServerGuard};
88
use serde_json::json;
@@ -211,8 +211,8 @@ async fn eth_to_fri_rate_two_urls() {
211211
loop {
212212
match client.eth_to_fri_rate(TIMESTAMP2).await {
213213
Ok(_) => panic!("Both servers should be returning bad JSON!"),
214-
Err(EthToStrkOracleClientError::QueryNotReadyError(_)) => {}
215-
Err(EthToStrkOracleClientError::AllUrlsFailedError(_, index)) => {
214+
Err(PriceOracleClientError::QueryNotReadyError(_)) => {}
215+
Err(PriceOracleClientError::AllUrlsFailedError(_, index)) => {
216216
assert!(index == 1, "Last error should be index 1 (server2).");
217217
break; // This is the expected error, since server1 and 2 returned bad JSON.
218218
}

crates/apollo_l1_gas_price/src/l1_gas_price_provider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl L1GasPriceProvider {
188188
self.eth_to_strk_oracle_client
189189
.eth_to_fri_rate(timestamp)
190190
.await
191-
.map_err(L1GasPriceProviderError::EthToStrkOracleClientError)
191+
.map_err(L1GasPriceProviderError::PriceOracleClientError)
192192
}
193193
}
194194

crates/apollo_l1_gas_price_types/src/errors.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub enum L1GasPriceProviderError {
1818
)]
1919
StaleL1GasPricesError { current_timestamp: u64, last_valid_price_timestamp: u64 },
2020
#[error(transparent)]
21-
EthToStrkOracleClientError(#[from] EthToStrkOracleClientError),
21+
PriceOracleClientError(#[from] PriceOracleClientError),
2222
}
2323

2424
#[derive(Clone, Debug, Error)]
@@ -28,11 +28,11 @@ pub enum L1GasPriceClientError {
2828
#[error(transparent)]
2929
L1GasPriceProviderError(#[from] L1GasPriceProviderError),
3030
#[error(transparent)]
31-
EthToStrkOracleClientError(#[from] EthToStrkOracleClientError),
31+
PriceOracleClientError(#[from] PriceOracleClientError),
3232
}
3333

3434
#[derive(Clone, Debug, Error, Serialize, Deserialize, PartialEq, Eq)]
35-
pub enum EthToStrkOracleClientError {
35+
pub enum PriceOracleClientError {
3636
#[error("Join error: {0}")]
3737
JoinError(String),
3838
#[error("Request error: {0}")]
@@ -49,8 +49,8 @@ pub enum EthToStrkOracleClientError {
4949
AllUrlsFailedError(u64, usize),
5050
}
5151

52-
impl From<reqwest::Error> for EthToStrkOracleClientError {
52+
impl From<reqwest::Error> for PriceOracleClientError {
5353
fn from(value: reqwest::Error) -> Self {
54-
EthToStrkOracleClientError::RequestError(value.to_string())
54+
PriceOracleClientError::RequestError(value.to_string())
5555
}
5656
}

crates/apollo_l1_gas_price_types/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use apollo_infra::{
1212
};
1313
use apollo_metrics::generate_permutation_labels;
1414
use async_trait::async_trait;
15-
use errors::{EthToStrkOracleClientError, L1GasPriceClientError, L1GasPriceProviderError};
15+
use errors::{L1GasPriceClientError, L1GasPriceProviderError, PriceOracleClientError};
1616
#[cfg(any(feature = "testing", test))]
1717
use mockall::automock;
1818
use papyrus_base_layer::L1BlockNumber;
@@ -106,7 +106,7 @@ pub trait L1GasPriceProviderClient: Send + Sync {
106106
#[async_trait]
107107
pub trait EthToStrkOracleClientTrait: Send + Sync + Debug {
108108
/// Fetches the eth to fri rate for a given timestamp.
109-
async fn eth_to_fri_rate(&self, timestamp: u64) -> Result<u128, EthToStrkOracleClientError>;
109+
async fn eth_to_fri_rate(&self, timestamp: u64) -> Result<u128, PriceOracleClientError>;
110110
}
111111

112112
#[async_trait]

0 commit comments

Comments
 (0)