Skip to content

Commit

Permalink
fix:solana utils single tx (#1743)
Browse files Browse the repository at this point in the history
* add fix

* bump

* improve comment
  • Loading branch information
guibescos authored Jun 28, 2024
1 parent 2c2bfe3 commit 3cb45ec
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion target_chains/solana/sdk/js/solana_utils/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
31 changes: 29 additions & 2 deletions target_chains/solana/sdk/js/solana_utils/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] : []
Expand Down Expand Up @@ -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,
};
}
Expand Down

0 comments on commit 3cb45ec

Please sign in to comment.