Skip to content

Commit a4cafa9

Browse files
committed
feat: accumulator v2 (wip 3)
1 parent 0bb6502 commit a4cafa9

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 0 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
@@ -35,7 +35,7 @@ num-traits = { version = "0.2" }
3535
num_cpus = "1.13.1"
3636
once_cell = "1.12.0"
3737
ouroboros = "0.15.0"
38-
pyth-oracle = { path = "../../pyth-client/program/rust" }
38+
pyth-oracle = { path = "../../pyth-client/program/rust", features = ["library"] }
3939
pythnet-sdk = { git = "https://github.com/pyth-network/pyth-crosschain", version = "1.13.6", rev = "e670f57f89b05398ca352e4accb1e32724a8e1b4" }
4040
rand = "0.7.0"
4141
rayon = "1.5.3"

runtime/src/bank/pyth_accumulator.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub fn update_accumulator(bank: &Bank) {
9797
};
9898
}
9999

100+
// TODO: No longer a slot or feature flag, based on price account flag.
100101
if (*ACCUMULATOR_V2_SLOT).map_or(false, |v2_slot| bank.slot() >= v2_slot) {
101102
if let Err(e) = update_v2(bank) {
102103
error!("Error updating accumulator: {:?}", e);
@@ -398,14 +399,28 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV
398399
.get_program_accounts(&oracle_pubkey, &ScanConfig::new(true))
399400
.map_err(AccumulatorUpdateErrorV2::GetProgramAccounts)?;
400401

401-
// 3. Filter for Price Accounts
402-
let accounts = accounts.iter().filter(|(_, account)| true);
402+
// 3. Call Aggregation on Price Accounts.
403+
for (pubkey, mut account) in accounts {
404+
let mut price_account_data = account.data().to_owned();
405+
406+
// Perform Accumulation
407+
match pyth_oracle::validator::aggregate_price(
408+
bank.slot(),
409+
bank.clock().unix_timestamp,
410+
&mut price_account_data,
411+
) {
412+
Ok(success) => {
413+
if success {
414+
account.set_data(price_account_data);
415+
bank.store_account_and_update_capitalization(&pubkey, &account);
416+
}
417+
}
418+
Err(err) => trace!("Aggregation: failed to update_price_cumulative, {:?}", err),
419+
}
420+
}
403421

404-
// 4. Pass the PriceAccounts to the Oracle Code
405-
// - Change Oracle to not run update code.
406-
// - Change Oracle to have the aggregation code itself as a pure function.
407-
// - Call aggregation with PriceAccount as input.
408422
// 5. Merkleize the results.
423+
409424
// 6. Create Wormhole Message Account
410425

411426
Ok(())

0 commit comments

Comments
 (0)