Skip to content

Commit

Permalink
Merge branch 'main' into kjs/mem
Browse files Browse the repository at this point in the history
  • Loading branch information
kyscott18 committed Sep 24, 2024
2 parents ec0a05c + 2612ba2 commit e2921c7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 65 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-shoes-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ponder/core": patch
---

Fixed a bug introduced in `0.6.0` that caused a crash shortly after startup for some apps with a partial cache hit.
5 changes: 5 additions & 0 deletions .changeset/selfish-teachers-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ponder/core": patch
---

Pinned vite version. Some newer versions were known to cause hot reloading bugs.
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
"prom-client": "^15.0.0",
"react": "^18.2.0",
"stacktrace-parser": "^0.1.10",
"vite": "^5.0.7",
"vite-node": "^1.0.2",
"vite-tsconfig-paths": "^4.3.1"
"vite": "5.0.7",
"vite-node": "1.0.2",
"vite-tsconfig-paths": "4.3.1"
},
"devDependencies": {
"@types/babel__code-frame": "^7.0.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/sync-historical/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type HistoricalSync = {
* Extract raw data for `interval` and return the closest-to-tip block
* that is synced.
*/
sync(interval: Interval): Promise<SyncBlock>;
sync(interval: Interval): Promise<SyncBlock | undefined>;
kill(): void;
};

Expand Down Expand Up @@ -509,7 +509,7 @@ export const createHistoricalSync = async (
blockCache.clear();
transactionsCache.clear();

return latestBlock!;
return latestBlock;
},
kill() {
isKilled = true;
Expand Down
71 changes: 46 additions & 25 deletions packages/core/src/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ export const syncDiagnostic = async ({
*/
const end = sources.some(({ filter }) => filter.toBlock === undefined)
? undefined
: Math.min(...sources.map(({ filter }) => filter.toBlock!));
: Math.max(...sources.map(({ filter }) => filter.toBlock!));

const [remoteChainId, startBlock, endBlock, latestBlock] = await Promise.all([
requestQueue.request({ method: "eth_chainId" }),
Expand Down Expand Up @@ -1102,35 +1102,56 @@ export async function* localHistoricalSyncGenerator({
];

const endClock = startClock();
syncProgress.current = await historicalSync.sync(interval);
const duration = endClock();

// Update "ponder_sync_block" metric
common.metrics.ponder_sync_block.set(
{ network: network.name },
hexToNumber(syncProgress.current.number),
);

common.metrics.ponder_historical_duration.observe(label, duration);
common.metrics.ponder_historical_completed_blocks.inc(
label,
interval[1] - interval[0] + 1,
);

// Use the duration and interval of the last call to `sync` to update estimate
// 25 <= estimate(new) <= estimate(prev) * 2 <= 100_000
estimateRange = Math.min(
Math.max(
25,
Math.round((1_000 * (interval[1] - interval[0])) / duration),
),
estimateRange * 2,
100_000,
);
const syncBlock = await historicalSync.sync(interval);

// Update cursor to record progress
fromBlock = interval[1] + 1;

if (syncBlock === undefined) {
/**
* `syncBlock` will be undefined if a cache hit occur in `historicalSync.sync()`.
* If the all known blocks are synced, then update `syncProgress.current`, else
* progress to the next iteration.
*/
if (interval[1] === hexToNumber(historicalLast.number)) {
syncProgress.current = historicalLast;
} else {
continue;
}
} else {
if (interval[1] === hexToNumber(historicalLast.number)) {
syncProgress.current = historicalLast;
} else {
syncProgress.current = syncBlock;
}

const duration = endClock();

// Update "ponder_sync_block" metric
common.metrics.ponder_sync_block.set(
{ network: network.name },
hexToNumber(syncProgress.current.number),
);

common.metrics.ponder_historical_duration.observe(label, duration);
common.metrics.ponder_historical_completed_blocks.inc(
label,
interval[1] - interval[0] + 1,
);

// Use the duration and interval of the last call to `sync` to update estimate
// 25 <= estimate(new) <= estimate(prev) * 2 <= 100_000
estimateRange = Math.min(
Math.max(
25,
Math.round((1_000 * (interval[1] - interval[0])) / duration),
),
estimateRange * 2,
100_000,
);
}

yield;

if (
Expand Down
49 changes: 14 additions & 35 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e2921c7

Please sign in to comment.