Skip to content

Commit

Permalink
Fail the transaction loop when the blockhash expires
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher committed Oct 23, 2024
1 parent e8d53b4 commit 4acf40b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ping-thing-client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
isSolanaError,
getSignatureFromTransaction,
sendTransactionWithoutConfirmingFactory,
SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED,
// Address,
} from "@solana/web3.js";
import dotenv from "dotenv";
Expand All @@ -23,7 +24,7 @@ import { rpc, rpcSubscriptions } from "./utils/rpc.mjs";
import { getNextSlot } from "./utils/slot.mjs";
import { setMaxListeners } from "events";
import axios from "axios";
import { createRecentSignatureConfirmationPromiseFactory } from "@solana/transaction-confirmation";
import { createBlockHeightExceedencePromiseFactory, createRecentSignatureConfirmationPromiseFactory } from "@solana/transaction-confirmation";
import { safeRace } from '@solana/promises';

dotenv.config();
Expand Down Expand Up @@ -63,6 +64,10 @@ const mConfirmRecentSignature = createRecentSignatureConfirmationPromiseFactory(
rpc,
rpcSubscriptions,
});
const mThrowOnBlockheightExceedence = createBlockHeightExceedencePromiseFactory({
rpc,
rpcSubscriptions,
});
const mSendTransactionWithoutConfirming = sendTransactionWithoutConfirmingFactory({ rpc });

async function pingThing() {
Expand Down Expand Up @@ -157,6 +162,11 @@ async function pingThing() {
commitment: COMMITMENT_LEVEL,
signature,
}),
mThrowOnBlockheightExceedence({
abortSignal: pingAbortController.signal,
commitment: COMMITMENT_LEVEL,
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
}),
sendLoopPromise,
]);
console.log(`Confirmed tx ${signature}`);
Expand All @@ -170,7 +180,7 @@ async function pingThing() {

// If the transaction expired on the chain. Make a log entry and send
// to VA. Otherwise log and loop.
if (e.name === "TransactionExpiredBlockheightExceededError") {
if (isSolanaError(e, SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED)) {
console.log(
`ERROR: Blockhash expired/block height exceeded. TX failure sent to VA.`
);
Expand Down

0 comments on commit 4acf40b

Please sign in to comment.