Skip to content

Commit 6c9440f

Browse files
committed
Cover setComputeUnitLimit already set
1 parent 1d9a85a commit 6c9440f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/lib/transaction.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,20 @@ export const getSimulationComputeUnits = async (
4343
lookupTables: Array<AddressLookupTableAccount> | [],
4444
commitment: Commitment = "confirmed",
4545
): Promise<number | null> => {
46-
const testInstructions = [
47-
// Set an arbitrarily high number in simulation
48-
// so we can be sure the transaction will succeed
49-
// and get the real compute units used
50-
ComputeBudgetProgram.setComputeUnitLimit({ units: 1_400_000 }),
51-
...instructions,
52-
];
46+
const hasComputeInstructions = instructions.some(
47+
(ix: TransactionInstruction) =>
48+
ix.programId.equals(ComputeBudgetProgram.programId),
49+
);
50+
51+
const testInstructions = hasComputeInstructions
52+
? instructions
53+
: [
54+
// Set an arbitrarily high number in simulation
55+
// so we can be sure the transaction will succeed
56+
// and get the real compute units used
57+
ComputeBudgetProgram.setComputeUnitLimit({ units: 1_400_000 }),
58+
...instructions,
59+
];
5360

5461
const testTransaction = new VersionedTransaction(
5562
new TransactionMessage({

0 commit comments

Comments
 (0)