Skip to content

Commit 9da1b60

Browse files
committed
feat: batch publish 2 (wip)
1 parent 6982f90 commit 9da1b60

File tree

4 files changed

+88
-47
lines changed

4 files changed

+88
-47
lines changed

Cargo.lock

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

runtime/src/bank/pyth_accumulator.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -432,17 +432,11 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV
432432
for (pubkey, mut account) in accounts {
433433
let mut price_account_data = account.data().to_owned();
434434
let price_account =
435-
match pyth_oracle::validator::validate_price_account(&mut price_account_data) {
435+
match pyth_oracle::validator::checked_load_price_account_mut(&mut price_account_data) {
436436
Ok(data) => data,
437-
Err(err) => match err {
438-
AggregationError::NotPriceFeedAccount => {
439-
continue;
440-
}
441-
AggregationError::V1AggregationMode | AggregationError::AlreadyAggregated => {
442-
any_v1_aggregations = true;
443-
continue;
444-
}
445-
},
437+
Err(_err) => {
438+
continue;
439+
}
446440
};
447441

448442
let mut need_save =
@@ -459,7 +453,7 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV
459453
need_save = true;
460454
v2_messages.extend(messages);
461455
}
462-
Err(err) => match dbg!(err) {
456+
Err(err) => match err {
463457
AggregationError::NotPriceFeedAccount => {}
464458
AggregationError::V1AggregationMode | AggregationError::AlreadyAggregated => {
465459
any_v1_aggregations = true;

runtime/src/bank/pyth_accumulator_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ fn test_batch_publish() {
988988
price_account.flags.insert(
989989
PriceAccountFlags::ACCUMULATOR_V2 | PriceAccountFlags::MESSAGE_BUFFER_CLEARED,
990990
);
991-
price_account.unused_3_ = index;
991+
price_account.feed_index = index;
992992
price_account.comp_[0].pub_ = publishers[0].pubkey().to_bytes().into();
993993
price_account.comp_[1].pub_ = publishers[1].pubkey().to_bytes().into();
994994
price_account.num_ = 2;

runtime/src/bank/pyth_batch_publish.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use {
1111
thiserror::Error,
1212
};
1313

14+
// TODO: move to the publish program
1415
#[allow(dead_code)]
1516
pub mod publisher_prices_account {
1617
use {
@@ -224,15 +225,16 @@ pub fn extract_batch_publish_prices(
224225
}
225226
let publisher = header.publisher.into();
226227
for price in prices {
228+
let value = PublisherPriceValue {
229+
publisher,
230+
trading_status: price.trading_status(),
231+
price: price.price,
232+
confidence: price.confidence,
233+
};
227234
all_prices
228235
.entry(price.feed_index())
229236
.or_default()
230-
.push(PublisherPriceValue {
231-
publisher,
232-
trading_status: price.trading_status(),
233-
price: price.price,
234-
confidence: price.confidence,
235-
});
237+
.push(value);
236238
}
237239
}
238240
Ok(all_prices)
@@ -243,8 +245,7 @@ pub fn apply_published_prices(
243245
new_prices: &HashMap<u32, Vec<PublisherPriceValue>>,
244246
slot: Slot,
245247
) -> bool {
246-
// TODO: store index here or somewhere else?
247-
let price_feed_index = price_data.unused_3_ as u32;
248+
let price_feed_index = price_data.feed_index as u32;
248249
let mut any_update = false;
249250
for new_price in new_prices.get(&price_feed_index).unwrap_or(&Vec::new()) {
250251
match apply_published_price(price_data, new_price, slot) {
@@ -254,7 +255,7 @@ pub fn apply_published_prices(
254255
Err(err) => {
255256
warn!(
256257
"failed to apply publisher price to price feed {}: {}",
257-
price_data.unused_3_ as u32, err
258+
price_data.feed_index as u32, err
258259
);
259260
}
260261
}
@@ -285,7 +286,7 @@ fn apply_published_price(
285286
.ok_or(ApplyPublishedPriceError::InvalidPublishersNum)?;
286287

287288
let publisher_index = find_publisher_index(publishers, &new_price.publisher).ok_or(
288-
ApplyPublishedPriceError::NoPermission(price_data.unused_3_ as u32, new_price.publisher),
289+
ApplyPublishedPriceError::NoPermission(price_data.feed_index as u32, new_price.publisher),
289290
)?;
290291

291292
// IMPORTANT: If the publisher does not meet the price/conf

0 commit comments

Comments
 (0)