Skip to content

Commit

Permalink
feat: batch publish 2 (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
Riateche committed Aug 1, 2024
1 parent 6982f90 commit 9da1b60
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 47 deletions.
96 changes: 71 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 5 additions & 11 deletions runtime/src/bank/pyth_accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,17 +432,11 @@ 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 =
match pyth_oracle::validator::validate_price_account(&mut price_account_data) {
match pyth_oracle::validator::checked_load_price_account_mut(&mut price_account_data) {
Ok(data) => data,
Err(err) => match err {
AggregationError::NotPriceFeedAccount => {
continue;
}
AggregationError::V1AggregationMode | AggregationError::AlreadyAggregated => {
any_v1_aggregations = true;
continue;
}
},
Err(_err) => {
continue;
}
};

let mut need_save =
Expand All @@ -459,7 +453,7 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV
need_save = true;
v2_messages.extend(messages);
}
Err(err) => match dbg!(err) {
Err(err) => match err {
AggregationError::NotPriceFeedAccount => {}
AggregationError::V1AggregationMode | AggregationError::AlreadyAggregated => {
any_v1_aggregations = true;
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank/pyth_accumulator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ fn test_batch_publish() {
price_account.flags.insert(
PriceAccountFlags::ACCUMULATOR_V2 | PriceAccountFlags::MESSAGE_BUFFER_CLEARED,
);
price_account.unused_3_ = index;
price_account.feed_index = index;
price_account.comp_[0].pub_ = publishers[0].pubkey().to_bytes().into();
price_account.comp_[1].pub_ = publishers[1].pubkey().to_bytes().into();
price_account.num_ = 2;
Expand Down
21 changes: 11 additions & 10 deletions runtime/src/bank/pyth_batch_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use {
thiserror::Error,
};

// TODO: move to the publish program
#[allow(dead_code)]
pub mod publisher_prices_account {
use {
Expand Down Expand Up @@ -224,15 +225,16 @@ pub fn extract_batch_publish_prices(
}
let publisher = header.publisher.into();
for price in prices {
let value = PublisherPriceValue {
publisher,
trading_status: price.trading_status(),
price: price.price,
confidence: price.confidence,
};
all_prices
.entry(price.feed_index())
.or_default()
.push(PublisherPriceValue {
publisher,
trading_status: price.trading_status(),
price: price.price,
confidence: price.confidence,
});
.push(value);
}
}
Ok(all_prices)
Expand All @@ -243,8 +245,7 @@ pub fn apply_published_prices(
new_prices: &HashMap<u32, Vec<PublisherPriceValue>>,
slot: Slot,
) -> bool {
// TODO: store index here or somewhere else?
let price_feed_index = price_data.unused_3_ as u32;
let price_feed_index = price_data.feed_index as u32;
let mut any_update = false;
for new_price in new_prices.get(&price_feed_index).unwrap_or(&Vec::new()) {
match apply_published_price(price_data, new_price, slot) {
Expand All @@ -254,7 +255,7 @@ pub fn apply_published_prices(
Err(err) => {
warn!(
"failed to apply publisher price to price feed {}: {}",
price_data.unused_3_ as u32, err
price_data.feed_index as u32, err
);
}
}
Expand Down Expand Up @@ -285,7 +286,7 @@ fn apply_published_price(
.ok_or(ApplyPublishedPriceError::InvalidPublishersNum)?;

let publisher_index = find_publisher_index(publishers, &new_price.publisher).ok_or(
ApplyPublishedPriceError::NoPermission(price_data.unused_3_ as u32, new_price.publisher),
ApplyPublishedPriceError::NoPermission(price_data.feed_index as u32, new_price.publisher),
)?;

// IMPORTANT: If the publisher does not meet the price/conf
Expand Down

0 comments on commit 9da1b60

Please sign in to comment.