-
Notifications
You must be signed in to change notification settings - Fork 16
Batch publish #313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Batch publish #313
Changes from 6 commits
0fb5ef4
c0bb42c
0387cdf
491e168
2611090
9ceff43
ee765c5
36e1c80
85d59d9
4a97a26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Check Pythnet | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [pyth-v1.14.17] | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: 1.60.0 | ||
components: clippy | ||
override: true | ||
- name: Install dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y libssl-dev libudev-dev pkg-config zlib1g-dev llvm clang cmake make libprotobuf-dev | ||
- name: Run tests | ||
run: cargo test -p solana-runtime pyth | ||
clippy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: 1.60.0 | ||
components: clippy | ||
override: true | ||
- name: Install dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y libssl-dev libudev-dev pkg-config zlib1g-dev llvm clang cmake make libprotobuf-dev | ||
- name: Check clippy | ||
run: cargo clippy --bins --tests --examples -- --deny warnings | ||
format: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: nightly-2022-04-01 | ||
components: rustfmt | ||
override: true | ||
- name: Check formatting | ||
run: cargo fmt -- --check |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
use { | ||
super::Bank, | ||
crate::accounts_index::{IndexKey, ScanConfig, ScanError}, | ||
super::batch_publish, | ||
crate::{ | ||
accounts_index::{IndexKey, ScanConfig, ScanError}, | ||
bank::Bank, | ||
}, | ||
byteorder::{LittleEndian, ReadBytesExt}, | ||
itertools::Itertools, | ||
log::*, | ||
pyth_oracle::validator::AggregationError, | ||
pythnet_sdk::{ | ||
|
@@ -17,7 +21,10 @@ use { | |
hash::hashv, | ||
pubkey::Pubkey, | ||
}, | ||
std::env::{self, VarError}, | ||
std::{ | ||
collections::HashMap, | ||
env::{self, VarError}, | ||
}, | ||
}; | ||
|
||
pub const ACCUMULATOR_RING_SIZE: u32 = 10_000; | ||
|
@@ -51,6 +58,13 @@ lazy_static! { | |
.parse() | ||
.unwrap(), | ||
); | ||
pub static ref BATCH_PUBLISH_PID: Pubkey = env_pubkey_or( | ||
"BATCH_PUBLISH_PID", | ||
// TODO: replace with real program id | ||
"FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epA" | ||
.parse() | ||
.unwrap(), | ||
); | ||
} | ||
|
||
/// Accumulator specific error type. It would be nice to use `transaction::Error` but it does | ||
|
@@ -132,6 +146,7 @@ pub fn get_accumulator_keys() -> Vec<( | |
"STAKE_CAPS_PARAMETERS_ADDR", | ||
Ok(*STAKE_CAPS_PARAMETERS_ADDR), | ||
), | ||
("BATCH_PUBLISH_PID", Ok(*BATCH_PUBLISH_PID)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i recommend we rename this function and move it to mod.rs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
] | ||
} | ||
|
||
|
@@ -427,21 +442,34 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV | |
v2_messages.push(publisher_stake_caps_message); | ||
} | ||
|
||
let mut measure = Measure::start("update_v2_aggregate_price"); | ||
let mut new_prices = batch_publish::extract_batch_publish_prices(bank).unwrap_or_else(|err| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's have a measure for this too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
warn!("extract_batch_publish_prices failed: {}", err); | ||
HashMap::new() | ||
}); | ||
|
||
let mut measure = Measure::start("update_v2_aggregate_price"); | ||
for (pubkey, mut account) in accounts { | ||
let mut price_account_data = account.data().to_owned(); | ||
let price_account = | ||
match pyth_oracle::validator::checked_load_price_account_mut(&mut price_account_data) { | ||
Ok(data) => data, | ||
Err(_err) => { | ||
continue; | ||
} | ||
}; | ||
|
||
let mut need_save = | ||
batch_publish::apply_published_prices(price_account, &mut new_prices, bank.slot()); | ||
|
||
// Perform Accumulation | ||
match pyth_oracle::validator::aggregate_price( | ||
bank.slot(), | ||
bank.clock().unix_timestamp, | ||
&pubkey.to_bytes().into(), | ||
&mut price_account_data, | ||
price_account, | ||
) { | ||
Ok(messages) => { | ||
account.set_data(price_account_data); | ||
bank.store_account_and_update_capitalization(&pubkey, &account); | ||
need_save = true; | ||
v2_messages.extend(messages); | ||
} | ||
Err(err) => match err { | ||
|
@@ -451,6 +479,16 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV | |
} | ||
}, | ||
} | ||
if need_save { | ||
account.set_data(price_account_data); | ||
bank.store_account_and_update_capitalization(&pubkey, &account); | ||
} | ||
} | ||
if !new_prices.is_empty() { | ||
warn!( | ||
"pyth batch publish: missing price feed accounts for indexes: {}", | ||
new_prices.keys().join(", ") | ||
); | ||
} | ||
|
||
measure.stop(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.