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

Use parentBlockSlot in importBlock #4282

Merged
merged 1 commit into from
Jul 12, 2022
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
6 changes: 3 additions & 3 deletions packages/beacon-node/src/chain/blocks/importBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export type ImportBlockModules = {
* - Send events after everything is done
*/
export async function importBlock(chain: ImportBlockModules, fullyVerifiedBlock: FullyVerifiedBlock): Promise<void> {
const {block, postState, parentBlock, skipImportingAttestations, executionStatus} = fullyVerifiedBlock;
const {block, postState, parentBlockSlot, skipImportingAttestations, executionStatus} = fullyVerifiedBlock;
const pendingEvents = new PendingEvents(chain.emitter);

// - Observe attestations
Expand Down Expand Up @@ -256,7 +256,7 @@ export async function importBlock(chain: ImportBlockModules, fullyVerifiedBlock:
chain.lightClientServer.onImportBlockHead(
block.message as altair.BeaconBlock,
postState as CachedBeaconStateAltair,
parentBlock
parentBlockSlot
);
} catch (e) {
chain.logger.error("Error lightClientServer.onImportBlock", {slot: block.message.slot}, e as Error);
Expand Down Expand Up @@ -308,7 +308,7 @@ export async function importBlock(chain: ImportBlockModules, fullyVerifiedBlock:
pendingEvents.emit();

// Register stat metrics about the block after importing it
chain.metrics?.parentBlockDistance.observe(block.message.slot - parentBlock.slot);
chain.metrics?.parentBlockDistance.observe(block.message.slot - parentBlockSlot);
chain.metrics?.proposerBalanceDiffAny.observe(fullyVerifiedBlock.proposerBalanceDiff);
chain.metrics?.registerImportedBlock(block.message, fullyVerifiedBlock);

Expand Down
6 changes: 3 additions & 3 deletions packages/beacon-node/src/chain/blocks/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
import {ProtoBlock, ExecutionStatus} from "@lodestar/fork-choice";
import {allForks} from "@lodestar/types";
import {ExecutionStatus} from "@lodestar/fork-choice";
import {allForks, Slot} from "@lodestar/types";

export type FullyVerifiedBlockFlags = {
/**
Expand Down Expand Up @@ -50,7 +50,7 @@ export type PartiallyVerifiedBlockFlags = FullyVerifiedBlockFlags & {
export type FullyVerifiedBlock = FullyVerifiedBlockFlags & {
block: allForks.SignedBeaconBlock;
postState: CachedBeaconStateAllForks;
parentBlock: ProtoBlock;
parentBlockSlot: Slot;
proposerBalanceDiff: number;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/blocks/verifyBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function verifyBlock(
return {
block: partiallyVerifiedBlock.block,
postState,
parentBlock,
parentBlockSlot: parentBlock.slot,
skipImportingAttestations: partiallyVerifiedBlock.skipImportingAttestations,
executionStatus,
proposerBalanceDiff,
Expand Down
14 changes: 5 additions & 9 deletions packages/beacon-node/src/chain/lightClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,7 @@ export class LightClientServer {
* - Persist state witness
* - Use block's syncAggregate
*/
onImportBlockHead(
block: altair.BeaconBlock,
postState: CachedBeaconStateAltair,
parentBlock: {blockRoot: RootHex; slot: Slot}
): void {
onImportBlockHead(block: altair.BeaconBlock, postState: CachedBeaconStateAltair, parentBlockSlot: Slot): void {
// What is the syncAggregate signing?
// From the state-transition
// ```
Expand All @@ -206,7 +202,7 @@ export class LightClientServer {
this.logger.error("Error onSyncAggregate", {}, e);
});

this.persistPostBlockImportData(block, postState, parentBlock).catch((e) => {
this.persistPostBlockImportData(block, postState, parentBlockSlot).catch((e) => {
this.logger.error("Error persistPostBlockImportData", {}, e);
});
}
Expand Down Expand Up @@ -327,7 +323,7 @@ export class LightClientServer {
private async persistPostBlockImportData(
block: altair.BeaconBlock,
postState: CachedBeaconStateAltair,
parentBlock: {blockRoot: RootHex; slot: Slot}
parentBlockSlot: Slot
): Promise<void> {
const blockSlot = block.slot;

Expand Down Expand Up @@ -355,11 +351,11 @@ export class LightClientServer {
}

// Only store next sync committee once per dependant root
const parentBlockPeriod = computeSyncPeriodAtSlot(parentBlock.slot);
const parentBlockPeriod = computeSyncPeriodAtSlot(parentBlockSlot);
const period = computeSyncPeriodAtSlot(blockSlot);
if (parentBlockPeriod < period) {
// If the parentBlock is in a previous epoch it must be the dependantRoot of this epoch transition
const dependantRoot = parentBlock.blockRoot;
const dependantRoot = toHexString(block.parentRoot);
const periodDependantRoots = this.knownSyncCommittee.getOrDefault(period);
if (!periodDependantRoots.has(dependantRoot)) {
periodDependantRoots.add(dependantRoot);
Expand Down