From 1fbad5e3bae56e78b723bef817ab6d9b53097bff Mon Sep 17 00:00:00 2001 From: Chris Maree Date: Thu, 2 Jan 2025 11:16:27 +0100 Subject: [PATCH] fix: address LUT issues on tests (#811) * WIP Signed-off-by: Chris Maree * Discard changes to src/svm/instructionParamsUtils.ts * WIP Signed-off-by: Chris Maree --------- Signed-off-by: Chris Maree --- src/svm/transactionUtils.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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 }; }