@@ -1284,7 +1284,7 @@ pub struct CommitTransactionCounts {
12841284/// Accumulator specific error type. It would be nice to use `transaction::Error` but it does
12851285/// not include any `Custom` style variant we can leverage, so we introduce our own.
12861286#[derive(Debug, thiserror::Error)]
1287- enum AccumulatorUpdateError {
1287+ pub enum AccumulatorUpdateError {
12881288 #[error("get_program_accounts failed to return accounts")]
12891289 GetProgramAccounts,
12901290
@@ -2705,7 +2705,7 @@ impl Bank {
27052705 account
27062706 };
27072707
2708- // Serialize into (and create if necesary ) the message account.
2708+ // Serialize into (and create if necessary ) the message account.
27092709 let message = message
27102710 .try_to_vec()
27112711 .map_err(|_| AccumulatorUpdateError::FailedMessageSerialization)?;
@@ -2747,6 +2747,40 @@ impl Bank {
27472747 .unwrap_or(default))
27482748 }
27492749
2750+ /// Get all accumulator related pubkeys from environment variables
2751+ /// or return default if the variable is not set.
2752+ pub fn get_accumulator_keys(
2753+ &self,
2754+ ) -> Vec<(&str, std::result::Result<Pubkey, AccumulatorUpdateError>)> {
2755+ use pythnet_sdk::{pythnet, ACCUMULATOR_EMITTER_ADDRESS, MESSAGE_BUFFER_PID};
2756+ let accumulator_keys = vec![
2757+ (
2758+ "MESSAGE_BUFFER_PID",
2759+ Pubkey::new_from_array(MESSAGE_BUFFER_PID),
2760+ ),
2761+ // accumulator emitter address should always be the same regardless
2762+ // of environment but checking here for completeness
2763+ (
2764+ "ACCUMULATOR_EMITTER_ADDR",
2765+ Pubkey::new_from_array(ACCUMULATOR_EMITTER_ADDRESS),
2766+ ),
2767+ (
2768+ "ACCUMULATOR_SEQUENCE_ADDR",
2769+ Pubkey::new_from_array(pythnet::ACCUMULATOR_SEQUENCE_ADDR),
2770+ ),
2771+ (
2772+ "WORMHOLE_PID",
2773+ Pubkey::new_from_array(pythnet::WORMHOLE_PID),
2774+ ),
2775+ ];
2776+ let accumulator_pubkeys: Vec<(&str, std::result::Result<Pubkey, AccumulatorUpdateError>)> =
2777+ accumulator_keys
2778+ .iter()
2779+ .map(|(k, d)| (*k, self.env_pubkey_or(k, *d)))
2780+ .collect();
2781+ accumulator_pubkeys
2782+ }
2783+
27502784 pub fn epoch_duration_in_years(&self, prev_epoch: Epoch) -> f64 {
27512785 // period: time that has passed as a fraction of a year, basically the length of
27522786 // an epoch as a fraction of a year
@@ -15337,6 +15371,27 @@ pub(crate) mod tests {
1533715371 // 3. Check if message offset is > message size to prevent validator crash.
1533815372 }
1533915373
15374+ #[test]
15375+ fn test_get_accumulator_keys() {
15376+ use pythnet_sdk::{pythnet, ACCUMULATOR_EMITTER_ADDRESS, MESSAGE_BUFFER_PID};
15377+ let leader_pubkey = solana_sdk::pubkey::new_rand();
15378+ let GenesisConfigInfo { genesis_config, .. } =
15379+ create_genesis_config_with_leader(5, &leader_pubkey, 3);
15380+ let bank = Bank::new_for_tests(&genesis_config);
15381+ let accumulator_keys: Vec<Pubkey> = bank
15382+ .get_accumulator_keys()
15383+ .iter()
15384+ .map(|(_, pk_res)| *pk_res.as_ref().unwrap())
15385+ .collect();
15386+ let expected_pyth_keys = vec![
15387+ Pubkey::new_from_array(MESSAGE_BUFFER_PID),
15388+ Pubkey::new_from_array(ACCUMULATOR_EMITTER_ADDRESS),
15389+ Pubkey::new_from_array(pythnet::ACCUMULATOR_SEQUENCE_ADDR),
15390+ Pubkey::new_from_array(pythnet::WORMHOLE_PID),
15391+ ];
15392+ assert_eq!(accumulator_keys, expected_pyth_keys);
15393+ }
15394+
1534015395 fn poh_estimate_offset(bank: &Bank) -> Duration {
1534115396 let mut epoch_start_slot = bank.epoch_schedule.get_first_slot_in_epoch(bank.epoch());
1534215397 if epoch_start_slot == bank.slot() {
0 commit comments