diff --git a/.github/workflows/pyth.yml b/.github/workflows/pyth.yml new file mode 100644 index 0000000000..e623db975b --- /dev/null +++ b/.github/workflows/pyth.yml @@ -0,0 +1,51 @@ +name: Check Pythnet + +on: + pull_request: + push: + branches: [main] +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: 1.60.0 + components: clippy + override: true + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y libssl-dev libudev-dev pkg-config zlib1g-dev llvm clang cmake make libprotobuf-dev + - name: Run tests + run: cargo test -p solana-runtime pyth + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: 1.60.0 + components: clippy + override: true + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y libssl-dev libudev-dev pkg-config zlib1g-dev llvm clang cmake make libprotobuf-dev + - name: Check clippy + run: cargo clippy --bins --tests --examples -- --deny warnings + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly-2022-04-01 + components: rustfmt + override: true + - name: Check formatting + run: cargo fmt -- --check diff --git a/runtime/src/bank/pyth_accumulator.rs b/runtime/src/bank/pyth_accumulator.rs index e5a9d5a783..c20b0c4a97 100644 --- a/runtime/src/bank/pyth_accumulator.rs +++ b/runtime/src/bank/pyth_accumulator.rs @@ -431,13 +431,19 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV for (pubkey, mut account) in accounts { let mut price_account_data = account.data().to_owned(); - let price_account = if let Ok(data) = - pyth_oracle::validator::validate_price_account(&mut price_account_data) - { - data - } else { - continue; // Not a price account. - }; + let price_account = + match pyth_oracle::validator::validate_price_account(&mut price_account_data) { + Ok(data) => data, + Err(err) => match err { + AggregationError::NotPriceFeedAccount => { + continue; + } + AggregationError::V1AggregationMode | AggregationError::AlreadyAggregated => { + any_v1_aggregations = true; + continue; + } + }, + }; let mut need_save = pyth_batch_publish::apply_published_prices(price_account, &new_prices, bank.slot()); @@ -453,7 +459,7 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV need_save = true; v2_messages.extend(messages); } - Err(err) => match err { + Err(err) => match dbg!(err) { AggregationError::NotPriceFeedAccount => {} AggregationError::V1AggregationMode | AggregationError::AlreadyAggregated => { any_v1_aggregations = true; diff --git a/runtime/src/bank/pyth_accumulator_tests.rs b/runtime/src/bank/pyth_accumulator_tests.rs index d9cdddf217..6938940c1b 100644 --- a/runtime/src/bank/pyth_accumulator_tests.rs +++ b/runtime/src/bank/pyth_accumulator_tests.rs @@ -902,6 +902,7 @@ fn test_get_accumulator_keys() { Pubkey::new_from_array(pythnet::ACCUMULATOR_SEQUENCE_ADDR), Pubkey::new_from_array(pythnet::WORMHOLE_PID), *ORACLE_PID, + *BATCH_PUBLISH_PID, ]; assert_eq!(accumulator_keys, expected_pyth_keys); } diff --git a/validator/src/main.rs b/validator/src/main.rs index 1afe140da6..efee36b715 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -3200,28 +3200,26 @@ fn process_account_indexes(matches: &ArgMatches) -> AccountSecondaryIndexes { let exclude_keys = !account_indexes_exclude_keys.is_empty(); let include_keys = !account_indexes_include_keys.is_empty(); - if include_keys { - if !account_indexes_include_keys.contains(&*ORACLE_PID) + if include_keys + && (!account_indexes_include_keys.contains(&*ORACLE_PID) || !account_indexes_include_keys.contains(&*MESSAGE_BUFFER_PID) - || !account_indexes_include_keys.contains(&*BATCH_PUBLISH_PID) - { - panic!( + || !account_indexes_include_keys.contains(&*BATCH_PUBLISH_PID)) + { + panic!( "The oracle program id and message buffer program id must be included in the account index. Add the following flags\n\ --account-index-include-key {}\n\ --account-index-include-key {}\n\ --account-index-include-key {}\n", &*ORACLE_PID, &*MESSAGE_BUFFER_PID, &*BATCH_PUBLISH_PID, ); - } } - if exclude_keys { - if account_indexes_exclude_keys.contains(&*ORACLE_PID) + if exclude_keys + && (account_indexes_exclude_keys.contains(&*ORACLE_PID) || account_indexes_exclude_keys.contains(&*MESSAGE_BUFFER_PID) - || account_indexes_exclude_keys.contains(&*BATCH_PUBLISH_PID) - { - panic!("The oracle program id and message buffer program id must *not* be excluded from the account index."); - } + || account_indexes_exclude_keys.contains(&*BATCH_PUBLISH_PID)) + { + panic!("The oracle program id and message buffer program id must *not* be excluded from the account index."); } let keys = if !account_indexes.is_empty() && (exclude_keys || include_keys) {