Explorar el Código

fix:solana utils single tx (#1743)

* add fix

* bump

* improve comment
guibescos hace 1 año
padre
commit
3cb45ec136

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

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/solana-utils",
-  "version": "0.4.1",
+  "version": "0.4.2",
   "description": "Utility functions for Solana",
   "homepage": "https://pyth.network",
   "main": "lib/index.js",

+ 29 - 2
target_chains/solana/sdk/js/solana_utils/src/transaction.ts

@@ -259,11 +259,25 @@ export class TransactionBuilder {
           );
         }
 
+        // This handles an edge case where a single instruction is too big and therefore needs to be by itself without any compute budget instructions or jito tips
+        const instructionsToSend: TransactionInstruction[] = [];
+        for (const instruction of instructionsWithComputeBudget) {
+          const sizeWithInstruction = getSizeOfTransaction(
+            [...instructionsToSend, instruction],
+            true,
+            this.addressLookupTable
+          );
+          if (sizeWithInstruction > PACKET_DATA_SIZE) {
+            break;
+          }
+          instructionsToSend.push(instruction);
+        }
+
         return {
           tx: new VersionedTransaction(
             new TransactionMessage({
               recentBlockhash: blockhash,
-              instructions: instructionsWithComputeBudget,
+              instructions: instructionsToSend,
               payerKey: this.payer,
             }).compileToV0Message(
               this.addressLookupTable ? [this.addressLookupTable] : []
@@ -310,8 +324,21 @@ export class TransactionBuilder {
           );
         }
 
+        // This handles an edge case where a single instruction is too big and therefore needs to be by itself without any compute budget instructions or jito tips
+        const instructionsToSend: TransactionInstruction[] = [];
+        for (const instruction of instructionsWithComputeBudget) {
+          const sizeWithInstruction = getSizeOfTransaction(
+            [...instructionsToSend, instruction],
+            false
+          );
+          if (sizeWithInstruction > PACKET_DATA_SIZE) {
+            break;
+          }
+          instructionsToSend.push(instruction);
+        }
+
         return {
-          tx: new Transaction().add(...instructionsWithComputeBudget),
+          tx: new Transaction().add(...instructionsToSend),
           signers: signers,
         };
       }