diff --git a/src/svm/transactionUtils.ts b/src/svm/transactionUtils.ts index 94f3a1030..1fb43e442 100644 --- a/src/svm/transactionUtils.ts +++ b/src/svm/transactionUtils.ts @@ -39,7 +39,8 @@ export async function sendTransactionWithLookupTable( // Submit the ALT creation transaction await web3.sendAndConfirmTransaction(connection, new web3.Transaction().add(lookupTableInstruction), [sender], { - skipPreflight: true, // Avoids recent slot mismatch in simulation. + commitment: "confirmed", + skipPreflight: true, }); // Extend the ALT with all accounts making sure not to exceed the maximum number of accounts per transaction. @@ -52,12 +53,16 @@ export async function sendTransactionWithLookupTable( }); await web3.sendAndConfirmTransaction(connection, new web3.Transaction().add(extendInstruction), [sender], { - skipPreflight: true, // Avoids recent slot mismatch in simulation. + commitment: "confirmed", + skipPreflight: true, }); } - // Avoids invalid ALT index as ALT might not be active yet on the following tx. - await new Promise((resolve) => setTimeout(resolve, 1000)); + // Wait for slot to advance. LUTs only active after slot advance. + const initialSlot = await connection.getSlot(); + while ((await connection.getSlot()) === initialSlot) { + await new Promise((resolve) => setTimeout(resolve, 50)); + } // Fetch the AddressLookupTableAccount const lookupTableAccount = (await connection.getAddressLookupTable(lookupTableAddress)).value; @@ -76,5 +81,12 @@ export async function sendTransactionWithLookupTable( versionedTx.sign([sender]); const txSignature = await connection.sendTransaction(versionedTx); + // Confirm the versioned transaction + let block = await connection.getLatestBlockhash(); + await connection.confirmTransaction( + { signature: txSignature, blockhash: block.blockhash, lastValidBlockHeight: block.lastValidBlockHeight }, + "confirmed" + ); + return { txSignature, lookupTableAddress }; }