diff --git a/apps/extension/.env b/apps/extension/.env index b72914eb8c..6d0f4d731e 100644 --- a/apps/extension/.env +++ b/apps/extension/.env @@ -1,6 +1,6 @@ PRAX=lkpmkhpnhknhmibgnmmhdhgdilepfghe -IDB_VERSION=33 +IDB_VERSION=34 USDC_ASSET_ID="reum7wQmk/owgvGMWMZn/6RFPV24zIKq3W6In/WwZgg=" MINIFRONT_URL=https://app.testnet.penumbra.zone/ PENUMBRA_NODE_PD_URL=https://grpc.testnet.penumbra.zone/ diff --git a/packages/query/src/block-processor.ts b/packages/query/src/block-processor.ts index 9cec3319d2..b4430f6027 100644 --- a/packages/query/src/block-processor.ts +++ b/packages/query/src/block-processor.ts @@ -423,11 +423,10 @@ export class BlockProcessor implements BlockProcessorInterface { endHeightOfPreviousEpoch: bigint, latestKnownBlockHeight: bigint, ): Promise { - const { sctParams } = await this.querier.app.appParams(); const nextEpochStartHeight = endHeightOfPreviousEpoch + 1n; - await this.indexedDb.addEpoch(nextEpochStartHeight); + const { sctParams } = (await this.indexedDb.getAppParams()) ?? {}; const nextEpochIsLatestKnownEpoch = sctParams && latestKnownBlockHeight - nextEpochStartHeight < sctParams.epochDuration; diff --git a/packages/storage/src/indexed-db/index.ts b/packages/storage/src/indexed-db/index.ts index 30b8a8d374..d769fcea1c 100644 --- a/packages/storage/src/indexed-db/index.ts +++ b/packages/storage/src/indexed-db/index.ts @@ -477,6 +477,9 @@ export class IndexedDb implements IndexedDbInterface { const previousEpoch = cursor?.value ? Epoch.fromJson(cursor.value) : undefined; const index = previousEpoch?.index !== undefined ? previousEpoch.index + 1n : 0n; + // avoid saving the same epoch twice + if (previousEpoch?.startHeight === startHeight) return; + const newEpoch = { startHeight: startHeight.toString(), index: index.toString(), diff --git a/packages/storage/src/indexed-db/indexed-db.test.ts b/packages/storage/src/indexed-db/indexed-db.test.ts index 299b23428e..194550bec6 100644 --- a/packages/storage/src/indexed-db/indexed-db.test.ts +++ b/packages/storage/src/indexed-db/indexed-db.test.ts @@ -545,6 +545,13 @@ describe('IndexedDb', () => { expect(result2?.index).toBe(2n); expect(result3?.index).toBe(3n); }); + + it('should not save the epoch with the same startHeight twice', async () => { + await db.addEpoch(epoch3.startHeight); + + const result = await db.getEpochByHeight(350n); + expect(result?.index).toBe(3n); + }); }); describe('getEpochByHeight', () => {