From 16695fea8a0a8d80179c3fbe68120b34de076659 Mon Sep 17 00:00:00 2001 From: alvarius Date: Mon, 22 Apr 2024 13:42:52 +0100 Subject: [PATCH] fix(store-sync): await fetchAndStoreLogs (#2702) --- .changeset/few-glasses-rhyme.md | 5 +++++ packages/store-sync/src/createStoreSync.ts | 7 +------ 2 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 .changeset/few-glasses-rhyme.md diff --git a/.changeset/few-glasses-rhyme.md b/.changeset/few-glasses-rhyme.md new file mode 100644 index 0000000000..e01311a191 --- /dev/null +++ b/.changeset/few-glasses-rhyme.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/store-sync": patch +--- + +Partially revert [#2665](https://github.com/latticexyz/mud/pull/2665) to guarantee logs are stored in order. diff --git a/packages/store-sync/src/createStoreSync.ts b/packages/store-sync/src/createStoreSync.ts index 07c8279ab1..c14f6e68fa 100644 --- a/packages/store-sync/src/createStoreSync.ts +++ b/packages/store-sync/src/createStoreSync.ts @@ -26,7 +26,6 @@ import { shareReplay, combineLatest, scan, - identity, mergeMap, } from "rxjs"; import { debug as parentDebug } from "./debug"; @@ -199,9 +198,7 @@ export async function createStoreSync( startBlock = range.startBlock; endBlock = range.endBlock; }), - // We use `map` instead of `concatMap` here to send the fetch request immediately when a new block range appears, - // instead of sending the next request only when the previous one completed. - map((range) => { + concatMap((range) => { const storedBlocks = fetchAndStoreLogs({ publicClient, address, @@ -217,8 +214,6 @@ export async function createStoreSync( return from(storedBlocks); }), - // `concatMap` turns the stream of promises into their awaited values - concatMap(identity), tap(({ blockNumber, logs }) => { debug("stored", logs.length, "logs for block", blockNumber); lastBlockNumberProcessed = blockNumber;