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 epoch saving #909

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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;

Comment on lines +480 to +482
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I thought it would be best to link to epochRoot.
But it seems that binding to a unique startHeight is just as good, plus I'm not sure that epochRoot is guaranteed to be unique for every epoch

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
Loading