From 2f20ccb53f577c32279fe1e8feca511fc1cfa01f Mon Sep 17 00:00:00 2001 From: CryptoSpaces <39212459+CryptoSpaces@users.noreply.github.com> Date: Sun, 1 Sep 2024 18:49:59 +0200 Subject: [PATCH 1/4] fix(store-sync): improve TransactionReceiptNotFoundError error catching in waitForTransaction (#1833) --- packages/store-sync/src/createStoreSync.ts | 5 +++-- .../src/isViemTransactionReceiptNotFoundError.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 packages/store-sync/src/isViemTransactionReceiptNotFoundError.ts diff --git a/packages/store-sync/src/createStoreSync.ts b/packages/store-sync/src/createStoreSync.ts index a359d8d813..bb61296452 100644 --- a/packages/store-sync/src/createStoreSync.ts +++ b/packages/store-sync/src/createStoreSync.ts @@ -1,5 +1,5 @@ import { storeEventsAbi } from "@latticexyz/store"; -import { Hex, TransactionReceiptNotFoundError } from "viem"; +import { Hex } from "viem"; import { StorageAdapter, StorageAdapterBlock, @@ -34,6 +34,7 @@ import { bigIntMax, chunk, isDefined, waitForIdle } from "@latticexyz/common/uti import { getSnapshot } from "./getSnapshot"; import { fetchAndStoreLogs } from "./fetchAndStoreLogs"; import { Store as StoreConfig } from "@latticexyz/store"; +import { isViemTransactionReceiptNotFoundError } from "@latticexyz/store-sync/isViemTransactionReceiptNotFoundError"; const debug = parentDebug.extend("createStoreSync"); @@ -291,7 +292,7 @@ export async function createStoreSync( return { status, blockNumber, transactionHash }; } } catch (error) { - if (error instanceof TransactionReceiptNotFoundError) { + if (isViemTransactionReceiptNotFoundError(error)) { return; } throw error; diff --git a/packages/store-sync/src/isViemTransactionReceiptNotFoundError.ts b/packages/store-sync/src/isViemTransactionReceiptNotFoundError.ts new file mode 100644 index 0000000000..833a835451 --- /dev/null +++ b/packages/store-sync/src/isViemTransactionReceiptNotFoundError.ts @@ -0,0 +1,16 @@ +import { TransactionReceiptNotFoundErrorType } from "viem"; + +type PartialViemError = Partial; + +export function isViemTransactionReceiptNotFoundError(error: unknown): error is Error & PartialViemError { + if (!(error instanceof Error)) { + return false; + } + + const maybeTransactionReceiptNotFoundErrorType = error as PartialViemError; + + return ( + maybeTransactionReceiptNotFoundErrorType.name === "TransactionReceiptNotFoundError" && + !!maybeTransactionReceiptNotFoundErrorType.version?.match(/Version: viem@\d+\.\d+\.\d+/gi) + ); +} From 93e40b19c4a4c0409b749b721296fd1dfa95a783 Mon Sep 17 00:00:00 2001 From: CryptoSpaces <39212459+CryptoSpaces@users.noreply.github.com> Date: Sun, 1 Sep 2024 19:23:00 +0200 Subject: [PATCH 2/4] fix(store-sync): implement PR feedback (#1833) --- packages/store-sync/src/createStoreSync.ts | 10 ++++++---- .../src/isViemTransactionReceiptNotFoundError.ts | 16 ---------------- 2 files changed, 6 insertions(+), 20 deletions(-) delete mode 100644 packages/store-sync/src/isViemTransactionReceiptNotFoundError.ts diff --git a/packages/store-sync/src/createStoreSync.ts b/packages/store-sync/src/createStoreSync.ts index bb61296452..a7a5ce992a 100644 --- a/packages/store-sync/src/createStoreSync.ts +++ b/packages/store-sync/src/createStoreSync.ts @@ -1,5 +1,5 @@ import { storeEventsAbi } from "@latticexyz/store"; -import { Hex } from "viem"; +import { GetTransactionReceiptErrorType, Hex } from "viem"; import { StorageAdapter, StorageAdapterBlock, @@ -34,7 +34,6 @@ import { bigIntMax, chunk, isDefined, waitForIdle } from "@latticexyz/common/uti import { getSnapshot } from "./getSnapshot"; import { fetchAndStoreLogs } from "./fetchAndStoreLogs"; import { Store as StoreConfig } from "@latticexyz/store"; -import { isViemTransactionReceiptNotFoundError } from "@latticexyz/store-sync/isViemTransactionReceiptNotFoundError"; const debug = parentDebug.extend("createStoreSync"); @@ -291,10 +290,13 @@ export async function createStoreSync( if (lastBlock.blockNumber >= blockNumber) { return { status, blockNumber, transactionHash }; } - } catch (error) { - if (isViemTransactionReceiptNotFoundError(error)) { + } catch (e) { + const error = e as GetTransactionReceiptErrorType; + + if (error.name === "TransactionReceiptNotFoundError") { return; } + throw error; } }), diff --git a/packages/store-sync/src/isViemTransactionReceiptNotFoundError.ts b/packages/store-sync/src/isViemTransactionReceiptNotFoundError.ts deleted file mode 100644 index 833a835451..0000000000 --- a/packages/store-sync/src/isViemTransactionReceiptNotFoundError.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TransactionReceiptNotFoundErrorType } from "viem"; - -type PartialViemError = Partial; - -export function isViemTransactionReceiptNotFoundError(error: unknown): error is Error & PartialViemError { - if (!(error instanceof Error)) { - return false; - } - - const maybeTransactionReceiptNotFoundErrorType = error as PartialViemError; - - return ( - maybeTransactionReceiptNotFoundErrorType.name === "TransactionReceiptNotFoundError" && - !!maybeTransactionReceiptNotFoundErrorType.version?.match(/Version: viem@\d+\.\d+\.\d+/gi) - ); -} From 12c5348a8cecde7eacb69cd56720cf58ec8b32e9 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Sun, 1 Sep 2024 10:45:08 -0700 Subject: [PATCH 3/4] Create funny-hairs-destroy.md --- .changeset/funny-hairs-destroy.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/funny-hairs-destroy.md diff --git a/.changeset/funny-hairs-destroy.md b/.changeset/funny-hairs-destroy.md new file mode 100644 index 0000000000..f956e05b4f --- /dev/null +++ b/.changeset/funny-hairs-destroy.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/store-sync": patch +--- + +Improve error handling of `TransactionReceiptNotFoundError` in `waitForTransaction` when Viem versions aren't aligned. From 05ccab17a0d8515a28f1182a9a5db35a03ebac10 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Sun, 1 Sep 2024 10:45:30 -0700 Subject: [PATCH 4/4] Update .changeset/funny-hairs-destroy.md --- .changeset/funny-hairs-destroy.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/funny-hairs-destroy.md b/.changeset/funny-hairs-destroy.md index f956e05b4f..465ab2b9ef 100644 --- a/.changeset/funny-hairs-destroy.md +++ b/.changeset/funny-hairs-destroy.md @@ -2,4 +2,4 @@ "@latticexyz/store-sync": patch --- -Improve error handling of `TransactionReceiptNotFoundError` in `waitForTransaction` when Viem versions aren't aligned. +Improved error handling of `TransactionReceiptNotFoundError` in `waitForTransaction` when Viem versions aren't aligned.