@@ -1284,7 +1284,7 @@ pub struct CommitTransactionCounts {
1284
1284
/// Accumulator specific error type. It would be nice to use `transaction::Error` but it does
1285
1285
/// not include any `Custom` style variant we can leverage, so we introduce our own.
1286
1286
#[derive(Debug, thiserror::Error)]
1287
- enum AccumulatorUpdateError {
1287
+ pub enum AccumulatorUpdateError {
1288
1288
#[error("get_program_accounts failed to return accounts")]
1289
1289
GetProgramAccounts,
1290
1290
@@ -2705,7 +2705,7 @@ impl Bank {
2705
2705
account
2706
2706
};
2707
2707
2708
- // Serialize into (and create if necesary ) the message account.
2708
+ // Serialize into (and create if necessary ) the message account.
2709
2709
let message = message
2710
2710
.try_to_vec()
2711
2711
.map_err(|_| AccumulatorUpdateError::FailedMessageSerialization)?;
@@ -2747,6 +2747,40 @@ impl Bank {
2747
2747
.unwrap_or(default))
2748
2748
}
2749
2749
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
+
2750
2784
pub fn epoch_duration_in_years(&self, prev_epoch: Epoch) -> f64 {
2751
2785
// period: time that has passed as a fraction of a year, basically the length of
2752
2786
// an epoch as a fraction of a year
@@ -15337,6 +15371,27 @@ pub(crate) mod tests {
15337
15371
// 3. Check if message offset is > message size to prevent validator crash.
15338
15372
}
15339
15373
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
+
15340
15395
fn poh_estimate_offset(bank: &Bank) -> Duration {
15341
15396
let mut epoch_start_slot = bank.epoch_schedule.get_first_slot_in_epoch(bank.epoch());
15342
15397
if epoch_start_slot == bank.slot() {
0 commit comments