Skip to content

Commit db835e4

Browse files
committed
refactor: clean up and avoid extra vector
1 parent 281e9d4 commit db835e4

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
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", features = ["library"] }
38+
pyth-oracle = { git = "https://github.com/pyth-network/pyth-client", branch = "accumulator-v2", 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: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn get_accumulator_keys() -> Vec<(
133133

134134
pub fn update_v1<'a>(
135135
bank: &Bank,
136-
v2_messages: Vec<&'a [u8]>,
136+
v2_messages: &[Vec<u8>],
137137
use_message_buffers: bool,
138138
) -> std::result::Result<(), AccumulatorUpdateErrorV1> {
139139
use {
@@ -214,8 +214,8 @@ pub fn update_v1<'a>(
214214
Vec::new()
215215
};
216216

217-
let mut messages = v2_messages;
218-
messages.extend(v1_messages);
217+
let mut messages = v1_messages;
218+
messages.extend(v2_messages.iter().map(|x| &**x));
219219

220220
// We now generate a Proof PDA (Owned by the System Program) to store the resulting Proof
221221
// Set. The derivation includes the ring buffer index to simulate a ring buffer in order
@@ -376,18 +376,15 @@ fn post_accumulator_attestation(
376376
}
377377

378378
pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV1> {
379-
// 1. Find Oracle
380379
let oracle_pubkey = ORACLE_PUBKEY.ok_or(AccumulatorUpdateErrorV1::NoOraclePubkey)?;
381380

382-
// 2. Find Oracle Accounts
383381
let accounts = bank
384382
.get_program_accounts(&oracle_pubkey, &ScanConfig::new(true))
385383
.map_err(AccumulatorUpdateErrorV1::GetProgramAccounts)?;
386384

387385
let mut any_v1_aggregations = false;
388386
let mut v2_messages = Vec::new();
389387

390-
// 3. Call Aggregation on Price Accounts.
391388
for (pubkey, mut account) in accounts {
392389
let mut price_account_data = account.data().to_owned();
393390

@@ -414,16 +411,5 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV
414411
}
415412
}
416413

417-
// TODO: make new messages
418-
update_v1(
419-
bank,
420-
v2_messages.iter().map(|x| &**x).collect(),
421-
any_v1_aggregations,
422-
)?;
423-
424-
// 5. Merkleize the results.
425-
426-
// 6. Create Wormhole Message Account
427-
428-
Ok(())
414+
update_v1(bank, &v2_messages, any_v1_aggregations)
429415
}

0 commit comments

Comments
 (0)