diff --git a/sdk/src/tx/fastSingleTxSender.ts b/sdk/src/tx/fastSingleTxSender.ts index 1efa2727b..8567f33e3 100644 --- a/sdk/src/tx/fastSingleTxSender.ts +++ b/sdk/src/tx/fastSingleTxSender.ts @@ -15,8 +15,7 @@ import { IWallet } from '../types'; import { BaseTxSender } from './baseTxSender'; const DEFAULT_TIMEOUT = 35000; -const DEFAULT_BLOCKHASH_REFRESH = 500; -const MAX_BLOCKHASH_QUEUE_LENGTH = 100; +const DEFAULT_BLOCKHASH_REFRESH = 10000; export class FastSingleTxSender extends BaseTxSender { connection: Connection; @@ -26,7 +25,7 @@ export class FastSingleTxSender extends BaseTxSender { blockhashRefreshInterval: number; additionalConnections: Connection[]; timoutCount = 0; - blockhashQueue: string[] = []; + recentBlockhash: string; skipConfirmation: boolean; public constructor({ @@ -60,25 +59,15 @@ export class FastSingleTxSender extends BaseTxSender { startBlockhashRefreshLoop(): void { setInterval(async () => { try { - const blockhash = (await this.connection.getLatestBlockhash(this.opts)) - .blockhash; - this.addBlockhashToQueue(blockhash); + this.recentBlockhash = ( + await this.connection.getLatestBlockhash(this.opts) + ).blockhash; } catch (e) { console.error('Error in startBlockhashRefreshLoop: ', e); } }, this.blockhashRefreshInterval); } - addBlockhashToQueue(blockhash: string): void { - if (blockhash !== this.blockhashQueue[0]) { - this.blockhashQueue.push(blockhash); - return; - } - if (this.blockhashQueue.length > MAX_BLOCKHASH_QUEUE_LENGTH) { - this.blockhashQueue.shift(); - } - } - async prepareTx( tx: Transaction, additionalSigners: Array, @@ -87,7 +76,7 @@ export class FastSingleTxSender extends BaseTxSender { tx.feePayer = this.wallet.publicKey; tx.recentBlockhash = - this.blockhashQueue.shift() ?? + this.recentBlockhash ?? (await this.connection.getLatestBlockhash(opts.preflightCommitment)) .blockhash; @@ -118,7 +107,7 @@ export class FastSingleTxSender extends BaseTxSender { const message = new TransactionMessage({ payerKey: this.wallet.publicKey, recentBlockhash: - this.blockhashQueue.shift() ?? + this.recentBlockhash ?? (await this.connection.getLatestBlockhash(opts.preflightCommitment)) .blockhash, instructions: ixs,