Skip to content

Commit

Permalink
Revert "sdk: fast tx sender blockhash queue (#755)"
Browse files Browse the repository at this point in the history
This reverts commit 1bf38e9.
  • Loading branch information
crispheaney committed Dec 27, 2023
1 parent 9e78566 commit 9df6b9f
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions sdk/src/tx/fastSingleTxSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +25,7 @@ export class FastSingleTxSender extends BaseTxSender {
blockhashRefreshInterval: number;
additionalConnections: Connection[];
timoutCount = 0;
blockhashQueue: string[] = [];
recentBlockhash: string;
skipConfirmation: boolean;

public constructor({
Expand Down Expand Up @@ -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<Signer>,
Expand All @@ -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;

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9df6b9f

Please sign in to comment.