浏览代码

fix(pyth-solana-receiver): Only split VAA when needed (#2875)

* feat(governance,xc_admin): add fogo testnet

* fix(pyth_solana_receiver): improve VAA split handling
Tejas Badadare 4 月之前
父节点
当前提交
fb000d4894

+ 1 - 1
target_chains/solana/sdk/js/pyth_solana_receiver/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/pyth-solana-receiver",
-  "version": "0.10.1",
+  "version": "0.10.2",
   "description": "Pyth solana receiver SDK",
   "homepage": "https://pyth.network",
   "main": "lib/index.js",

+ 33 - 29
target_chains/solana/sdk/js/pyth_solana_receiver/src/vaa.ts

@@ -133,35 +133,39 @@ async function generateVaaInstructionGroups(
 
   // Second write and verify instructions
   const writeSecondPartAndVerifyInstructions: InstructionWithEphemeralSigners[] =
-    [
-      {
-        instruction: await wormhole.methods
-          .writeEncodedVaa({
-            index: VAA_SPLIT_INDEX,
-            data: vaa.subarray(VAA_SPLIT_INDEX),
-          })
-          .accounts({
-            draftVaa: encodedVaaKeypair.publicKey,
-          })
-          .instruction(),
-        signers: [],
-        computeUnits: WRITE_ENCODED_VAA_COMPUTE_BUDGET,
-      },
-      {
-        instruction: await wormhole.methods
-          .verifyEncodedVaaV1()
-          .accounts({
-            guardianSet: getGuardianSetPda(
-              getGuardianSetIndex(vaa),
-              wormhole.programId,
-            ),
-            draftVaa: encodedVaaKeypair.publicKey,
-          })
-          .instruction(),
-        signers: [],
-        computeUnits: VERIFY_ENCODED_VAA_COMPUTE_BUDGET,
-      },
-    ];
+    [];
+
+  // The second write instruction is only needed if there are more bytes past the split index in the VAA
+  if (vaa.length > VAA_SPLIT_INDEX) {
+    writeSecondPartAndVerifyInstructions.push({
+      instruction: await wormhole.methods
+        .writeEncodedVaa({
+          index: VAA_SPLIT_INDEX,
+          data: vaa.subarray(VAA_SPLIT_INDEX),
+        })
+        .accounts({
+          draftVaa: encodedVaaKeypair.publicKey,
+        })
+        .instruction(),
+      signers: [],
+      computeUnits: WRITE_ENCODED_VAA_COMPUTE_BUDGET,
+    });
+  }
+
+  writeSecondPartAndVerifyInstructions.push({
+    instruction: await wormhole.methods
+      .verifyEncodedVaaV1()
+      .accounts({
+        guardianSet: getGuardianSetPda(
+          getGuardianSetIndex(vaa),
+          wormhole.programId,
+        ),
+        draftVaa: encodedVaaKeypair.publicKey,
+      })
+      .instruction(),
+    signers: [],
+    computeUnits: VERIFY_ENCODED_VAA_COMPUTE_BUDGET,
+  });
 
   // Close instructions
   const closeInstructions: InstructionWithEphemeralSigners[] = [