Skip to content

Commit

Permalink
fix(store-sync): apply logs from buffer in watchLogs (#3346)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs authored Oct 30, 2024
1 parent 0592406 commit cd9fd0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-peaches-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store-sync": patch
---

Fixed a bug in `watchLogs` where logs from the buffer were not applied during the initial sync.
5 changes: 3 additions & 2 deletions packages/store-sync/src/watchLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ export function watchLogs({ url, address, fromBlock }: WatchLogsInput): WatchLog
try {
debug("fetching initial logs");
const initialLogs = await fetchInitialLogs({ client, address, fromBlock: resumeBlock, topics });
debug("got logs", initialLogs);
debug("got initial logs", initialLogs);
const logs = [...initialLogs, ...logBuffer].sort(logSort);
debug("combining with log buffer", logs);
const blockNumber = logs.at(-1)?.blockNumber ?? resumeBlock;
subscriber.next({ blockNumber, logs: initialLogs });
subscriber.next({ blockNumber, logs });
resumeBlock = blockNumber + 1n;
caughtUp = true;
} catch (error) {
Expand Down

0 comments on commit cd9fd0a

Please sign in to comment.