Skip to content

Commit

Permalink
chore: log sync aggregate participants when producing beacon block bo…
Browse files Browse the repository at this point in the history
…dy (#7300)

* chore: log sync aggregate participants when producing beacon block body

* Use isForkLightClient instead of ForkSeq

* Fix produce block unit tests
  • Loading branch information
nflaig authored Dec 15, 2024
1 parent a00c796 commit ba1d41b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
23 changes: 17 additions & 6 deletions packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {ChainForkConfig} from "@lodestar/config";
import {ForkExecution, ForkSeq, isForkExecution} from "@lodestar/params";
import {ForkExecution, ForkSeq, isForkExecution, isForkLightClient} from "@lodestar/params";
import {
CachedBeaconStateAllForks,
CachedBeaconStateBellatrix,
CachedBeaconStateCapella,
CachedBeaconStateExecutions,
computeEpochAtSlot,
computeTimeAtSlot,
getCurrentEpoch,
getExpectedWithdrawals,
Expand Down Expand Up @@ -143,8 +142,15 @@ export async function produceBlockBody<T extends BlockType>(
? 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,
Expand All @@ -154,6 +160,12 @@ export async function produceBlockBody<T extends BlockType>(
proposerSlashings: proposerSlashings.length,
});

if (isForkLightClient(fork)) {
Object.assign(logMeta, {
syncAggregateParticipants: syncAggregate.syncCommitteeBits.getTrueBitIndexes().length,
});
}

const endExecutionPayload = stepsMetrics?.startTimer();
if (isForkExecution(fork)) {
const safeBlockHash = this.forkChoice.getJustifiedBlock().executionPayloadBlockHash ?? ZERO_HASH_HEX;
Expand Down Expand Up @@ -608,7 +620,6 @@ export async function produceCommonBlockBody<T extends BlockType>(
? this.metrics?.executionBlockProductionTimeSteps
: this.metrics?.builderBlockProductionTimeSteps;

const blockEpoch = computeEpochAtSlot(slot);
const fork = currentState.config.getForkName(slot);

// TODO:
Expand Down Expand Up @@ -653,7 +664,7 @@ export async function produceCommonBlockBody<T extends BlockType>(
}

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
Expand Down
11 changes: 10 additions & 1 deletion packages/beacon-node/test/mocks/mockedBeaconChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -27,6 +27,7 @@ export type MockedBeaconChain = Mocked<BeaconChain> & {
eth1: Mocked<Eth1ForBlockProduction>;
opPool: Mocked<OpPool>;
aggregatedAttestationPool: Mocked<AggregatedAttestationPool>;
syncContributionAndProofPool: Mocked<SyncContributionAndProofPool>;
beaconProposerCache: Mocked<BeaconProposerCache>;
shufflingCache: Mocked<ShufflingCache>;
regen: Mocked<QueuedStateRegenerator>;
Expand Down Expand Up @@ -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,
};
});

Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit ba1d41b

Please sign in to comment.