From b63a239114f5a8d03fb20dae6fe9a9e54f6bfb5e Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Tue, 24 Oct 2023 16:43:20 +0200 Subject: [PATCH 1/2] chore(hermes): change level of some logs --- hermes/src/aggregate/wormhole_merkle.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hermes/src/aggregate/wormhole_merkle.rs b/hermes/src/aggregate/wormhole_merkle.rs index f9bf410e73..940b9526ca 100644 --- a/hermes/src/aggregate/wormhole_merkle.rs +++ b/hermes/src/aggregate/wormhole_merkle.rs @@ -114,7 +114,7 @@ pub fn construct_message_states_proofs( } pub fn construct_update_data(mut messages: Vec) -> Result>> { - tracing::info!("Constructing update data for {} messages", messages.len()); + tracing::debug!("Constructing update data for {} messages", messages.len()); messages.sort_by_key(|m| m.slot); @@ -140,7 +140,7 @@ pub fn construct_update_data(mut messages: Vec) -> Re } } - tracing::info!( + tracing::debug!( slot = slot, "Combining {} messages in a single updateData", updates.len() From 86d7a37160d21f5cd83421466b59cc1f9a04133b Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Tue, 24 Oct 2023 17:17:34 +0200 Subject: [PATCH 2/2] feat(hermes): only return unique price updates on get_* methods --- hermes/Cargo.lock | 2 +- hermes/Cargo.toml | 2 +- hermes/src/api/rest.rs | 4 ++++ hermes/src/api/rest/get_price_feed.rs | 9 +++++++++ hermes/src/api/rest/get_vaa.rs | 21 +++++++++++++++------ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/hermes/Cargo.lock b/hermes/Cargo.lock index 33b7fe9b86..2cfb6725ef 100644 --- a/hermes/Cargo.lock +++ b/hermes/Cargo.lock @@ -1574,7 +1574,7 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermes" -version = "0.4.2" +version = "0.4.3" dependencies = [ "anyhow", "async-trait", diff --git a/hermes/Cargo.toml b/hermes/Cargo.toml index 629add8481..c759668a24 100644 --- a/hermes/Cargo.toml +++ b/hermes/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hermes" -version = "0.4.2" +version = "0.4.3" description = "Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle." edition = "2021" diff --git a/hermes/src/api/rest.rs b/hermes/src/api/rest.rs index 6e80fcb909..d553459d5b 100644 --- a/hermes/src/api/rest.rs +++ b/hermes/src/api/rest.rs @@ -33,6 +33,7 @@ pub use { }; pub enum RestError { + BenchmarkPriceNotUnique, UpdateDataNotFound, CcipUpdateDataNotFound, InvalidCCIPInput, @@ -42,6 +43,9 @@ pub enum RestError { impl IntoResponse for RestError { fn into_response(self) -> Response { match self { + RestError::BenchmarkPriceNotUnique => { + (StatusCode::NOT_FOUND, "Benchmark price is not unique").into_response() + } RestError::UpdateDataNotFound => { (StatusCode::NOT_FOUND, "Update data not found").into_response() } diff --git a/hermes/src/api/rest/get_price_feed.rs b/hermes/src/api/rest/get_price_feed.rs index 1151f4a600..f2d7edcc24 100644 --- a/hermes/src/api/rest/get_price_feed.rs +++ b/hermes/src/api/rest/get_price_feed.rs @@ -89,6 +89,15 @@ pub async fn get_price_feed( .next() .ok_or(RestError::UpdateDataNotFound)?; + // Currently Benchmarks API doesn't support returning the previous publish time. So we + // are assuming that it is doing the same filter as us and returns not found if the + // price update is not unique. + if let Some(prev_publish_time) = price_feed.prev_publish_time { + if prev_publish_time == price_feed.price_feed.get_price_unchecked().publish_time { + return Err(RestError::BenchmarkPriceNotUnique); + } + } + // Note: This is a hack to get around the fact that Benchmark doesn't give per price feed // update data. Since we request only for a single feed then the whole prices update data // is this price feed update data. diff --git a/hermes/src/api/rest/get_vaa.rs b/hermes/src/api/rest/get_vaa.rs index 3ebda11028..15800c7949 100644 --- a/hermes/src/api/rest/get_vaa.rs +++ b/hermes/src/api/rest/get_vaa.rs @@ -97,13 +97,22 @@ pub async fn get_vaa( .map(|bytes| base64_standard_engine.encode(bytes)) .ok_or(RestError::UpdateDataNotFound)?; - let publish_time = price_feeds_with_update_data + let price_feed = price_feeds_with_update_data .price_feeds - .get(0) - .ok_or(RestError::UpdateDataNotFound)? - .price_feed - .get_price_unchecked() - .publish_time; + .into_iter() + .next() + .ok_or(RestError::UpdateDataNotFound)?; + + let publish_time = price_feed.price_feed.get_price_unchecked().publish_time; + + // Currently Benchmarks API doesn't support returning the previous publish time. So we + // are assuming that it is doing the same filter as us and returns not found if the + // price update is not unique. + if let Some(prev_publish_time) = price_feed.prev_publish_time { + if prev_publish_time == price_feed.price_feed.get_price_unchecked().publish_time { + return Err(RestError::BenchmarkPriceNotUnique); + } + } Ok(Json(GetVaaResponse { vaa, publish_time })) }