Skip to content

Commit

Permalink
passing null for timeout will bypass tx confirmation and sending retries
Browse files Browse the repository at this point in the history
  • Loading branch information
tlrjs committed Dec 6, 2021
1 parent f0dab6c commit b45e176
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
30 changes: 20 additions & 10 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,20 @@ export class MangoClient {
}

// TODO - switch Account to Keypair and switch off setSigners due to deprecated
/**
* Send a transaction using the Solana Web3.js connection on the mango client
*
* @param transaction
* @param payer
* @param additionalSigners
* @param timeout Retries sending the transaction and trying to confirm it until the given timeout. Defaults to 30000ms. Passing null will disable the transaction confirmation check and always return success.
* @param postSignTxCallback Callback to be called after the transaction is signed but before it's sent.
*/
async sendTransaction(
transaction: Transaction,
payer: Account | WalletAdapter | Keypair,
additionalSigners: Account[],
timeout = 30000,
// @ts-ignore
timeout: number | null = 30000,
confirmLevel: TransactionConfirmationStatus = 'processed',
postSignTxCallback?: any,
): Promise<TransactionSignature> {
Expand All @@ -231,16 +239,18 @@ export class MangoClient {
{ skipPreflight: true },
);

// console.log(
// 'Started awaiting confirmation for',
// txid,
// 'size:',
// rawTransaction.length,
// );
if (!timeout) return txid;

console.log(
'Started awaiting confirmation for',
txid,
'size:',
rawTransaction.length,
);

let done = false;
let retrySleep = 1500;

let retrySleep = 1500;
(async () => {
// TODO - make sure this works well on mainnet
while (!done && getUnixTs() - startTime < timeout / 1000) {
Expand Down Expand Up @@ -1090,7 +1100,7 @@ export class MangoClient {
const transaction = new Transaction();
transaction.add(consumeEventsInstruction);

return await this.sendTransaction(transaction, payer, [], 15000);
return await this.sendTransaction(transaction, payer, [], null);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/keeper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ async function processConsumeEvents(
perpMarkets: PerpMarket[],
) {
try {
// console.log('processConsumeEvents');

const eventQueuePks = perpMarkets.map((mkt) => mkt.eventQueue);
const eventQueueAccts = await getMultipleAccounts(
connection,
Expand Down Expand Up @@ -232,7 +230,7 @@ async function processConsumeEvents(
},
);

await Promise.all(promises);
Promise.all(promises);
} finally {
setTimeout(
processConsumeEvents,
Expand Down

0 comments on commit b45e176

Please sign in to comment.