Skip to content

Commit

Permalink
chore(sequencer): implement market endpoint (#1946)
Browse files Browse the repository at this point in the history
## Summary
This is a small PR to address a couple of minor omissions: implementing
a query endpoint, and removing a needless RPC call.

## Background
These are likely just small omissions from previous work/discussions.

## Changes
- Updated `MarketMapQueryService::market` to not always return a "not
implemented" error response.
- Changed initial connection attempts to oracle sidecar to not actually
send a request.

## Testing
Manually tested both changes locally. The former would ideally have unit
tests, but this entire module is not unit tested. The latter is harder
to create a meaningful unit test for, but new smoke tests using the
sidecar will make it apparent if this function is broken.

## Changelogs
No updates required.
  • Loading branch information
Fraser999 authored Feb 5, 2025
2 parents e6a00f6 + ac28a94 commit 3736477
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
25 changes: 23 additions & 2 deletions crates/astria-sequencer/src/grpc/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,30 @@ impl MarketMapQueryService for SequencerServer {
#[instrument(skip_all)]
async fn market(
self: Arc<Self>,
_request: Request<MarketRequest>,
request: Request<MarketRequest>,
) -> Result<Response<MarketResponse>, Status> {
Err(Status::unimplemented("market endpoint is not implemented"))
let snapshot = self.storage.latest_snapshot();
let market_map = snapshot
.get_market_map()
.await
.map_err(|e| Status::internal(format!("error getting market map from storage: {e:#}")))?
.ok_or_else(|| Status::not_found("market map not stored"))?;
let raw_currency_pair = request
.into_inner()
.currency_pair
.ok_or_else(|| Status::invalid_argument("`currency_pair` must be set"))?;
let currency_pair = CurrencyPair::try_from_raw(raw_currency_pair)
.map_err(|e| Status::invalid_argument(format!("invalid `currency_pair`: {e:#}")))?
.to_string();
let market = market_map
.markets
.get(&currency_pair)
.cloned()
.ok_or_else(|| Status::not_found(format!("`{currency_pair}` not in market map")))?;

Ok(Response::new(MarketResponse {
market: Some(market.into_raw()),
}))
}

#[instrument(skip_all)]
Expand Down
11 changes: 2 additions & 9 deletions crates/astria-sequencer/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use astria_core::generated::{
connect::{
marketmap::v2::query_server::QueryServer as MarketMapQueryServer,
oracle::v2::query_server::QueryServer as OracleQueryServer,
service::v2::{
oracle_client::OracleClient,
QueryPricesRequest,
},
service::v2::oracle_client::OracleClient,
},
};
use astria_eyre::{
Expand Down Expand Up @@ -385,16 +382,12 @@ async fn new_oracle_client(config: &Config) -> Result<Option<OracleClient<Channe

#[instrument(skip_all, err(level = tracing::Level::WARN))]
async fn connect_to_oracle(endpoint: &Endpoint, uri: &Uri) -> Result<OracleClient<Channel>> {
let mut oracle_client = OracleClient::new(
let oracle_client = OracleClient::new(
endpoint
.connect()
.await
.wrap_err("failed to connect to oracle sidecar")?,
);
let _ = oracle_client
.prices(QueryPricesRequest::default())
.await
.wrap_err("oracle sidecar responded with error to query for prices");
debug!(uri = %uri, "oracle sidecar is reachable");
Ok(oracle_client)
}
Expand Down

0 comments on commit 3736477

Please sign in to comment.