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

Optimize merge tracker and add merge metrics #4350

Merged
merged 18 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from 17 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
959 changes: 938 additions & 21 deletions dashboards/lodestar_general.json

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion packages/beacon-node/src/chain/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "@lodestar/state-transition";
import {IBeaconConfig} from "@lodestar/config";
import {allForks, UintNum64, Root, phase0, Slot, RootHex, Epoch, ValidatorIndex} from "@lodestar/types";
import {CheckpointWithHex, IForkChoice, ProtoBlock} from "@lodestar/fork-choice";
import {CheckpointWithHex, ExecutionStatus, IForkChoice, ProtoBlock} from "@lodestar/fork-choice";
import {ILogger, toHex} from "@lodestar/utils";
import {CompositeTypeAny, fromHexString, TreeView, Type} from "@chainsafe/ssz";
import {GENESIS_EPOCH, ZERO_HASH} from "../constants/index.js";
Expand Down Expand Up @@ -521,6 +521,17 @@ export class BeaconChain implements IBeaconChain {
this.seenAggregatedAttestations.prune(epoch);
this.seenBlockAttesters.prune(epoch);
this.beaconProposerCache.prune(epoch);

// Poll for merge block in the background to speed-up block production. Only if:
// - after BELLATRIX_FORK_EPOCH
// - Beacon node synced
// - head state not isMergeTransitionComplete
if (this.config.BELLATRIX_FORK_EPOCH - epoch < 1) {
const head = this.forkChoice.getHead();
if (epoch - computeEpochAtSlot(head.slot) < 5 && head.executionStatus === ExecutionStatus.PreMerge) {
this.eth1.startPollingMergeBlock();
}
}
}

private onForkChoiceHead(head: ProtoBlock): void {
Expand Down
10 changes: 5 additions & 5 deletions packages/beacon-node/src/chain/factory/block/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export async function prepareExecutionPayload(
state: CachedBeaconStateBellatrix,
suggestedFeeRecipient: string
): Promise<{isPremerge: true} | {isPremerge: false; payloadId: PayloadId}> {
const parentHashRes = getExecutionPayloadParentHash(chain, state);
const parentHashRes = await getExecutionPayloadParentHash(chain, state);
if (parentHashRes.isPremerge) {
// Return null only if the execution is pre-merge
return {isPremerge: true};
Expand Down Expand Up @@ -237,7 +237,7 @@ async function prepareExecutionPayloadHeader(
throw Error("executionBuilder required");
}

const parentHashRes = getExecutionPayloadParentHash(chain, state);
const parentHashRes = await getExecutionPayloadParentHash(chain, state);

if (parentHashRes.isPremerge) {
// TODO: Is this okay?
Expand All @@ -248,13 +248,13 @@ async function prepareExecutionPayloadHeader(
return chain.executionBuilder.getPayloadHeader(state.slot, parentHash, proposerPubKey);
}

function getExecutionPayloadParentHash(
async function getExecutionPayloadParentHash(
chain: {
eth1: IEth1ForBlockProduction;
config: IChainForkConfig;
},
state: CachedBeaconStateBellatrix
): {isPremerge: true} | {isPremerge: false; parentHash: Root} {
): Promise<{isPremerge: true} | {isPremerge: false; parentHash: Root}> {
// Use different POW block hash parent for block production based on merge status.
// Returned value of null == using an empty ExecutionPayload value
if (isMergeTransitionComplete(state)) {
Expand All @@ -271,7 +271,7 @@ function getExecutionPayloadParentHash(
}, actual: ${getCurrentEpoch(state)}`
);

const terminalPowBlockHash = chain.eth1.getTerminalPowBlock();
const terminalPowBlockHash = await chain.eth1.getTerminalPowBlock();
if (terminalPowBlockHash === null) {
// Pre-merge, no prepare payload call is needed
return {isPremerge: true};
Expand Down
Loading