From 491e168492eaeaf698a8cbc9608a8a290d9bfedb Mon Sep 17 00:00:00 2001 From: Pavel Strakhov Date: Wed, 7 Aug 2024 11:25:21 +0100 Subject: [PATCH] feat: verify that price feed index is set --- .github/workflows/pyth.yml | 2 +- Cargo.lock | 2 +- runtime/src/bank/pyth_batch_publish.rs | 13 +++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pyth.yml b/.github/workflows/pyth.yml index e623db975b..291a49bf3f 100644 --- a/.github/workflows/pyth.yml +++ b/.github/workflows/pyth.yml @@ -3,7 +3,7 @@ name: Check Pythnet on: pull_request: push: - branches: [main] + branches: [pyth-v1.14.17] jobs: test: runs-on: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index f3314cc104..0a652e01bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3601,7 +3601,7 @@ dependencies = [ [[package]] name = "pyth-oracle" version = "2.33.0" -source = "git+https://github.com/pyth-network/pyth-client?branch=batch-publish#44bf1257e14d3ecf06516bc2520d9358e58b1ed7" +source = "git+https://github.com/pyth-network/pyth-client?branch=batch-publish#f466deb73c4a15ea13cb271c3a900c5a85810c87" dependencies = [ "bindgen 0.60.1", "bitflags 2.6.0", diff --git a/runtime/src/bank/pyth_batch_publish.rs b/runtime/src/bank/pyth_batch_publish.rs index 406a313551..fe9c6cb371 100644 --- a/runtime/src/bank/pyth_batch_publish.rs +++ b/runtime/src/bank/pyth_batch_publish.rs @@ -245,9 +245,14 @@ pub fn apply_published_prices( new_prices: &HashMap>, slot: Slot, ) -> bool { - let price_feed_index = price_data.feed_index as u32; + if price_data.feed_index == 0 { + return false; + } let mut any_update = false; - for new_price in new_prices.get(&price_feed_index).unwrap_or(&Vec::new()) { + for new_price in new_prices + .get(&price_data.feed_index) + .unwrap_or(&Vec::new()) + { match apply_published_price(price_data, new_price, slot) { Ok(()) => { any_update = true; @@ -255,7 +260,7 @@ pub fn apply_published_prices( Err(err) => { warn!( "failed to apply publisher price to price feed {}: {}", - price_data.feed_index as u32, err + price_data.feed_index, err ); } } @@ -286,7 +291,7 @@ fn apply_published_price( .ok_or(ApplyPublishedPriceError::InvalidPublishersNum)?; let publisher_index = find_publisher_index(publishers, &new_price.publisher).ok_or( - ApplyPublishedPriceError::NoPermission(price_data.feed_index as u32, new_price.publisher), + ApplyPublishedPriceError::NoPermission(price_data.feed_index, new_price.publisher), )?; // IMPORTANT: If the publisher does not meet the price/conf