Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent false blockheight exceedence errors when transaction confirmations are aborted #3353

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-bananas-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@solana/transaction-confirmation': patch
---

Fixed a bug that could result in the transaction confirmer claiming that the blockheight had been exceeded, when the fact of the matter was that the confirmation was aborted by an `AbortSignal`
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,55 @@ describe('createBlockHeightExceedencePromiseFactory', () => {
}),
).rejects.toThrow('o no');
});
it('throws if started aborted', async () => {
expect.assertions(1);
const abortController = new AbortController();
abortController.abort();
await expect(
getBlockHeightExceedencePromise({
abortSignal: abortController.signal,
lastValidBlockHeight: 100n,
}),
).rejects.toThrow(/operation was aborted/);
});
it('throws if aborted while waiting for the epoch info', async () => {
expect.assertions(1);
const abortController = new AbortController();
let resolveEpochInfo!: (value: { absoluteSlot: bigint; blockHeight: bigint }) => void;
const epochInfoPromise = new Promise(r => {
resolveEpochInfo = r;
});
getEpochInfoRequestSender.mockReturnValue(epochInfoPromise);
const blockHeightExceedencePromise = getBlockHeightExceedencePromise({
abortSignal: abortController.signal,
lastValidBlockHeight: 100n,
});
await jest.runAllTimersAsync();
abortController.abort();
resolveEpochInfo({ absoluteSlot: 101n, blockHeight: 101n });
await expect(blockHeightExceedencePromise).rejects.toThrow(/operation was aborted/);
});
it('throws if aborted while the slot subscription is working', async () => {
expect.assertions(1);
const abortController = new AbortController();
let resolveSlotSubscription!: (value: { slot: bigint }) => void;
const slotSubscriptionReturnPromise = new Promise(r => {
resolveSlotSubscription = r;
});
getEpochInfoRequestSender.mockResolvedValue({ absoluteSlot: 100n, blockHeight: 100n });
slotNotificationsGenerator.mockImplementation(
// eslint-disable-next-line require-yield
async function* () {
await slotSubscriptionReturnPromise;
},
);
const blockHeightExceedencePromise = getBlockHeightExceedencePromise({
abortSignal: abortController.signal,
lastValidBlockHeight: 100n,
});
await jest.runAllTimersAsync();
abortController.abort();
resolveSlotSubscription({ slot: 101n });
await expect(blockHeightExceedencePromise).rejects.toThrow(/operation was aborted/);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export function createBlockHeightExceedencePromiseFactory<
abortSignal: callerAbortSignal,
commitment,
lastValidBlockHeight,
}) {
}): Promise<never> {
callerAbortSignal.throwIfAborted();
const abortController = new AbortController();
const handleAbort = () => {
abortController.abort();
Expand All @@ -57,6 +58,7 @@ export function createBlockHeightExceedencePromiseFactory<
rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal }),
getBlockHeightAndDifferenceBetweenSlotHeightAndBlockHeight(),
]);
callerAbortSignal.throwIfAborted();
let currentBlockHeight = initialBlockHeight;
if (currentBlockHeight <= lastValidBlockHeight) {
let lastKnownDifferenceBetweenSlotHeightAndBlockHeight = differenceBetweenSlotHeightAndBlockHeight;
Expand All @@ -83,6 +85,7 @@ export function createBlockHeightExceedencePromiseFactory<
}
}
}
callerAbortSignal.throwIfAborted();
throw new SolanaError(SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED, {
currentBlockHeight,
lastValidBlockHeight,
Expand Down