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

fix(store-sync): reduce latency in waitForTransaction #2665

Merged
merged 28 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bc4be63
feat(common): send fetch requests in parallel
alvrs Apr 11, 2024
527eecc
feat(common): do not dynamically fetch fixed tx params
alvrs Apr 11, 2024
3e9ef7f
fix: bring back separate gas estimation
alvrs Apr 11, 2024
814ae1e
feat(common): refresh fees in intervals instead of right before every…
alvrs Apr 11, 2024
58a0464
feat(common): don't care about max fee during gas estimation
alvrs Apr 11, 2024
7b5d7ef
remove stubbed values from result
alvrs Apr 11, 2024
858f163
fix: gas estimation
alvrs Apr 12, 2024
2ecc4d9
update viem
alvrs Apr 12, 2024
260d791
self-review
alvrs Apr 12, 2024
702eccb
Merge branch 'main' into latency
alvrs Apr 12, 2024
f3daaf9
run all-install
alvrs Apr 12, 2024
a592fa5
don't throw
alvrs Apr 12, 2024
b31383f
bump viem to 2.9.16
holic Apr 12, 2024
cec07e8
fix nonce handling
alvrs Apr 12, 2024
d62171a
use getAction
alvrs Apr 12, 2024
1e8acce
bring back block tag
alvrs Apr 12, 2024
b366ebf
cast return type for now
holic Apr 12, 2024
24610a1
Merge branch 'holic/viem-2.9' into latency
alvrs Apr 12, 2024
7e6635e
update log
alvrs Apr 12, 2024
fc7824c
Merge branch 'main' into latency
alvrs Apr 12, 2024
bbc1cee
Create fresh-nails-draw.md
alvrs Apr 12, 2024
c61f8dd
review feedback
alvrs Apr 15, 2024
263c679
Merge branch 'main' into latency
alvrs Apr 15, 2024
99d7a29
pull out store-sync changes
alvrs Apr 15, 2024
af3eadc
gasfee chain dependent
alvrs Apr 16, 2024
8c2bfd0
reduce latency in waitForTransaction
alvrs Apr 15, 2024
9c1d52f
Create twelve-hairs-fry.md
alvrs Apr 15, 2024
615664a
Merge branch 'main' into latency-2
alvrs Apr 16, 2024
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/twelve-hairs-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store-sync": patch
---

Small optimizations in `waitForTransaction` to parallelize network requests.
11 changes: 9 additions & 2 deletions packages/store-sync/src/createStoreSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
combineLatest,
scan,
identity,
mergeMap,
} from "rxjs";
import { debug as parentDebug } from "./debug";
import { SyncStep } from "./SyncStep";
Expand Down Expand Up @@ -197,7 +198,9 @@ export async function createStoreSync<config extends StoreConfig = StoreConfig>(
startBlock = range.startBlock;
endBlock = range.endBlock;
}),
concatMap((range) => {
// 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) => {
const storedBlocks = fetchAndStoreLogs({
publicClient,
address,
Expand All @@ -213,6 +216,8 @@ 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 Expand Up @@ -263,7 +268,9 @@ export async function createStoreSync<config extends StoreConfig = StoreConfig>(
// This currently blocks for async call on each block processed
// We could potentially speed this up a tiny bit by racing to see if 1) tx exists in processed block or 2) fetch tx receipt for latest block processed
const hasTransaction$ = recentBlocks$.pipe(
concatMap(async (blocks) => {
// We use `mergeMap` 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.
mergeMap(async (blocks) => {
const txs = blocks.flatMap((block) => block.logs.map((op) => op.transactionHash).filter(isDefined));
if (txs.includes(tx)) return true;

Expand Down
Loading