From 3cb45ec136deb68d2e11222de7c35ccc0f7a9169 Mon Sep 17 00:00:00 2001 From: guibescos <59208140+guibescos@users.noreply.github.com> Date: Fri, 28 Jun 2024 08:51:03 +0100 Subject: [PATCH] fix:solana utils single tx (#1743) * add fix * bump * improve comment --- .../solana/sdk/js/solana_utils/package.json | 2 +- .../sdk/js/solana_utils/src/transaction.ts | 31 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/target_chains/solana/sdk/js/solana_utils/package.json b/target_chains/solana/sdk/js/solana_utils/package.json index 729ae32397..7e9dc50174 100644 --- a/target_chains/solana/sdk/js/solana_utils/package.json +++ b/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", diff --git a/target_chains/solana/sdk/js/solana_utils/src/transaction.ts b/target_chains/solana/sdk/js/solana_utils/src/transaction.ts index b38f2d8e89..ba3340d7b8 100644 --- a/target_chains/solana/sdk/js/solana_utils/src/transaction.ts +++ b/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, }; }