Skip to content

Commit edbbe96

Browse files
committed
fixup! pyth: introduce pyth accumulator library
1 parent dc44d29 commit edbbe96

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

runtime/src/bank.rs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,13 +1885,19 @@ impl Bank {
18851885
new.update_stake_history(Some(parent_epoch));
18861886
new.update_clock(Some(parent_epoch));
18871887
new.update_fees();
1888+
},
1889+
(),
1890+
"update_sysvars",
1891+
);
18881892

1893+
let (_, update_accumulator_time) = Measure::this(
1894+
|_| {
18891895
// Update the accumulator last to make sure that all sysvars are in a
18901896
// fully updated state before the accumulator sysvar updates.
18911897
new.update_accumulator();
18921898
},
18931899
(),
1894-
"update_sysvars",
1900+
"update_accumulator",
18951901
);
18961902

18971903
let (_, fill_sysvar_cache_time) = Measure::this(
@@ -1934,6 +1940,11 @@ impl Bank {
19341940
("ancestors_us", ancestors_time.as_us(), i64),
19351941
("update_epoch_us", update_epoch_time.as_us(), i64),
19361942
("update_sysvars_us", update_sysvars_time.as_us(), i64),
1943+
(
1944+
"update_accumulator_us",
1945+
update_accumulator_time.as_us(),
1946+
i64
1947+
),
19371948
("fill_sysvar_cache_us", fill_sysvar_cache_time.as_us(), i64),
19381949
);
19391950

@@ -2484,20 +2495,6 @@ impl Bank {
24842495
});
24852496
}
24862497

2487-
/// Loads the Accumulator Sysvar from disk, creating an empty account for it if it does not
2488-
/// exist already. See `clock` to see a similar sysvar this is based on.
2489-
pub fn accumulator(
2490-
&self,
2491-
) -> sysvar::accumulator::MerkleAccumulator<pythnet_sdk::hashers::keccak256_160::Keccak160>
2492-
{
2493-
from_account(
2494-
&self
2495-
.get_account(&sysvar::accumulator::id())
2496-
.unwrap_or_default(),
2497-
)
2498-
.unwrap_or_default()
2499-
}
2500-
25012498
/// Updates the Accumulator Sysvar at the start of a new slot. See `update_clock` to see a similar
25022499
/// sysvar this is based on.
25032500
///
@@ -2510,10 +2507,13 @@ impl Bank {
25102507
.feature_set
25112508
.is_active(&feature_set::enable_accumulator_sysvar::id())
25122509
{
2513-
info!("Accumulator: Skipping because the feature is disabled. Slot: {}", self.slot());
2510+
info!(
2511+
"Accumulator: Skipping because the feature is disabled. Slot: {}",
2512+
self.slot()
2513+
);
25142514
return;
25152515
}
2516-
2516+
25172517
info!("Accumulator: Updating accumulator. Slot: {}", self.slot());
25182518
if let Err(e) = self.update_accumulator_impl() {
25192519
error!("Error updating accumulator: {:?}", e);
@@ -2625,7 +2625,10 @@ impl Bank {
26252625

26262626
// Write the Account Set into `accumulator_state` so that the hermes application can
26272627
// request historical data to prove.
2628-
info!("Accumulator: Writing accumulator state to {:?}", accumulator_account);
2628+
info!(
2629+
"Accumulator: Writing accumulator state to {:?}",
2630+
accumulator_account
2631+
);
26292632
self.store_account_and_update_capitalization(&accumulator_account, &accumulator_data);
26302633

26312634
Ok(())
@@ -15111,10 +15114,7 @@ pub(crate) mod tests {
1511115114

1511215115
// Derive the Wormhole Message Account that will be generated by the sysvar updater.
1511315116
let (wormhole_message_pubkey, _bump) = Pubkey::find_program_address(
15114-
&[
15115-
b"AccumulatorMessage",
15116-
&(bank.slot() as u32).to_be_bytes(),
15117-
],
15117+
&[b"AccumulatorMessage", &(bank.slot() as u32).to_be_bytes()],
1511815118
&Pubkey::new_from_array(pythnet_sdk::pythnet::WORMHOLE_PID),
1511915119
);
1512015120

@@ -15242,16 +15242,14 @@ pub(crate) mod tests {
1524215242
);
1524315243

1524415244
// verify ring buffer cycles
15245-
let ring_index_before_buffer_cycle =
15246-
(bank.slot() % ACCUMULATOR_RING_SIZE as u64) as u32;
15245+
let ring_index_before_buffer_cycle = (bank.slot() % ACCUMULATOR_RING_SIZE as u64) as u32;
1524715246
let target_slot = bank.slot() + ACCUMULATOR_RING_SIZE as u64;
1524815247
// advance ACCUMULATOR_RING_SIZE slots using warp_from_parent since doing large loops
1524915248
// with new_from_parent takes a long time. warp_from_parent results in a bank that is frozen.
1525015249
bank = Bank::warp_from_parent(&Arc::new(bank), &Pubkey::default(), target_slot);
1525115250

1525215251
// accumulator messages should still be the same before looping around
15253-
let ring_index_after_buffer_cycle =
15254-
(bank.slot() % ACCUMULATOR_RING_SIZE as u64) as u32;
15252+
let ring_index_after_buffer_cycle = (bank.slot() % ACCUMULATOR_RING_SIZE as u64) as u32;
1525515253
assert_eq!(
1525615254
ring_index_before_buffer_cycle,
1525715255
ring_index_after_buffer_cycle

sdk/program/src/sysvar/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use {
99
lazy_static::lazy_static,
1010
};
1111

12-
pub mod accumulator;
1312
pub mod clock;
1413
pub mod epoch_schedule;
1514
pub mod fees;
@@ -35,7 +34,6 @@ lazy_static! {
3534
slot_history::id(),
3635
stake_history::id(),
3736
instructions::id(),
38-
accumulator::id(),
3937
];
4038
}
4139

0 commit comments

Comments
 (0)