Skip to content

Commit 385721d

Browse files
apollo_l1_gas_price_types,apollo_l1_gas_price: rename trait method eth_to_fri_rate to fetch_rate
1 parent ec16cd6 commit 385721d

4 files changed

Lines changed: 22 additions & 22 deletions

File tree

crates/apollo_l1_gas_price/src/exchange_rate_oracle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl ExchangeRateOracleClientTrait for ExchangeRateOracleClient {
204204
/// - `price`: a hexadecimal string representing the price.
205205
/// - `decimals`: a `u64` value, must be equal to `EXCHANGE_RATE_DECIMALS`.
206206
#[instrument(skip(self))]
207-
async fn eth_to_fri_rate(&self, timestamp: u64) -> Result<u128, ExchangeRateOracleClientError> {
207+
async fn fetch_rate(&self, timestamp: u64) -> Result<u128, ExchangeRateOracleClientError> {
208208
const NUMBER_OF_TIMESTAMPS_BACK: u64 = 1;
209209
let quantized_timestamp = (timestamp - self.config.lag_interval_seconds)
210210
.checked_div(self.config.lag_interval_seconds)

crates/apollo_l1_gas_price/src/exchange_rate_oracle_test.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,14 @@ async fn eth_to_fri_rate_uses_cache_on_quantized_hit() {
6060
let client = ExchangeRateOracleClient::new(config.clone());
6161

6262
// First request should fail because the cache is empty.
63-
assert!(client.eth_to_fri_rate(TIMESTAMP1).await.is_err());
63+
assert!(client.fetch_rate(TIMESTAMP1).await.is_err());
6464
// Wait for the query to resolve.
65-
while client.eth_to_fri_rate(TIMESTAMP1).await.is_err() {
65+
while client.fetch_rate(TIMESTAMP1).await.is_err() {
6666
tokio::task::yield_now().await; // Don't block the executor.
6767
}
68-
let rate1 = client.eth_to_fri_rate(TIMESTAMP1).await.unwrap();
69-
let rate2 = client
70-
.eth_to_fri_rate(TIMESTAMP2)
71-
.await
72-
.expect("Should resolve immediately due to the cache");
68+
let rate1 = client.fetch_rate(TIMESTAMP1).await.unwrap();
69+
let rate2 =
70+
client.fetch_rate(TIMESTAMP2).await.expect("Should resolve immediately due to the cache");
7371
assert_eq!(rate1, rate2);
7472
}
7573

@@ -134,28 +132,28 @@ async fn eth_to_fri_rate_uses_prev_cache_when_query_not_ready() {
134132
let client = ExchangeRateOracleClient::new(config.clone());
135133

136134
// First request should fail because the cache is empty.
137-
assert!(client.eth_to_fri_rate(TIMESTAMP1).await.is_err());
135+
assert!(client.fetch_rate(TIMESTAMP1).await.is_err());
138136
// Wait for the query to resolve.
139-
while client.eth_to_fri_rate(TIMESTAMP1).await.is_err() {
137+
while client.fetch_rate(TIMESTAMP1).await.is_err() {
140138
tokio::task::yield_now().await; // Don't block the executor.
141139
}
142-
let rate1 = client.eth_to_fri_rate(TIMESTAMP1).await.unwrap();
140+
let rate1 = client.fetch_rate(TIMESTAMP1).await.unwrap();
143141
assert_eq!(rate1, EXPECTED_RATE);
144142
// Second request should resolve immediately due to the cache.
145-
let rate2 = client.eth_to_fri_rate(TIMESTAMP2).await.unwrap();
143+
let rate2 = client.fetch_rate(TIMESTAMP2).await.unwrap();
146144
assert_eq!(rate2, EXPECTED_RATE);
147145

148146
// Wait for the query to resolve, and the price to be updated.
149147
for _ in 0..100 {
150-
let current_rate = client.eth_to_fri_rate(TIMESTAMP2).await.unwrap();
148+
let current_rate = client.fetch_rate(TIMESTAMP2).await.unwrap();
151149
if current_rate > EXPECTED_RATE {
152150
break;
153151
}
154152
tokio::time::sleep(Duration::from_millis(1)).await;
155153
}
156154

157155
// Third request should already successfully get the query from the server.
158-
let rate3 = client.eth_to_fri_rate(TIMESTAMP2).await.unwrap();
156+
let rate3 = client.fetch_rate(TIMESTAMP2).await.unwrap();
159157
assert_eq!(rate3, different_rate);
160158
}
161159

@@ -194,22 +192,22 @@ async fn eth_to_fri_rate_two_urls() {
194192
};
195193
let client = ExchangeRateOracleClient::new(config.clone());
196194
// First request should fail because the cache is empty.
197-
assert!(client.eth_to_fri_rate(TIMESTAMP1).await.is_err());
195+
assert!(client.fetch_rate(TIMESTAMP1).await.is_err());
198196
// Wait for the query to resolve.
199-
while client.eth_to_fri_rate(TIMESTAMP1).await.is_err() {
197+
while client.fetch_rate(TIMESTAMP1).await.is_err() {
200198
tokio::task::yield_now().await; // Don't block the executor.
201199
}
202-
let rate1 = client.eth_to_fri_rate(TIMESTAMP1).await.unwrap();
200+
let rate1 = client.fetch_rate(TIMESTAMP1).await.unwrap();
203201
assert_eq!(rate1, EXPECTED_RATE);
204202

205203
// Note this server fails on missing "decimals", not "price".
206204
let _mock_response3 =
207205
make_server(&mut server2, json!({"price": &expected_rate_hex, "bar": 18})).await;
208206
// First request should fail because the cache is empty.
209-
assert!(client.eth_to_fri_rate(TIMESTAMP2).await.is_err());
207+
assert!(client.fetch_rate(TIMESTAMP2).await.is_err());
210208
// Wait for the query to resolve.
211209
loop {
212-
match client.eth_to_fri_rate(TIMESTAMP2).await {
210+
match client.fetch_rate(TIMESTAMP2).await {
213211
Ok(_) => panic!("Both servers should be returning bad JSON!"),
214212
Err(ExchangeRateOracleClientError::QueryNotReadyError(_)) => {}
215213
Err(ExchangeRateOracleClientError::AllUrlsFailedError(_, index)) => {

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
@@ -186,7 +186,7 @@ impl L1GasPriceProvider {
186186

187187
pub async fn eth_to_fri_rate(&self, timestamp: u64) -> L1GasPriceProviderResult<u128> {
188188
self.eth_to_strk_oracle_client
189-
.eth_to_fri_rate(timestamp)
189+
.fetch_rate(timestamp)
190190
.await
191191
.map_err(L1GasPriceProviderError::ExchangeRateOracleClientError)
192192
}

crates/apollo_l1_gas_price_types/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ pub trait L1GasPriceProviderClient: Send + Sync {
105105
#[cfg_attr(any(feature = "testing", test), automock)]
106106
#[async_trait]
107107
pub trait ExchangeRateOracleClientTrait: Send + Sync + Debug {
108-
/// Fetches the eth to fri rate for a given timestamp.
109-
async fn eth_to_fri_rate(&self, timestamp: u64) -> Result<u128, ExchangeRateOracleClientError>;
108+
/// Fetches a rate as a u128 for the given timestamp. The semantics of the rate (e.g.
109+
/// ETH/FRI, STRK/USD) are determined by the URLs the implementation is configured with;
110+
/// callers label the per-instance meaning at the field that holds the trait object.
111+
async fn fetch_rate(&self, timestamp: u64) -> Result<u128, ExchangeRateOracleClientError>;
110112
}
111113

112114
#[async_trait]

0 commit comments

Comments
 (0)