Skip to content

Commit

Permalink
fix epoch saving (#909)
Browse files Browse the repository at this point in the history
* fix epoch saving

* Update packages/storage/src/indexed-db/indexed-db.test.ts

Co-authored-by: Jesse Pinho <[email protected]>

* move sctParams below

* bump idb version

---------

Co-authored-by: Jesse Pinho <[email protected]>
  • Loading branch information
Valentine1898 and jessepinho authored Apr 9, 2024
1 parent b4082b7 commit 5248540
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/extension/.env
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 1 addition & 2 deletions packages/query/src/block-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,10 @@ export class BlockProcessor implements BlockProcessorInterface {
endHeightOfPreviousEpoch: bigint,
latestKnownBlockHeight: bigint,
): Promise<void> {
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;

Expand Down
3 changes: 3 additions & 0 deletions packages/storage/src/indexed-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
7 changes: 7 additions & 0 deletions packages/storage/src/indexed-db/indexed-db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 5248540

Please sign in to comment.