From b45e1765d9423749feadc8de629185a1781ab3e5 Mon Sep 17 00:00:00 2001 From: Tyler Shipe Date: Mon, 6 Dec 2021 14:07:31 -0500 Subject: [PATCH] passing null for timeout will bypass tx confirmation and sending retries --- src/client.ts | 30 ++++++++++++++++++++---------- src/keeper.ts | 4 +--- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/client.ts b/src/client.ts index 3942a30e..f0c335ce 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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 { @@ -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) { @@ -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); } /** diff --git a/src/keeper.ts b/src/keeper.ts index d65fad0b..f7141d7a 100644 --- a/src/keeper.ts +++ b/src/keeper.ts @@ -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, @@ -232,7 +230,7 @@ async function processConsumeEvents( }, ); - await Promise.all(promises); + Promise.all(promises); } finally { setTimeout( processConsumeEvents,