diff --git a/Cargo.lock b/Cargo.lock index 1a866d777b..ef2948af13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3616,12 +3616,12 @@ dependencies = [ ] [[package]] -name = "pyth-price-publisher" +name = "pyth-price-store" version = "0.1.0" -source = "git+https://github.com/pyth-network/pyth-crosschain?branch=add-publisher-program#1fa5089f0f5abf1fe1d48ba0dda489843fcd545a" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbb76932606741e8b690d51d3e78df620df4a13474a2ca5f53ded5f70522cdc" dependencies = [ "bytemuck", - "solana-program 1.14.17", "thiserror", ] @@ -6210,7 +6210,7 @@ dependencies = [ "once_cell", "ouroboros", "pyth-oracle", - "pyth-price-publisher", + "pyth-price-store", "pythnet-sdk 1.13.6", "rand 0.7.3", "rand_chacha 0.2.2", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 7fc60299d0..1e80c5d304 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -37,7 +37,7 @@ once_cell = "1.12.0" ouroboros = "0.15.0" pyth-oracle = { git = "https://github.com/pyth-network/pyth-client", rev = "256b57", features = ["library"] } pythnet-sdk = { git = "https://github.com/pyth-network/pyth-crosschain", version = "1.13.6", rev = "33f901aa45f4f0005aa5a84a1479b78ca9033074" } -pyth-price-publisher = { git = "https://github.com/pyth-network/pyth-crosschain", branch = "add-publisher-program" } +pyth-price-store = "0.1.0" rand = "0.7.0" rayon = "1.5.3" regex = "1.5.6" diff --git a/runtime/src/bank/pyth/accumulator.rs b/runtime/src/bank/pyth/accumulator.rs index ee86f9c559..701e37e574 100644 --- a/runtime/src/bank/pyth/accumulator.rs +++ b/runtime/src/bank/pyth/accumulator.rs @@ -60,8 +60,7 @@ lazy_static! { ); pub static ref BATCH_PUBLISH_PID: Pubkey = env_pubkey_or( "BATCH_PUBLISH_PID", - // TODO: replace with real program id - "FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epA" + "3m6sv6HGqEbuyLV84mD7rJn4MAC9LhUa1y1AUNVqcPfr" .parse() .unwrap(), ); diff --git a/runtime/src/bank/pyth/batch_publish.rs b/runtime/src/bank/pyth/batch_publish.rs index a7a7962dc6..d91d437dcf 100644 --- a/runtime/src/bank/pyth/batch_publish.rs +++ b/runtime/src/bank/pyth/batch_publish.rs @@ -9,7 +9,7 @@ use { find_publisher_index, get_status_for_conf_price_ratio, solana_program::pubkey::Pubkey, OracleError, PriceAccount, }, - pyth_price_publisher::accounts::publisher_prices as publisher_prices_account, + pyth_price_store::accounts::buffer, solana_sdk::{account::ReadableAccount, clock::Slot}, std::collections::HashMap, thiserror::Error, @@ -37,7 +37,7 @@ pub fn extract_batch_publish_prices( "Oracle program account index missing" ); - let publisher_prices_accounts = bank + let publish_program_accounts = bank .get_filtered_indexed_accounts( &IndexKey::ProgramId(*BATCH_PUBLISH_PID), |account| account.owner() == &*BATCH_PUBLISH_PID, @@ -49,11 +49,11 @@ pub fn extract_batch_publish_prices( let mut all_prices = HashMap::>::new(); let mut num_found_accounts = 0; let mut num_found_prices = 0; - for (account_key, account) in publisher_prices_accounts { - if !publisher_prices_account::format_matches(account.data()) { + for (account_key, account) in publish_program_accounts { + if !buffer::format_matches(account.data()) { continue; } - let (header, prices) = match publisher_prices_account::read(account.data()) { + let (header, prices) = match buffer::read(account.data()) { Ok(r) => r, Err(err) => { warn!("invalid publisher prices account {}: {}", account_key, err); diff --git a/runtime/src/bank/pyth/tests/batch_publish_tests.rs b/runtime/src/bank/pyth/tests/batch_publish_tests.rs index b26f547976..8c52d36bb4 100644 --- a/runtime/src/bank/pyth/tests/batch_publish_tests.rs +++ b/runtime/src/bank/pyth/tests/batch_publish_tests.rs @@ -10,8 +10,12 @@ use { pyth_oracle::{ solana_program::account_info::AccountInfo, PriceAccount, PriceAccountFlags, PythAccount, }, - pyth_price_publisher::accounts::publisher_prices::{ - self as publisher_prices_account, PublisherPrice, + pyth_price_store::{ + accounts::{ + buffer::{self, BufferedPrice}, + publisher_config, + }, + instruction::PUBLISHER_CONFIG_SEED, }, solana_sdk::{ account::{AccountSharedData, ReadableAccount, WritableAccount}, @@ -38,37 +42,55 @@ fn test_batch_publish() { genesis_config.epoch_schedule = EpochSchedule::new(slots_in_epoch); let mut bank = create_new_bank_for_tests_with_index(&genesis_config); - let generate_publisher = |seed, new_prices| { - let publisher1_key = keypair_from_seed(seed).unwrap(); + let generate_publisher = |seed, seed2, new_prices| { + let publisher_key = keypair_from_seed(seed).unwrap(); - let (publisher1_prices_key, _bump) = Pubkey::find_program_address( - &[b"BUFFER", &publisher1_key.pubkey().to_bytes()], + let (publisher_config_key, _bump) = Pubkey::find_program_address( + &[ + PUBLISHER_CONFIG_SEED.as_bytes(), + &publisher_key.pubkey().to_bytes(), + ], &BATCH_PUBLISH_PID, ); - let mut publisher1_prices_account = - AccountSharedData::new(42, publisher_prices_account::size(100), &BATCH_PUBLISH_PID); + let publisher_buffer_key = + Pubkey::create_with_seed(&leader_pubkey, seed2, &BATCH_PUBLISH_PID).unwrap(); + + let mut publisher_config_account = + AccountSharedData::new(42, publisher_config::SIZE, &BATCH_PUBLISH_PID); + + publisher_config::create( + publisher_config_account.data_mut(), + publisher_key.pubkey().to_bytes(), + publisher_buffer_key.to_bytes(), + ) + .unwrap(); + bank.store_account(&publisher_config_key, &publisher_config_account); + + let mut publisher_buffer_account = + AccountSharedData::new(42, buffer::size(100), &BATCH_PUBLISH_PID); { - let (header, prices) = publisher_prices_account::create( - publisher1_prices_account.data_mut(), - publisher1_key.pubkey().to_bytes(), + let (header, prices) = buffer::create( + publisher_buffer_account.data_mut(), + publisher_key.pubkey().to_bytes(), ) .unwrap(); - publisher_prices_account::extend(header, prices, cast_slice(new_prices)).unwrap(); + buffer::update(header, prices, bank.slot(), cast_slice(new_prices)).unwrap(); } - bank.store_account(&publisher1_prices_key, &publisher1_prices_account); + bank.store_account(&publisher_buffer_key, &publisher_buffer_account); - publisher1_key + publisher_key }; let publishers = [ generate_publisher( &[1u8; 32], + "seed1", &[ - PublisherPrice::new(1, 1, 10, 2).unwrap(), - PublisherPrice::new(2, 1, 20, 3).unwrap(), + BufferedPrice::new(1, 1, 10, 2).unwrap(), + BufferedPrice::new(2, 1, 20, 3).unwrap(), // Attempt to publish with price_index == 0, // but it will not be applied. - PublisherPrice { + BufferedPrice { trading_status_and_feed_index: 0, price: 30, confidence: 35, @@ -77,9 +99,10 @@ fn test_batch_publish() { ), generate_publisher( &[2u8; 32], + "seed2", &[ - PublisherPrice::new(1, 1, 15, 2).unwrap(), - PublisherPrice::new(2, 1, 25, 3).unwrap(), + BufferedPrice::new(1, 1, 15, 2).unwrap(), + BufferedPrice::new(2, 1, 25, 3).unwrap(), ], ), ];