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

Check for an existing start epoch before creating one #864

Merged
merged 4 commits into from
Apr 1, 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=31
IDB_VERSION=32
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anyone who has duplicate epochs in their database already will need to regenerate their data from scratch — hence the version bump.

USDC_ASSET_ID="reum7wQmk/owgvGMWMZn/6RFPV24zIKq3W6In/WwZgg="
MINIFRONT_URL=https://app.testnet.penumbra.zone/
PENUMBRA_NODE_PD_URL=https://grpc.testnet.penumbra.zone/
2 changes: 0 additions & 2 deletions packages/query/src/block-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ export class BlockProcessor implements BlockProcessorInterface {
// beginning of sync as well, and force the rest of sync to wait until
// it's done.
await this.updateValidatorInfos(0n);

await this.indexedDb.addEpoch(0n);
}

// this is an indefinite stream of the (compact) chain from the network
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/indexed-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class IndexedDb implements IndexedDbInterface {

const instance = new this(db, new IbdUpdater(db), constants, chainId);
await instance.saveLocalAssetsMetadata(); // Pre-load asset metadata
await instance.addEpoch(0n); // Create first epoch
return instance;
}

Expand Down
12 changes: 6 additions & 6 deletions packages/storage/src/indexed-db/indexed-db.test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,16 +703,16 @@ export const tradingPairGmGn = TradingPair.fromJson({
});

export const epoch1 = new Epoch({
index: 0n,
startHeight: 0n,
});

export const epoch2 = new Epoch({
index: 1n,
startHeight: 100n,
});

export const epoch3 = new Epoch({
export const epoch2 = new Epoch({
index: 2n,
startHeight: 200n,
});

export const epoch3 = new Epoch({
index: 3n,
startHeight: 300n,
});
33 changes: 24 additions & 9 deletions packages/storage/src/indexed-db/indexed-db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,31 +514,46 @@ describe('IndexedDb', () => {

beforeEach(async () => {
db = await IndexedDb.initialize({ ...generateInitialProps() });
await db.addEpoch(epoch1.startHeight);
await db.addEpoch(epoch2.startHeight);
await db.addEpoch(epoch3.startHeight);
});

it('prepopulates the 0th epoch', async () => {
const epoch = await db.getEpochByHeight(0n);
expect(epoch?.index).toBe(0n);
expect(epoch?.startHeight).toBe(0n);
});

describe('addEpoch', () => {
it('auto-increments the epoch index if one is not provided', async () => {
beforeEach(async () => {
await db.addEpoch(epoch1.startHeight);
await db.addEpoch(epoch2.startHeight);
await db.addEpoch(epoch3.startHeight);
});

it('auto-increments the epoch index', async () => {
const [result1, result2, result3] = await Promise.all([
db.getEpochByHeight(50n),
db.getEpochByHeight(150n),
db.getEpochByHeight(250n),
db.getEpochByHeight(350n),
]);

expect(result1?.index).toBe(0n);
expect(result2?.index).toBe(1n);
expect(result3?.index).toBe(2n);
expect(result1?.index).toBe(1n);
expect(result2?.index).toBe(2n);
expect(result3?.index).toBe(3n);
});
});

describe('getEpochByHeight', () => {
beforeEach(async () => {
await db.addEpoch(epoch1.startHeight);
await db.addEpoch(epoch2.startHeight);
await db.addEpoch(epoch3.startHeight);
});

it('returns the epoch containing the given block height', async () => {
const [result1, result2, result3] = await Promise.all([
db.getEpochByHeight(50n),
db.getEpochByHeight(150n),
db.getEpochByHeight(250n),
db.getEpochByHeight(350n),
]);

expect(result1?.toJson()).toEqual(epoch1.toJson());
Expand Down
Loading