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 1 commit
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 packages/query/src/block-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ export class BlockProcessor implements BlockProcessorInterface {
endHeightOfPreviousEpoch: bigint,
latestKnownBlockHeight: bigint,
): Promise<void> {
const { sctParams } = await this.querier.app.appParams();
const { sctParams } = (await this.indexedDb.getAppParams()) ?? {};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also fixed this, we don't need to request sctParams from the full node since we store them in indexed-db

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like this.indexedDb.addEpoch() should go above this

Copy link
Contributor

Choose a reason for hiding this comment

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

@grod220 why's that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The params are used further down. There seems to be code in between that doesn't use the params.

const nextEpochStartHeight = endHeightOfPreviousEpoch + 1n;

await this.indexedDb.addEpoch(nextEpochStartHeight);
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 result3 = await db.getEpochByHeight(350n);
expect(result3?.index).toBe(3n);
Valentine1898 marked this conversation as resolved.
Show resolved Hide resolved
});
});

describe('getEpochByHeight', () => {
Expand Down
Loading