Skip to content

Commit 85f9e67

Browse files
authored
Merge b064b55 into 99794d3
2 parents 99794d3 + b064b55 commit 85f9e67

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import {ChainForkConfig} from "@lodestar/config";
2-
import {ForkExecution, ForkSeq, isForkExecution} from "@lodestar/params";
2+
import {ForkExecution, ForkSeq, isForkExecution, isForkLightClient} from "@lodestar/params";
33
import {
44
CachedBeaconStateAllForks,
55
CachedBeaconStateBellatrix,
66
CachedBeaconStateCapella,
77
CachedBeaconStateExecutions,
8-
computeEpochAtSlot,
98
computeTimeAtSlot,
109
getCurrentEpoch,
1110
getExpectedWithdrawals,
@@ -143,8 +142,15 @@ export async function produceBlockBody<T extends BlockType>(
143142
? Object.assign({}, commonBlockBody)
144143
: await produceCommonBlockBody.call(this, blockType, currentState, blockAttr);
145144

146-
const {attestations, deposits, voluntaryExits, attesterSlashings, proposerSlashings, blsToExecutionChanges} =
147-
blockBody;
145+
const {
146+
attestations,
147+
deposits,
148+
voluntaryExits,
149+
attesterSlashings,
150+
proposerSlashings,
151+
syncAggregate,
152+
blsToExecutionChanges,
153+
} = blockBody;
148154

149155
Object.assign(logMeta, {
150156
attestations: attestations.length,
@@ -154,6 +160,12 @@ export async function produceBlockBody<T extends BlockType>(
154160
proposerSlashings: proposerSlashings.length,
155161
});
156162

163+
if (isForkLightClient(fork)) {
164+
Object.assign(logMeta, {
165+
syncAggregateParticipants: syncAggregate.syncCommitteeBits.getTrueBitIndexes().length,
166+
});
167+
}
168+
157169
const endExecutionPayload = stepsMetrics?.startTimer();
158170
if (isForkExecution(fork)) {
159171
const safeBlockHash = this.forkChoice.getJustifiedBlock().executionPayloadBlockHash ?? ZERO_HASH_HEX;
@@ -608,7 +620,6 @@ export async function produceCommonBlockBody<T extends BlockType>(
608620
? this.metrics?.executionBlockProductionTimeSteps
609621
: this.metrics?.builderBlockProductionTimeSteps;
610622

611-
const blockEpoch = computeEpochAtSlot(slot);
612623
const fork = currentState.config.getForkName(slot);
613624

614625
// TODO:
@@ -653,7 +664,7 @@ export async function produceCommonBlockBody<T extends BlockType>(
653664
}
654665

655666
const endSyncAggregate = stepsMetrics?.startTimer();
656-
if (blockEpoch >= this.config.ALTAIR_FORK_EPOCH) {
667+
if (ForkSeq[fork] >= ForkSeq.altair) {
657668
const syncAggregate = this.syncContributionAndProofPool.getAggregate(parentSlot, parentBlockRoot);
658669
this.metrics?.production.producedSyncAggregateParticipants.observe(
659670
syncAggregate.syncCommitteeBits.getTrueBitIndexes().length

packages/beacon-node/test/mocks/mockedBeaconChain.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {BeaconProposerCache} from "../../src/chain/beaconProposerCache.js";
88
import {BeaconChain} from "../../src/chain/chain.js";
99
import {ChainEventEmitter} from "../../src/chain/emitter.js";
1010
import {LightClientServer} from "../../src/chain/lightClient/index.js";
11-
import {AggregatedAttestationPool, OpPool} from "../../src/chain/opPools/index.js";
11+
import {AggregatedAttestationPool, OpPool, SyncContributionAndProofPool} from "../../src/chain/opPools/index.js";
1212
import {QueuedStateRegenerator} from "../../src/chain/regen/index.js";
1313
import {ShufflingCache} from "../../src/chain/shufflingCache.js";
1414
import {Eth1ForBlockProduction} from "../../src/eth1/index.js";
@@ -27,6 +27,7 @@ export type MockedBeaconChain = Mocked<BeaconChain> & {
2727
eth1: Mocked<Eth1ForBlockProduction>;
2828
opPool: Mocked<OpPool>;
2929
aggregatedAttestationPool: Mocked<AggregatedAttestationPool>;
30+
syncContributionAndProofPool: Mocked<SyncContributionAndProofPool>;
3031
beaconProposerCache: Mocked<BeaconProposerCache>;
3132
shufflingCache: Mocked<ShufflingCache>;
3233
regen: Mocked<QueuedStateRegenerator>;
@@ -94,10 +95,17 @@ vi.mock("../../src/chain/opPools/index.js", async (importActual) => {
9495
};
9596
});
9697

98+
const SyncContributionAndProofPool = vi.fn().mockImplementation(() => {
99+
return {
100+
getAggregate: vi.fn(),
101+
};
102+
});
103+
97104
return {
98105
...mod,
99106
OpPool,
100107
AggregatedAttestationPool,
108+
SyncContributionAndProofPool,
101109
};
102110
});
103111

@@ -124,6 +132,7 @@ vi.mock("../../src/chain/chain.js", async (importActual) => {
124132
eth1: new Eth1ForBlockProduction(),
125133
opPool: new OpPool(),
126134
aggregatedAttestationPool: new AggregatedAttestationPool(config),
135+
syncContributionAndProofPool: new SyncContributionAndProofPool(),
127136
// @ts-expect-error
128137
beaconProposerCache: new BeaconProposerCache(),
129138
shufflingCache: new ShufflingCache(),

packages/beacon-node/test/unit/api/impl/validator/produceBlockV2.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {fromHexString, toHexString} from "@chainsafe/ssz";
22
import {ProtoBlock} from "@lodestar/fork-choice";
33
import {ForkName} from "@lodestar/params";
4-
import {CachedBeaconStateBellatrix, computeTimeAtSlot} from "@lodestar/state-transition";
4+
import {CachedBeaconStateBellatrix, G2_POINT_AT_INFINITY, computeTimeAtSlot} from "@lodestar/state-transition";
55
import {ssz} from "@lodestar/types";
66
import {afterEach, beforeEach, describe, expect, it, vi} from "vitest";
77
import {getValidatorApi} from "../../../../../src/api/impl/validator/index.js";
@@ -99,6 +99,10 @@ describe("api/validator - produceBlockV2", () => {
9999
eth1Data: ssz.phase0.Eth1Data.defaultValue(),
100100
deposits: [],
101101
});
102+
modules.chain["syncContributionAndProofPool"].getAggregate.mockReturnValue({
103+
syncCommitteeBits: ssz.altair.SyncCommitteeBits.defaultValue(),
104+
syncCommitteeSignature: G2_POINT_AT_INFINITY,
105+
});
102106
modules.forkChoice.getJustifiedBlock.mockReturnValue({} as ProtoBlock);
103107
modules.forkChoice.getFinalizedBlock.mockReturnValue({} as ProtoBlock);
104108

0 commit comments

Comments
 (0)