Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
TalDerei committed Oct 1, 2024
1 parent 48274c1 commit 5bb8f9d
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/query/src/block-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ export class BlockProcessor implements BlockProcessorInterface {
* - iterate
*/
private async syncAndStore() {
const PRE_GENESIS_SYNC_HEIGHT = -1n;

// start at next block, or genesis if height is undefined
let currentHeight = (await this.indexedDb.getFullSyncHeight()) ?? -1n;
let currentHeight = (await this.indexedDb.getFullSyncHeight()) ?? PRE_GENESIS_SYNC_HEIGHT;

// this is the first network query of the block processor. use backoff to
// delay until network is available
Expand All @@ -160,14 +162,19 @@ export class BlockProcessor implements BlockProcessorInterface {
{ retry: () => true },
);

// special case genesis sync
if (currentHeight === -1n) {
// create first epoch and initialize validator info at genesis
await this.indexedDb.addEpoch(currentHeight + 1n);
void this.updateValidatorInfos(currentHeight + 1n);
// handle the special case where no syncing has been done yet, and
// prepares for syncing and checks for a bundled genesis block,
// which can save time by avoiding an initial network request.
if (currentHeight === PRE_GENESIS_SYNC_HEIGHT) {
// create first epoch
await this.indexedDb.addEpoch(0n);

// initialize validator info at genesis
// TODO: use batch endpoint https://github.com/penumbra-zone/penumbra/issues/4688
void this.updateValidatorInfos(0n);

// conditional only runs if there is a bundled genesis block provided for the chain
if (this.genesisBlock?.height === currentHeight + 1n) {
// begin the chain with local genesis block if provided
currentHeight = this.genesisBlock.height;

// Set the trial decryption flag for the genesis compact block
Expand Down Expand Up @@ -373,6 +380,7 @@ export class BlockProcessor implements BlockProcessorInterface {
);
}

// The presence of `epochRoot` indicates that this is the final block of the current epoch.
if (compactBlock.epochRoot) {
await this.handleEpochTransition(compactBlock.height, latestKnownBlockHeight);
}
Expand Down

0 comments on commit 5bb8f9d

Please sign in to comment.