From f291b819ace550ec7be67a180e286034759635e1 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 13 Dec 2024 19:38:45 +0100 Subject: [PATCH 1/3] chore: log sync aggregate participants when producing beacon block body --- .../src/chain/produceBlock/produceBlockBody.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts b/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts index d26703050070..f239dbe8565b 100644 --- a/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts +++ b/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts @@ -143,8 +143,15 @@ export async function produceBlockBody( ? Object.assign({}, commonBlockBody) : await produceCommonBlockBody.call(this, blockType, currentState, blockAttr); - const {attestations, deposits, voluntaryExits, attesterSlashings, proposerSlashings, blsToExecutionChanges} = - blockBody; + const { + attestations, + deposits, + voluntaryExits, + attesterSlashings, + proposerSlashings, + syncAggregate, + blsToExecutionChanges, + } = blockBody; Object.assign(logMeta, { attestations: attestations.length, @@ -154,6 +161,12 @@ export async function produceBlockBody( proposerSlashings: proposerSlashings.length, }); + if (ForkSeq[fork] >= ForkSeq.altair) { + Object.assign(logMeta, { + syncAggregateParticipants: syncAggregate.syncCommitteeBits.getTrueBitIndexes().length, + }); + } + const endExecutionPayload = stepsMetrics?.startTimer(); if (isForkExecution(fork)) { const safeBlockHash = this.forkChoice.getJustifiedBlock().executionPayloadBlockHash ?? ZERO_HASH_HEX; From 389c3424517666b873f056bfa555357fe7b2c7ce Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 13 Dec 2024 21:24:58 +0100 Subject: [PATCH 2/3] Use isForkLightClient instead of ForkSeq --- .../beacon-node/src/chain/produceBlock/produceBlockBody.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts b/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts index f239dbe8565b..149fcd639bb3 100644 --- a/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts +++ b/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts @@ -1,5 +1,5 @@ import {ChainForkConfig} from "@lodestar/config"; -import {ForkExecution, ForkSeq, isForkExecution} from "@lodestar/params"; +import {ForkExecution, ForkSeq, isForkExecution, isForkLightClient} from "@lodestar/params"; import { CachedBeaconStateAllForks, CachedBeaconStateBellatrix, @@ -161,7 +161,7 @@ export async function produceBlockBody( proposerSlashings: proposerSlashings.length, }); - if (ForkSeq[fork] >= ForkSeq.altair) { + if (isForkLightClient(fork)) { Object.assign(logMeta, { syncAggregateParticipants: syncAggregate.syncCommitteeBits.getTrueBitIndexes().length, }); From b064b55f4afd6d94e254343a9ecfd8b25dfa83ba Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 13 Dec 2024 21:25:13 +0100 Subject: [PATCH 3/3] Fix produce block unit tests --- .../src/chain/produceBlock/produceBlockBody.ts | 4 +--- packages/beacon-node/test/mocks/mockedBeaconChain.ts | 11 ++++++++++- .../unit/api/impl/validator/produceBlockV2.test.ts | 6 +++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts b/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts index 149fcd639bb3..e4c86b78907c 100644 --- a/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts +++ b/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts @@ -5,7 +5,6 @@ import { CachedBeaconStateBellatrix, CachedBeaconStateCapella, CachedBeaconStateExecutions, - computeEpochAtSlot, computeTimeAtSlot, getCurrentEpoch, getExpectedWithdrawals, @@ -621,7 +620,6 @@ export async function produceCommonBlockBody( ? this.metrics?.executionBlockProductionTimeSteps : this.metrics?.builderBlockProductionTimeSteps; - const blockEpoch = computeEpochAtSlot(slot); const fork = currentState.config.getForkName(slot); // TODO: @@ -666,7 +664,7 @@ export async function produceCommonBlockBody( } const endSyncAggregate = stepsMetrics?.startTimer(); - if (blockEpoch >= this.config.ALTAIR_FORK_EPOCH) { + if (ForkSeq[fork] >= ForkSeq.altair) { const syncAggregate = this.syncContributionAndProofPool.getAggregate(parentSlot, parentBlockRoot); this.metrics?.production.producedSyncAggregateParticipants.observe( syncAggregate.syncCommitteeBits.getTrueBitIndexes().length diff --git a/packages/beacon-node/test/mocks/mockedBeaconChain.ts b/packages/beacon-node/test/mocks/mockedBeaconChain.ts index b274284e3ab1..36d6fb27c53a 100644 --- a/packages/beacon-node/test/mocks/mockedBeaconChain.ts +++ b/packages/beacon-node/test/mocks/mockedBeaconChain.ts @@ -8,7 +8,7 @@ import {BeaconProposerCache} from "../../src/chain/beaconProposerCache.js"; import {BeaconChain} from "../../src/chain/chain.js"; import {ChainEventEmitter} from "../../src/chain/emitter.js"; import {LightClientServer} from "../../src/chain/lightClient/index.js"; -import {AggregatedAttestationPool, OpPool} from "../../src/chain/opPools/index.js"; +import {AggregatedAttestationPool, OpPool, SyncContributionAndProofPool} from "../../src/chain/opPools/index.js"; import {QueuedStateRegenerator} from "../../src/chain/regen/index.js"; import {ShufflingCache} from "../../src/chain/shufflingCache.js"; import {Eth1ForBlockProduction} from "../../src/eth1/index.js"; @@ -27,6 +27,7 @@ export type MockedBeaconChain = Mocked & { eth1: Mocked; opPool: Mocked; aggregatedAttestationPool: Mocked; + syncContributionAndProofPool: Mocked; beaconProposerCache: Mocked; shufflingCache: Mocked; regen: Mocked; @@ -94,10 +95,17 @@ vi.mock("../../src/chain/opPools/index.js", async (importActual) => { }; }); + const SyncContributionAndProofPool = vi.fn().mockImplementation(() => { + return { + getAggregate: vi.fn(), + }; + }); + return { ...mod, OpPool, AggregatedAttestationPool, + SyncContributionAndProofPool, }; }); @@ -124,6 +132,7 @@ vi.mock("../../src/chain/chain.js", async (importActual) => { eth1: new Eth1ForBlockProduction(), opPool: new OpPool(), aggregatedAttestationPool: new AggregatedAttestationPool(config), + syncContributionAndProofPool: new SyncContributionAndProofPool(), // @ts-expect-error beaconProposerCache: new BeaconProposerCache(), shufflingCache: new ShufflingCache(), diff --git a/packages/beacon-node/test/unit/api/impl/validator/produceBlockV2.test.ts b/packages/beacon-node/test/unit/api/impl/validator/produceBlockV2.test.ts index 52f600b7174c..418dd2e56d8d 100644 --- a/packages/beacon-node/test/unit/api/impl/validator/produceBlockV2.test.ts +++ b/packages/beacon-node/test/unit/api/impl/validator/produceBlockV2.test.ts @@ -1,7 +1,7 @@ import {fromHexString, toHexString} from "@chainsafe/ssz"; import {ProtoBlock} from "@lodestar/fork-choice"; import {ForkName} from "@lodestar/params"; -import {CachedBeaconStateBellatrix, computeTimeAtSlot} from "@lodestar/state-transition"; +import {CachedBeaconStateBellatrix, G2_POINT_AT_INFINITY, computeTimeAtSlot} from "@lodestar/state-transition"; import {ssz} from "@lodestar/types"; import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {getValidatorApi} from "../../../../../src/api/impl/validator/index.js"; @@ -99,6 +99,10 @@ describe("api/validator - produceBlockV2", () => { eth1Data: ssz.phase0.Eth1Data.defaultValue(), deposits: [], }); + modules.chain["syncContributionAndProofPool"].getAggregate.mockReturnValue({ + syncCommitteeBits: ssz.altair.SyncCommitteeBits.defaultValue(), + syncCommitteeSignature: G2_POINT_AT_INFINITY, + }); modules.forkChoice.getJustifiedBlock.mockReturnValue({} as ProtoBlock); modules.forkChoice.getFinalizedBlock.mockReturnValue({} as ProtoBlock);