71
71
dashmap::DashMap,
72
72
itertools::Itertools,
73
73
log::*,
74
- pythnet_sdk::pythnet,
75
74
rand::Rng,
76
75
rayon::{
77
76
iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator},
@@ -2515,8 +2514,7 @@ impl Bank {
2515
2514
pythnet_sdk::{
2516
2515
accumulators::{merkle::MerkleAccumulator, Accumulator},
2517
2516
hashers::keccak256_160::Keccak160,
2518
- pythnet::PYTH_PID,
2519
- MESSAGE_BUFFER_PID,
2517
+ pythnet, MESSAGE_BUFFER_PID,
2520
2518
},
2521
2519
solana_sdk::borsh::BorshSerialize,
2522
2520
};
@@ -2527,7 +2525,7 @@ impl Bank {
2527
2525
// Find all accounts owned by the Message Buffer program using get_program_accounts, and
2528
2526
// extract the account data.
2529
2527
2530
- let message_buffer_pid = Self:: env_pubkey_or(
2528
+ let message_buffer_pid = self. env_pubkey_or(
2531
2529
"MESSAGE_BUFFER_PID",
2532
2530
Pubkey::new_from_array(MESSAGE_BUFFER_PID),
2533
2531
)?;
@@ -2536,14 +2534,15 @@ impl Bank {
2536
2534
.get_program_accounts(&message_buffer_pid, &ScanConfig::new(true))
2537
2535
.map_err(|_| AccumulatorUpdateError::GetProgramAccounts)?;
2538
2536
2537
+ let preimage = b"account:MessageBuffer";
2538
+ let mut expected_sighash = [0u8; 8];
2539
+ expected_sighash.copy_from_slice(&hashv(&[preimage]).to_bytes()[..8]);
2540
+
2539
2541
// Filter accounts that don't match the Anchor sighash.
2540
2542
let accounts = accounts.iter().filter(|(_, account)| {
2541
2543
// Remove accounts that do not start with the expected Anchor sighash.
2542
- let preimage = b"account:MessageBuffer";
2543
2544
let mut sighash = [0u8; 8];
2544
- let mut expected_sighash = [0u8; 8];
2545
2545
sighash.copy_from_slice(&account.data()[..8]);
2546
- expected_sighash.copy_from_slice(&hashv(&[preimage]).to_bytes()[..8]);
2547
2546
sighash == expected_sighash
2548
2547
});
2549
2548
@@ -2559,15 +2558,17 @@ impl Bank {
2559
2558
let header_len = cursor.read_u16::<LittleEndian>()?;
2560
2559
let mut header_begin = header_len;
2561
2560
let mut inputs = Vec::new();
2561
+ let mut cur_end_offsets_idx: usize = 0;
2562
2562
while let Some(end) = cursor.read_u16::<LittleEndian>().ok() {
2563
- if end == 0 {
2563
+ if end == 0 || cur_end_offsets_idx == (u8::MAX as usize) {
2564
2564
break;
2565
2565
}
2566
2566
2567
2567
let end_offset = header_len + end;
2568
2568
let accumulator_input_data = &data[header_begin as usize..end_offset as usize];
2569
2569
inputs.push(accumulator_input_data);
2570
2570
header_begin = end_offset;
2571
+ cur_end_offsets_idx += 1;
2571
2572
}
2572
2573
2573
2574
Ok(inputs)
@@ -2578,7 +2579,7 @@ impl Bank {
2578
2579
.sorted_unstable()
2579
2580
.dedup();
2580
2581
2581
- let pyth_pid = Self:: env_pubkey_or("PYTH_PID", Pubkey::new_from_array(pythnet::PYTH_PID))?;
2582
+ let pyth_pid = self. env_pubkey_or("PYTH_PID", Pubkey::new_from_array(pythnet::PYTH_PID))?;
2582
2583
2583
2584
// We now generate a Proof PDA (Owned by the System Program) to store the resulting Proof
2584
2585
// Set. The derivation includes the ring buffer index to simulate a ring buffer in order
@@ -2593,7 +2594,11 @@ impl Bank {
2593
2594
);
2594
2595
2595
2596
let accumulator_data = {
2596
- let data = accounts.clone().collect::<Vec<_>>().try_to_vec()?;
2597
+ let mut data = vec![];
2598
+ let acc_state_magic = &mut b"PAS1".to_vec();
2599
+ let accounts_data = &mut accounts.clone().collect::<Vec<_>>().try_to_vec()?;
2600
+ data.append(acc_state_magic);
2601
+ data.append(accounts_data);
2597
2602
let owner = solana_sdk::system_program::id();
2598
2603
let balance = self.get_minimum_balance_for_rent_exemption(data.len());
2599
2604
let mut account = AccountSharedData::new(balance, data.len(), &owner);
@@ -2625,16 +2630,16 @@ impl Bank {
2625
2630
) -> std::result::Result<(), AccumulatorUpdateError> {
2626
2631
use {
2627
2632
pythnet_sdk::{
2628
- pythnet::{ACCUMULATOR_SEQUENCE_ADDR, WORMHOLE_PID} ,
2633
+ pythnet,
2629
2634
wormhole::{AccumulatorSequenceTracker, MessageData, PostedMessageUnreliableData},
2630
2635
ACCUMULATOR_EMITTER_ADDRESS,
2631
2636
},
2632
2637
solana_sdk::borsh::BorshSerialize,
2633
2638
};
2634
2639
2635
- let accumulator_sequence_addr = Self:: env_pubkey_or(
2640
+ let accumulator_sequence_addr = self. env_pubkey_or(
2636
2641
"ACCUMULATOR_SEQUENCE_ADDR",
2637
- Pubkey::new_from_array(ACCUMULATOR_SEQUENCE_ADDR),
2642
+ Pubkey::new_from_array(pythnet:: ACCUMULATOR_SEQUENCE_ADDR),
2638
2643
)?;
2639
2644
2640
2645
// Wormhole uses a Sequence account that is incremented each time a message is posted. As
@@ -2668,8 +2673,10 @@ impl Bank {
2668
2673
};
2669
2674
2670
2675
info!("msg_data.message: {:?}", message.message);
2671
- let wormhole_pid =
2672
- Self::env_pubkey_or("WORMHOLE_PID", Pubkey::new_from_array(WORMHOLE_PID))?;
2676
+ let wormhole_pid = self.env_pubkey_or(
2677
+ "WORMHOLE_PID",
2678
+ Pubkey::new_from_array(pythnet::WORMHOLE_PID),
2679
+ )?;
2673
2680
2674
2681
// Now we can bump and write the Sequence account.
2675
2682
sequence.sequence += 1;
@@ -2710,7 +2717,10 @@ impl Bank {
2710
2717
Ok(())
2711
2718
}
2712
2719
2720
+ /// Read the pubkey from the environment variable `var` or return `default`
2721
+ /// if the variable is not set.
2713
2722
fn env_pubkey_or(
2723
+ &self,
2714
2724
var: &str,
2715
2725
default: Pubkey,
2716
2726
) -> std::result::Result<Pubkey, AccumulatorUpdateError> {
0 commit comments