From 56509bdf6dcbeddf62123c7aff29df00dd80df24 Mon Sep 17 00:00:00 2001 From: Steven Luscher Date: Tue, 15 Oct 2024 17:44:11 +0000 Subject: [PATCH] Fail the transaction loop when the blockhash expires --- ping-thing-client.mjs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ping-thing-client.mjs b/ping-thing-client.mjs index d774d28..4334e50 100644 --- a/ping-thing-client.mjs +++ b/ping-thing-client.mjs @@ -11,6 +11,7 @@ import { isSolanaError, getSignatureFromTransaction, sendTransactionWithoutConfirmingFactory, + SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED, // Address, } from "@solana/web3.js"; import dotenv from "dotenv"; @@ -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(); @@ -63,6 +64,10 @@ const mConfirmRecentSignature = createRecentSignatureConfirmationPromiseFactory( rpc, rpcSubscriptions, }); +const mThrowOnBlockheightExceedence = createBlockHeightExceedencePromiseFactory({ + rpc, + rpcSubscriptions, +}); const mSendTransactionWithoutConfirming = sendTransactionWithoutConfirmingFactory({ rpc }); async function pingThing() { @@ -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}`); @@ -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.` );