Skip to content

Commit

Permalink
handle epoch genesis in block processor
Browse files Browse the repository at this point in the history
  • Loading branch information
turbocrime committed Aug 20, 2024
1 parent 7b58ef1 commit 48e2df7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
14 changes: 6 additions & 8 deletions packages/query/src/block-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class BlockProcessor implements BlockProcessorInterface {
* Sync local state to present. This method will
* - identify current synced height (or `-1n` to represent a 'pre-genesis' state)
* - query remote rpc for the chain's latest block height
* - pre-genesis, initialize validator info
* - pre-genesis, initialize 0th epoch and validator info
* - pre-genesis, process a local genesis block if provided
* - query remote rpc to begin streaming at the next block
* - iterate
Expand All @@ -164,12 +164,11 @@ export class BlockProcessor implements BlockProcessorInterface {

// special case genesis sync
if (currentHeight === -1n) {
// initialize validator info at genesis
// TODO: use batch endpoint https://github.com/penumbra-zone/penumbra/issues/4688
// initialize epoch 0
await this.indexedDb.addEpoch(currentHeight + 1n);
await this.updateValidatorInfos(currentHeight + 1n);

// begin the chain with local genesis block if provided
if (this.genesisBlock?.height === currentHeight + 1n) {
// begin the chain with local genesis block if provided
currentHeight = this.genesisBlock.height;
await this.processBlock(this.genesisBlock, latestKnownBlockHeight);
}
Expand Down Expand Up @@ -351,8 +350,7 @@ export class BlockProcessor implements BlockProcessorInterface {
);
}

const isLastBlockOfEpoch = !!compactBlock.epochRoot;
if (isLastBlockOfEpoch) {
if (compactBlock.epochRoot) {
await this.handleEpochTransition(compactBlock.height, latestKnownBlockHeight);
}

Expand Down Expand Up @@ -669,7 +667,7 @@ export class BlockProcessor implements BlockProcessorInterface {
// only get updated validator infos once we're within the latest known
// epoch.
if (nextEpochIsLatestKnownEpoch) {
void this.updateValidatorInfos(nextEpochStartHeight);
await this.updateValidatorInfos(nextEpochStartHeight);
}
}

Expand Down
5 changes: 0 additions & 5 deletions packages/storage/src/indexed-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@ export class IndexedDb implements IndexedDbInterface {
);
await instance.saveRegistryAssets(registryClient, chainId); // Pre-load asset metadata from registry

const existing0thEpoch = await instance.getEpochByHeight(0n);
if (!existing0thEpoch) {
await instance.addEpoch(0n);
} // Create first epoch

return instance;
}

Expand Down

0 comments on commit 48e2df7

Please sign in to comment.