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

chore: log sync aggregate participants when producing beacon block body #7300

Merged
merged 3 commits into from
Dec 15, 2024
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
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) {
Copy link
Member Author

@nflaig nflaig Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required so we properly call this post altair, also using the epoch is not something we do a lot, the change shouldn't make a difference and we save a bit not having to calculate block epoch

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
Loading