Skip to content

Commit

Permalink
LightClientServer only import block if its new head (#3967)
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths authored May 4, 2022
1 parent 0740259 commit 3eeb6e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
30 changes: 15 additions & 15 deletions packages/lodestar/src/chain/blocks/importBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,21 @@ export async function importBlock(chain: ImportBlockModules, fullyVerifiedBlock:
pendingEvents.push(ChainEvent.forkChoiceReorg, newHead, oldHead, distance);
chain.metrics?.forkChoiceReorg.inc();
}

// Lightclient server support (only after altair)
// - Persist state witness
// - Use block's syncAggregate
if (blockEpoch >= chain.config.ALTAIR_FORK_EPOCH) {
try {
chain.lightClientServer.onImportBlockHead(
block.message as altair.BeaconBlock,
postState as CachedBeaconStateAltair,
parentBlock
);
} catch (e) {
chain.logger.error("Error lightClientServer.onImportBlock", {slot: block.message.slot}, e as Error);
}
}
}

// NOTE: forkChoice.fsStore.finalizedCheckpoint MUST only change is response to an onBlock event
Expand Down Expand Up @@ -245,21 +260,6 @@ export async function importBlock(chain: ImportBlockModules, fullyVerifiedBlock:
chain.stateCache.add(postState);
await chain.db.block.add(block);

// Lightclient server support (only after altair)
// - Persist state witness
// - Use block's syncAggregate
if (computeEpochAtSlot(block.message.slot) >= chain.config.ALTAIR_FORK_EPOCH) {
try {
chain.lightClientServer.onImportBlock(
block.message as altair.BeaconBlock,
postState as CachedBeaconStateAltair,
parentBlock
);
} catch (e) {
chain.logger.error("Error lightClientServer.onImportBlock", {slot: block.message.slot}, e as Error);
}
}

// - head_tracker.register_block(block_root, parent_root, slot)

// - Send event after everything is done
Expand Down
4 changes: 2 additions & 2 deletions packages/lodestar/src/chain/lightClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ export class LightClientServer {
}

/**
* Call after importing a block, having the postState available in memory for proof generation.
* Call after importing a block head, having the postState available in memory for proof generation.
* - Persist state witness
* - Use block's syncAggregate
*/
onImportBlock(
onImportBlockHead(
block: altair.BeaconBlock,
postState: CachedBeaconStateAltair,
parentBlock: {blockRoot: RootHex; slot: Slot}
Expand Down

1 comment on commit 3eeb6e2

@Seki22

This comment was marked as spam.

Please sign in to comment.