Skip to content

Commit

Permalink
sdk: fastSingleTxSender uses finalized commitment by default
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Dec 27, 2023
1 parent 7109840 commit 0d0fb6c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sdk/src/tx/fastSingleTxSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TransactionMessage,
TransactionInstruction,
AddressLookupTableAccount,
Commitment,
} from '@solana/web3.js';
import { AnchorProvider } from '@coral-xyz/anchor';
import { IWallet } from '../types';
Expand All @@ -27,6 +28,7 @@ export class FastSingleTxSender extends BaseTxSender {
timoutCount = 0;
recentBlockhash: string;
skipConfirmation: boolean;
blockhashCommitment: Commitment;

public constructor({
connection,
Expand All @@ -36,6 +38,7 @@ export class FastSingleTxSender extends BaseTxSender {
blockhashRefreshInterval = DEFAULT_BLOCKHASH_REFRESH,
additionalConnections = new Array<Connection>(),
skipConfirmation = false,
blockhashCommitment = 'finalized',
}: {
connection: Connection;
wallet: IWallet;
Expand All @@ -44,6 +47,7 @@ export class FastSingleTxSender extends BaseTxSender {
blockhashRefreshInterval?: number;
additionalConnections?;
skipConfirmation?: boolean;
blockhashCommitment?: Commitment;
}) {
super({ connection, wallet, opts, timeout, additionalConnections });
this.connection = connection;
Expand All @@ -53,14 +57,15 @@ export class FastSingleTxSender extends BaseTxSender {
this.blockhashRefreshInterval = blockhashRefreshInterval;
this.additionalConnections = additionalConnections;
this.skipConfirmation = skipConfirmation;
this.blockhashCommitment = blockhashCommitment;
this.startBlockhashRefreshLoop();
}

startBlockhashRefreshLoop(): void {
setInterval(async () => {
try {
this.recentBlockhash = (
await this.connection.getLatestBlockhash(this.opts)
await this.connection.getLatestBlockhash(this.blockhashCommitment)
).blockhash;
} catch (e) {
console.error('Error in startBlockhashRefreshLoop: ', e);
Expand All @@ -71,13 +76,13 @@ export class FastSingleTxSender extends BaseTxSender {
async prepareTx(
tx: Transaction,
additionalSigners: Array<Signer>,
opts: ConfirmOptions
_opts: ConfirmOptions
): Promise<Transaction> {
tx.feePayer = this.wallet.publicKey;

tx.recentBlockhash =
this.recentBlockhash ??
(await this.connection.getLatestBlockhash(opts.preflightCommitment))
(await this.connection.getLatestBlockhash(this.blockhashCommitment))
.blockhash;

additionalSigners
Expand Down

0 comments on commit 0d0fb6c

Please sign in to comment.