Skip to content

Commit

Permalink
Optimize merge tracker and add merge metrics (#4350)
Browse files Browse the repository at this point in the history
* Optimize merge tracker and add merge metrics

* early return if genesis is merge block

* add metric for latest block time

* grafana dashboard

* cleanup merge update

* expanded/compressed merge logging

* fix type check in tests

* improve logging

* expanded merge at 12hrs

* Review PR

* Fix tests

* Update prettyTimeDiffSec test

* merge time and dashboard fixes

* fix the comment

* change timeseries input to seconds from ms

* merge found fix

* change last block timestamp collection to seconds

Co-authored-by: dapplion <[email protected]>
  • Loading branch information
g11tech and dapplion authored Aug 2, 2022
1 parent f0a5f41 commit b6c1e2b
Show file tree
Hide file tree
Showing 18 changed files with 1,491 additions and 429 deletions.
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

0 comments on commit b6c1e2b

Please sign in to comment.