Skip to content

Commit

Permalink
fix: disableCache running out of order (#1164)
Browse files Browse the repository at this point in the history
* fix disableCache out of order pruning

* fixed problem with last release
  • Loading branch information
kyscott18 authored Oct 13, 2024
1 parent a558e19 commit 087d393
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-hairs-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ponder/core": patch
---

See https://github.com/ponder-sh/ponder/blob/main/packages/core/CHANGELOG.md#0614
5 changes: 5 additions & 0 deletions .changeset/lovely-spies-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ponder/core": patch
---

Fixed a bug introduced in v0.6.0 where the `disableCache` option did not correctly ignore the cache in some cases.
50 changes: 24 additions & 26 deletions packages/core/src/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,19 @@ export const createSync = async (args: CreateSyncParameters): Promise<Sync> => {
network,
});

// Invalidate sync cache for devnet sources
if (network.disableCache) {
args.common.logger.warn({
service: "sync",
msg: `Deleting cache records for '${network.name}' from block ${hexToNumber(start.number)}`,
});

await args.syncStore.pruneByChain({
fromBlock: hexToNumber(start.number),
chainId: network.chainId,
});
}

const historicalSync = await createHistoricalSync({
common: args.common,
sources,
Expand All @@ -262,33 +275,18 @@ export const createSync = async (args: CreateSyncParameters): Promise<Sync> => {
onFatalError: args.onFatalError,
});

let cached: SyncBlock | LightBlock | undefined;

// Invalidate sync cache for devnet sources
if (network.disableCache) {
args.common.logger.warn({
service: "sync",
msg: `Deleting cache records for '${network.name}' from block ${hexToNumber(start.number)}`,
});

await args.syncStore.pruneByChain({
fromBlock: hexToNumber(start.number),
chainId: network.chainId,
});
} else {
cached = await getCachedBlock({
sources,
requestQueue,
historicalSync,
});
const cached = await getCachedBlock({
sources,
requestQueue,
historicalSync,
});

// Update "ponder_sync_block" metric
if (cached !== undefined) {
args.common.metrics.ponder_sync_block.set(
{ network: network.name },
hexToNumber(cached.number),
);
}
// Update "ponder_sync_block" metric
if (cached !== undefined) {
args.common.metrics.ponder_sync_block.set(
{ network: network.name },
hexToNumber(cached.number),
);
}

const syncProgress: SyncProgress = {
Expand Down

0 comments on commit 087d393

Please sign in to comment.