Skip to content

Commit 0387cdf

Browse files
committed
feat: batch publish 2 (wip)
1 parent c0bb42c commit 0387cdf

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
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
@@ -447,17 +447,11 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV
447447
for (pubkey, mut account) in accounts {
448448
let mut price_account_data = account.data().to_owned();
449449
let price_account =
450-
match pyth_oracle::validator::validate_price_account(&mut price_account_data) {
450+
match pyth_oracle::validator::checked_load_price_account_mut(&mut price_account_data) {
451451
Ok(data) => data,
452-
Err(err) => match err {
453-
AggregationError::NotPriceFeedAccount => {
454-
continue;
455-
}
456-
AggregationError::V1AggregationMode | AggregationError::AlreadyAggregated => {
457-
any_v1_aggregations = true;
458-
continue;
459-
}
460-
},
452+
Err(_err) => {
453+
continue;
454+
}
461455
};
462456

463457
let mut need_save =
@@ -474,7 +468,7 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV
474468
need_save = true;
475469
v2_messages.extend(messages);
476470
}
477-
Err(err) => match dbg!(err) {
471+
Err(err) => match err {
478472
AggregationError::NotPriceFeedAccount => {}
479473
AggregationError::V1AggregationMode | AggregationError::AlreadyAggregated => {
480474
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
@@ -1228,7 +1228,7 @@ fn test_batch_publish() {
12281228
price_account.flags.insert(
12291229
PriceAccountFlags::ACCUMULATOR_V2 | PriceAccountFlags::MESSAGE_BUFFER_CLEARED,
12301230
);
1231-
price_account.unused_3_ = index;
1231+
price_account.feed_index = index;
12321232
price_account.comp_[0].pub_ = publishers[0].pubkey().to_bytes().into();
12331233
price_account.comp_[1].pub_ = publishers[1].pubkey().to_bytes().into();
12341234
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)