Skip to content

Commit a36eb8d

Browse files
fix: document VAA split handling in pyth-solana-receiver-cli
Co-Authored-By: Tejas Badadare <[email protected]>
1 parent f890933 commit a36eb8d

File tree

1 file changed

+32
-21
lines changed
  • target_chains/solana/cli/src

1 file changed

+32
-21
lines changed

target_chains/solana/cli/src/main.rs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ pub fn process_write_encoded_vaa_and_post_twap_update(
483483
)?;
484484

485485
// Transaction 3: Write remaining VAA data and verify both VAAs
486-
let mut verify_instructions = vec![ComputeBudgetInstruction::set_compute_unit_limit(400_000)];
486+
let mut verify_instructions = vec![ComputeBudgetInstruction::set_compute_unit_limit(1_200_000)];
487487
verify_instructions.extend(write_remaining_data_and_verify_vaa_ixs(
488488
&payer.pubkey(),
489489
start_vaa,
@@ -523,6 +523,8 @@ pub fn process_write_encoded_vaa_and_post_twap_update(
523523
}
524524

525525
/// Creates instructions to initialize an encoded VAA account and write the first part of the VAA data
526+
/// The VAA data is split at VAA_SPLIT_INDEX (755 bytes) to ensure the create+init+write instructions
527+
/// can fit in a single Solana transaction. This is a transaction size optimization, not a VAA structure requirement.
526528
pub fn init_encoded_vaa_and_write_initial_data_ixs(
527529
payer: &Pubkey,
528530
vaa: &[u8],
@@ -563,7 +565,7 @@ pub fn init_encoded_vaa_and_write_initial_data_ixs(
563565
data: wormhole_core_bridge_solana::instruction::WriteEncodedVaa {
564566
args: WriteEncodedVaaArgs {
565567
index: 0,
566-
data: vaa[..VAA_SPLIT_INDEX].to_vec(),
568+
data: vaa[..std::cmp::min(VAA_SPLIT_INDEX, vaa.len())].to_vec(),
567569
},
568570
}
569571
.data(),
@@ -577,33 +579,44 @@ pub fn init_encoded_vaa_and_write_initial_data_ixs(
577579
}
578580

579581
/// Creates instructions to write remaining VAA data and verify the VAA
582+
/// If the VAA data is longer than VAA_SPLIT_INDEX, the remaining data is written in a separate instruction
583+
/// before verification. This ensures proper handling of large VAAs while respecting Solana transaction size limits.
584+
/// The verification step requires the complete VAA data to be written before it can succeed.
580585
pub fn write_remaining_data_and_verify_vaa_ixs(
581586
payer: &Pubkey,
582587
vaa: &[u8],
583588
encoded_vaa_keypair: &Pubkey,
584589
wormhole: Pubkey,
585590
) -> Result<Vec<Instruction>> {
586-
let write_encoded_vaa_accounts = wormhole_core_bridge_solana::accounts::WriteEncodedVaa {
587-
write_authority: *payer,
588-
draft_vaa: *encoded_vaa_keypair,
589-
}
590-
.to_account_metas(None);
591+
// Only write remaining data if there is data after VAA_SPLIT_INDEX
592+
let mut instructions = Vec::new();
591593

592-
let write_encoded_vaa_instruction = Instruction {
593-
program_id: wormhole,
594-
accounts: write_encoded_vaa_accounts,
595-
data: wormhole_core_bridge_solana::instruction::WriteEncodedVaa {
596-
args: WriteEncodedVaaArgs {
597-
index: VAA_SPLIT_INDEX.try_into().unwrap(),
598-
data: vaa[VAA_SPLIT_INDEX..].to_vec(),
599-
},
594+
if vaa.len() > VAA_SPLIT_INDEX {
595+
let write_encoded_vaa_accounts = wormhole_core_bridge_solana::accounts::WriteEncodedVaa {
596+
write_authority: *payer,
597+
draft_vaa: *encoded_vaa_keypair,
600598
}
601-
.data(),
602-
};
599+
.to_account_metas(None);
600+
601+
let write_encoded_vaa_instruction = Instruction {
602+
program_id: wormhole,
603+
accounts: write_encoded_vaa_accounts,
604+
data: wormhole_core_bridge_solana::instruction::WriteEncodedVaa {
605+
args: WriteEncodedVaaArgs {
606+
index: VAA_SPLIT_INDEX.try_into().unwrap(),
607+
data: vaa[VAA_SPLIT_INDEX..].to_vec(),
608+
},
609+
}
610+
.data(),
611+
};
612+
instructions.push(write_encoded_vaa_instruction);
613+
}
603614

615+
// Parse VAA header to get guardian set index
604616
let (header, _): (Header, Body<&RawMessage>) = serde_wormhole::from_slice(vaa).unwrap();
605617
let guardian_set = GuardianSet::key(&wormhole, header.guardian_set_index);
606618

619+
// Add verify instruction
607620
let verify_encoded_vaa_accounts = wormhole_core_bridge_solana::accounts::VerifyEncodedVaaV1 {
608621
guardian_set,
609622
write_authority: *payer,
@@ -616,11 +629,9 @@ pub fn write_remaining_data_and_verify_vaa_ixs(
616629
accounts: verify_encoded_vaa_accounts,
617630
data: wormhole_core_bridge_solana::instruction::VerifyEncodedVaaV1 {}.data(),
618631
};
632+
instructions.push(verify_encoded_vaa_instruction);
619633

620-
Ok(vec![
621-
write_encoded_vaa_instruction,
622-
verify_encoded_vaa_instruction,
623-
])
634+
Ok(instructions)
624635
}
625636

626637
pub fn process_transaction(

0 commit comments

Comments
 (0)