Skip to content

Commit

Permalink
fix(store-sync): await fetchAndStoreLogs (#2702)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs authored Apr 22, 2024
1 parent c3c8fb8 commit 16695fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-glasses-rhyme.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 1 addition & 6 deletions packages/store-sync/src/createStoreSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
shareReplay,
combineLatest,
scan,
identity,
mergeMap,
} from "rxjs";
import { debug as parentDebug } from "./debug";
Expand Down Expand Up @@ -199,9 +198,7 @@ export async function createStoreSync<config extends StoreConfig = StoreConfig>(
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,
Expand All @@ -217,8 +214,6 @@ export async function createStoreSync<config extends StoreConfig = StoreConfig>(

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;
Expand Down

0 comments on commit 16695fe

Please sign in to comment.