Skip to content

Commit

Permalink
fix: address LUT issues on tests (#811)
Browse files Browse the repository at this point in the history
* WIP

Signed-off-by: Chris Maree <[email protected]>

* Discard changes to src/svm/instructionParamsUtils.ts

* WIP

Signed-off-by: Chris Maree <[email protected]>

---------

Signed-off-by: Chris Maree <[email protected]>
  • Loading branch information
chrismaree authored Jan 2, 2025
1 parent 61d5e83 commit 1fbad5e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/svm/transactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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 };
}

0 comments on commit 1fbad5e

Please sign in to comment.