Skip to content

Commit c2270e5

Browse files
authored
Update dependency, program id and test for pyth-price-store (#314)
* test: modify batch publish tests * chore: use real batch publish pid as default * chore: update pyth-price-store dependency
1 parent 2a7cebd commit c2270e5

File tree

5 files changed

+53
-31
lines changed

5 files changed

+53
-31
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ once_cell = "1.12.0"
3737
ouroboros = "0.15.0"
3838
pyth-oracle = { git = "https://github.com/pyth-network/pyth-client", rev = "256b57", features = ["library"] }
3939
pythnet-sdk = { git = "https://github.com/pyth-network/pyth-crosschain", version = "1.13.6", rev = "33f901aa45f4f0005aa5a84a1479b78ca9033074" }
40-
pyth-price-publisher = { git = "https://github.com/pyth-network/pyth-crosschain", branch = "add-publisher-program" }
40+
pyth-price-store = "0.1.0"
4141
rand = "0.7.0"
4242
rayon = "1.5.3"
4343
regex = "1.5.6"

runtime/src/bank/pyth/accumulator.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ lazy_static! {
6060
);
6161
pub static ref BATCH_PUBLISH_PID: Pubkey = env_pubkey_or(
6262
"BATCH_PUBLISH_PID",
63-
// TODO: replace with real program id
64-
"FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epA"
63+
"3m6sv6HGqEbuyLV84mD7rJn4MAC9LhUa1y1AUNVqcPfr"
6564
.parse()
6665
.unwrap(),
6766
);

runtime/src/bank/pyth/batch_publish.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use {
99
find_publisher_index, get_status_for_conf_price_ratio, solana_program::pubkey::Pubkey,
1010
OracleError, PriceAccount,
1111
},
12-
pyth_price_publisher::accounts::publisher_prices as publisher_prices_account,
12+
pyth_price_store::accounts::buffer,
1313
solana_sdk::{account::ReadableAccount, clock::Slot},
1414
std::collections::HashMap,
1515
thiserror::Error,
@@ -37,7 +37,7 @@ pub fn extract_batch_publish_prices(
3737
"Oracle program account index missing"
3838
);
3939

40-
let publisher_prices_accounts = bank
40+
let publish_program_accounts = bank
4141
.get_filtered_indexed_accounts(
4242
&IndexKey::ProgramId(*BATCH_PUBLISH_PID),
4343
|account| account.owner() == &*BATCH_PUBLISH_PID,
@@ -49,11 +49,11 @@ pub fn extract_batch_publish_prices(
4949
let mut all_prices = HashMap::<u32, Vec<PublisherPriceValue>>::new();
5050
let mut num_found_accounts = 0;
5151
let mut num_found_prices = 0;
52-
for (account_key, account) in publisher_prices_accounts {
53-
if !publisher_prices_account::format_matches(account.data()) {
52+
for (account_key, account) in publish_program_accounts {
53+
if !buffer::format_matches(account.data()) {
5454
continue;
5555
}
56-
let (header, prices) = match publisher_prices_account::read(account.data()) {
56+
let (header, prices) = match buffer::read(account.data()) {
5757
Ok(r) => r,
5858
Err(err) => {
5959
warn!("invalid publisher prices account {}: {}", account_key, err);

runtime/src/bank/pyth/tests/batch_publish_tests.rs

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ use {
1010
pyth_oracle::{
1111
solana_program::account_info::AccountInfo, PriceAccount, PriceAccountFlags, PythAccount,
1212
},
13-
pyth_price_publisher::accounts::publisher_prices::{
14-
self as publisher_prices_account, PublisherPrice,
13+
pyth_price_store::{
14+
accounts::{
15+
buffer::{self, BufferedPrice},
16+
publisher_config,
17+
},
18+
instruction::PUBLISHER_CONFIG_SEED,
1519
},
1620
solana_sdk::{
1721
account::{AccountSharedData, ReadableAccount, WritableAccount},
@@ -38,37 +42,55 @@ fn test_batch_publish() {
3842
genesis_config.epoch_schedule = EpochSchedule::new(slots_in_epoch);
3943
let mut bank = create_new_bank_for_tests_with_index(&genesis_config);
4044

41-
let generate_publisher = |seed, new_prices| {
42-
let publisher1_key = keypair_from_seed(seed).unwrap();
45+
let generate_publisher = |seed, seed2, new_prices| {
46+
let publisher_key = keypair_from_seed(seed).unwrap();
4347

44-
let (publisher1_prices_key, _bump) = Pubkey::find_program_address(
45-
&[b"BUFFER", &publisher1_key.pubkey().to_bytes()],
48+
let (publisher_config_key, _bump) = Pubkey::find_program_address(
49+
&[
50+
PUBLISHER_CONFIG_SEED.as_bytes(),
51+
&publisher_key.pubkey().to_bytes(),
52+
],
4653
&BATCH_PUBLISH_PID,
4754
);
48-
let mut publisher1_prices_account =
49-
AccountSharedData::new(42, publisher_prices_account::size(100), &BATCH_PUBLISH_PID);
55+
let publisher_buffer_key =
56+
Pubkey::create_with_seed(&leader_pubkey, seed2, &BATCH_PUBLISH_PID).unwrap();
57+
58+
let mut publisher_config_account =
59+
AccountSharedData::new(42, publisher_config::SIZE, &BATCH_PUBLISH_PID);
60+
61+
publisher_config::create(
62+
publisher_config_account.data_mut(),
63+
publisher_key.pubkey().to_bytes(),
64+
publisher_buffer_key.to_bytes(),
65+
)
66+
.unwrap();
67+
bank.store_account(&publisher_config_key, &publisher_config_account);
68+
69+
let mut publisher_buffer_account =
70+
AccountSharedData::new(42, buffer::size(100), &BATCH_PUBLISH_PID);
5071
{
51-
let (header, prices) = publisher_prices_account::create(
52-
publisher1_prices_account.data_mut(),
53-
publisher1_key.pubkey().to_bytes(),
72+
let (header, prices) = buffer::create(
73+
publisher_buffer_account.data_mut(),
74+
publisher_key.pubkey().to_bytes(),
5475
)
5576
.unwrap();
56-
publisher_prices_account::extend(header, prices, cast_slice(new_prices)).unwrap();
77+
buffer::update(header, prices, bank.slot(), cast_slice(new_prices)).unwrap();
5778
}
58-
bank.store_account(&publisher1_prices_key, &publisher1_prices_account);
79+
bank.store_account(&publisher_buffer_key, &publisher_buffer_account);
5980

60-
publisher1_key
81+
publisher_key
6182
};
6283

6384
let publishers = [
6485
generate_publisher(
6586
&[1u8; 32],
87+
"seed1",
6688
&[
67-
PublisherPrice::new(1, 1, 10, 2).unwrap(),
68-
PublisherPrice::new(2, 1, 20, 3).unwrap(),
89+
BufferedPrice::new(1, 1, 10, 2).unwrap(),
90+
BufferedPrice::new(2, 1, 20, 3).unwrap(),
6991
// Attempt to publish with price_index == 0,
7092
// but it will not be applied.
71-
PublisherPrice {
93+
BufferedPrice {
7294
trading_status_and_feed_index: 0,
7395
price: 30,
7496
confidence: 35,
@@ -77,9 +99,10 @@ fn test_batch_publish() {
7799
),
78100
generate_publisher(
79101
&[2u8; 32],
102+
"seed2",
80103
&[
81-
PublisherPrice::new(1, 1, 15, 2).unwrap(),
82-
PublisherPrice::new(2, 1, 25, 3).unwrap(),
104+
BufferedPrice::new(1, 1, 15, 2).unwrap(),
105+
BufferedPrice::new(2, 1, 25, 3).unwrap(),
83106
],
84107
),
85108
];

0 commit comments

Comments
 (0)