@lodestar/beacon-node 1.48.0-dev.2948e4a2af → 1.48.0-dev.30d2b0bf52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +39 -39
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/chain.d.ts +0 -5
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +38 -48
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +64 -46
- package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
- package/package.json +14 -14
- package/src/api/impl/validator/index.ts +43 -44
- package/src/chain/chain.ts +46 -55
- package/src/chain/produceBlock/produceBlockBody.ts +71 -50
|
@@ -133,37 +133,40 @@ type BidCandidate = {
|
|
|
133
133
|
};
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
136
|
+
* Return the best bid by boosted total payment. A candidate with the max boost factor is
|
|
137
|
+
* preferred over any other regardless of value, ties prefer a builder api bid over the
|
|
138
|
+
* p2p bid, and the earlier received bid between builder api bids.
|
|
138
139
|
*/
|
|
139
|
-
function
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
140
|
+
function selectBestBid(candidates: BidCandidate[]): BidCandidate | null {
|
|
141
|
+
const boostedValue = ({totalGwei, boostFactor}: BidCandidate): bigint => boostFactor * totalGwei;
|
|
142
|
+
let best: BidCandidate | null = null;
|
|
143
|
+
for (const candidate of candidates) {
|
|
144
|
+
if (best === null) {
|
|
145
|
+
best = candidate;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
// Preserve max boost preference before comparing bid values
|
|
149
|
+
const candidateIsMaxBoost = candidate.boostFactor === MAX_BUILDER_BOOST_FACTOR;
|
|
150
|
+
const bestIsMaxBoost = best.boostFactor === MAX_BUILDER_BOOST_FACTOR;
|
|
151
|
+
if (candidateIsMaxBoost !== bestIsMaxBoost) {
|
|
152
|
+
if (candidateIsMaxBoost) {
|
|
153
|
+
best = candidate;
|
|
154
|
+
}
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const candidateValue = boostedValue(candidate);
|
|
158
|
+
const bestValue = boostedValue(best);
|
|
159
|
+
if (candidateValue > bestValue) {
|
|
160
|
+
best = candidate;
|
|
161
|
+
} else if (
|
|
162
|
+
candidateValue === bestValue &&
|
|
163
|
+
// A tie prefers a builder api bid over the p2p bid, and the earlier received bid otherwise
|
|
164
|
+
(best.url === undefined || (candidate.url !== undefined && candidate.receivedMs < best.receivedMs))
|
|
165
|
+
) {
|
|
166
|
+
best = candidate;
|
|
167
|
+
}
|
|
163
168
|
}
|
|
164
|
-
|
|
165
|
-
// and the earlier received bid between builder api bids
|
|
166
|
-
return a.receivedMs - b.receivedMs;
|
|
169
|
+
return best;
|
|
167
170
|
}
|
|
168
171
|
|
|
169
172
|
type ProduceBlockContentsRes = {executionPayloadValue: Wei; consensusBlockValue: Wei} & {
|
|
@@ -1046,24 +1049,20 @@ export function getValidatorApi(
|
|
|
1046
1049
|
});
|
|
1047
1050
|
}
|
|
1048
1051
|
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
const rankedCandidates = candidates.toSorted(compareBidCandidates);
|
|
1054
|
-
for (const [index, candidate] of rankedCandidates.entries()) {
|
|
1055
|
-
logger.debug("Builder bid candidate", {
|
|
1052
|
+
const best = selectBestBid(candidates);
|
|
1053
|
+
if (candidates.length > 0) {
|
|
1054
|
+
logger.debug("Ranked builder bid candidates", {
|
|
1056
1055
|
slot,
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1056
|
+
candidates: candidates
|
|
1057
|
+
.map(
|
|
1058
|
+
(candidate) =>
|
|
1059
|
+
`${candidate.url ?? "p2p"}:total=${prettyGweiToEth(candidate.totalGwei)}:boost=${candidate.boostFactor}:received=${candidate.receivedMs}ms`
|
|
1060
|
+
)
|
|
1061
|
+
.join(","),
|
|
1062
|
+
bidSource: best?.url ?? "p2p",
|
|
1064
1063
|
});
|
|
1065
1064
|
}
|
|
1066
|
-
return
|
|
1065
|
+
return best;
|
|
1067
1066
|
})();
|
|
1068
1067
|
|
|
1069
1068
|
const commonBlockBodyPromise = chain.produceCommonBlockBody({
|
package/src/chain/chain.ts
CHANGED
|
@@ -1271,65 +1271,59 @@ export class BeaconChain implements IBeaconChain {
|
|
|
1271
1271
|
try {
|
|
1272
1272
|
const prevHead = this.forkChoice.getHead();
|
|
1273
1273
|
const head = this.forkChoice.updateAndGetHead({mode: UpdateHeadOpt.GetCanonicalHead}).head;
|
|
1274
|
-
this.emitHeadEvents(prevHead, head);
|
|
1275
|
-
return head;
|
|
1276
|
-
} catch (e) {
|
|
1277
|
-
this.metrics?.forkChoice.errors.inc({entrypoint: UpdateHeadOpt.GetCanonicalHead});
|
|
1278
|
-
throw e;
|
|
1279
|
-
} finally {
|
|
1280
|
-
timer?.();
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
1274
|
|
|
1284
|
-
|
|
1285
|
-
* Emit `head` and `head_v2` when the fork choice head differs between two observations. Every caller that
|
|
1286
|
-
* can move the head, `updateAndGetHead()` and `updateTime()`, must capture the head before and pass both.
|
|
1287
|
-
*/
|
|
1288
|
-
private emitHeadEvents(prevHead: ProtoBlock, head: ProtoBlock): void {
|
|
1289
|
-
const headRootChanged = head.blockRoot !== prevHead.blockRoot;
|
|
1275
|
+
const headRootChanged = head.blockRoot !== prevHead.blockRoot;
|
|
1290
1276
|
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1277
|
+
if (!headRootChanged && prevHead.payloadStatus === head.payloadStatus) {
|
|
1278
|
+
return head;
|
|
1279
|
+
}
|
|
1294
1280
|
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1281
|
+
try {
|
|
1282
|
+
const previousDutyDependentRoot = this.forkChoice.getDependentRoot(head, EpochDifference.previous);
|
|
1283
|
+
const currentDutyDependentRoot = this.forkChoice.getDependentRoot(head, EpochDifference.current);
|
|
1284
|
+
const epochTransition = computeStartSlotAtEpoch(computeEpochAtSlot(head.slot)) === head.slot;
|
|
1285
|
+
const executionOptimistic = isOptimisticBlock(head);
|
|
1286
|
+
|
|
1287
|
+
if (headRootChanged) {
|
|
1288
|
+
this.emitter.emit(routes.events.EventType.head, {
|
|
1289
|
+
block: head.blockRoot,
|
|
1290
|
+
epochTransition,
|
|
1291
|
+
slot: head.slot,
|
|
1292
|
+
state: head.stateRoot,
|
|
1293
|
+
previousDutyDependentRoot,
|
|
1294
|
+
currentDutyDependentRoot,
|
|
1295
|
+
executionOptimistic,
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
this.emitter.emit(routes.events.EventType.headV2, {
|
|
1300
|
+
version: this.config.getForkName(head.slot),
|
|
1301
|
+
data: {
|
|
1302
|
+
slot: head.slot,
|
|
1303
|
+
block: head.blockRoot,
|
|
1304
|
+
state: head.stateRoot,
|
|
1305
|
+
payloadStatus: head.payloadStatus === PayloadStatus.FULL ? "full" : "empty",
|
|
1306
|
+
epochTransition,
|
|
1307
|
+
currentEpochDependentRoot: previousDutyDependentRoot,
|
|
1308
|
+
nextEpochDependentRoot: currentDutyDependentRoot,
|
|
1309
|
+
executionOptimistic,
|
|
1310
|
+
},
|
|
1310
1311
|
});
|
|
1312
|
+
} catch (e) {
|
|
1313
|
+
// getDependentRoot() may fail with error: "No block for root" as we can see in holesky non-finality issue
|
|
1314
|
+
this.logger.debug(
|
|
1315
|
+
"Error emitting head/head_v2 event",
|
|
1316
|
+
{slot: head.slot, root: head.blockRoot, headRootChanged},
|
|
1317
|
+
e as Error
|
|
1318
|
+
);
|
|
1311
1319
|
}
|
|
1312
1320
|
|
|
1313
|
-
|
|
1314
|
-
version: this.config.getForkName(head.slot),
|
|
1315
|
-
data: {
|
|
1316
|
-
slot: head.slot,
|
|
1317
|
-
block: head.blockRoot,
|
|
1318
|
-
state: head.stateRoot,
|
|
1319
|
-
payloadStatus: head.payloadStatus === PayloadStatus.FULL ? "full" : "empty",
|
|
1320
|
-
epochTransition,
|
|
1321
|
-
currentEpochDependentRoot: previousDutyDependentRoot,
|
|
1322
|
-
nextEpochDependentRoot: currentDutyDependentRoot,
|
|
1323
|
-
executionOptimistic,
|
|
1324
|
-
},
|
|
1325
|
-
});
|
|
1321
|
+
return head;
|
|
1326
1322
|
} catch (e) {
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
e as Error
|
|
1332
|
-
);
|
|
1323
|
+
this.metrics?.forkChoice.errors.inc({entrypoint: UpdateHeadOpt.GetCanonicalHead});
|
|
1324
|
+
throw e;
|
|
1325
|
+
} finally {
|
|
1326
|
+
timer?.();
|
|
1333
1327
|
}
|
|
1334
1328
|
}
|
|
1335
1329
|
|
|
@@ -1618,10 +1612,7 @@ export class BeaconChain implements IBeaconChain {
|
|
|
1618
1612
|
this.processShutdownCallback(this.forkChoice.irrecoverableError);
|
|
1619
1613
|
}
|
|
1620
1614
|
|
|
1621
|
-
// updateTime() recomputes the head on epoch-boundary checkpoint pull-up and under fast confirmation
|
|
1622
|
-
const prevHead = this.forkChoice.getHead();
|
|
1623
1615
|
this.forkChoice.updateTime(slot);
|
|
1624
|
-
this.emitHeadEvents(prevHead, this.forkChoice.getHead());
|
|
1625
1616
|
this.metrics?.clockSlot.set(slot);
|
|
1626
1617
|
|
|
1627
1618
|
this.attestationPool.prune(slot);
|
|
@@ -528,18 +528,23 @@ export async function produceBlockBody<T extends BlockType>(
|
|
|
528
528
|
}
|
|
529
529
|
}
|
|
530
530
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
531
|
+
if (ForkSeq[fork] >= ForkSeq.deneb) {
|
|
532
|
+
const {blobKzgCommitments} = builderRes;
|
|
533
|
+
if (blobKzgCommitments === undefined) {
|
|
534
|
+
throw Error(`Invalid builder getHeader response for fork=${fork}, missing blobKzgCommitments`);
|
|
535
|
+
}
|
|
535
536
|
|
|
536
|
-
|
|
537
|
-
|
|
537
|
+
(blockBody as deneb.BlindedBeaconBlockBody).blobKzgCommitments = blobKzgCommitments;
|
|
538
|
+
Object.assign(logMeta, {blobs: blobKzgCommitments.length});
|
|
539
|
+
}
|
|
538
540
|
|
|
539
|
-
if (
|
|
540
|
-
|
|
541
|
+
if (ForkSeq[fork] >= ForkSeq.electra) {
|
|
542
|
+
const {executionRequests} = builderRes;
|
|
543
|
+
if (executionRequests === undefined) {
|
|
544
|
+
throw Error(`Invalid builder getHeader response for fork=${fork}, missing executionRequests`);
|
|
545
|
+
}
|
|
546
|
+
(blockBody as electra.BlindedBeaconBlockBody).executionRequests = executionRequests;
|
|
541
547
|
}
|
|
542
|
-
(blockBody as BlindedBeaconBlockBody<ForkName.fulu>).executionRequests = executionRequests;
|
|
543
548
|
}
|
|
544
549
|
|
|
545
550
|
// blockType === BlockType.Full
|
|
@@ -894,38 +899,45 @@ function preparePayloadAttributes(
|
|
|
894
899
|
): SSEPayloadAttributes["payloadAttributes"] {
|
|
895
900
|
const timestamp = computeTimeAtSlot(chain.config, prepareSlot, prepareState.genesisTime);
|
|
896
901
|
const prevRandao = prepareState.getRandaoMix(prepareState.epoch);
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
902
|
+
const payloadAttributes = {
|
|
903
|
+
timestamp,
|
|
904
|
+
prevRandao,
|
|
905
|
+
suggestedFeeRecipient: feeRecipient,
|
|
906
|
+
};
|
|
900
907
|
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
908
|
+
if (ForkSeq[fork] >= ForkSeq.capella) {
|
|
909
|
+
if (!isStatePostCapella(prepareState)) {
|
|
910
|
+
throw new Error("Expected Capella state for withdrawals");
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
if (isStatePostGloas(prepareState)) {
|
|
914
|
+
const isExtendingPayload = byteArrayEquals(parentBlockHash, prepareState.latestExecutionPayloadBid.blockHash);
|
|
915
|
+
if (isExtendingPayload) {
|
|
916
|
+
// applyParentExecutionPayload sets latestBlockHash = parentBid.blockHash, so a mismatch
|
|
917
|
+
// here means the caller did not apply parent payload to prepareState
|
|
918
|
+
if (!byteArrayEquals(prepareState.latestBlockHash, prepareState.latestExecutionPayloadBid.blockHash)) {
|
|
919
|
+
throw new Error("Expected state with parent execution payload applied for withdrawals");
|
|
920
|
+
}
|
|
921
|
+
(payloadAttributes as capella.SSEPayloadAttributes["payloadAttributes"]).withdrawals =
|
|
922
|
+
prepareState.getExpectedWithdrawals().expectedWithdrawals;
|
|
923
|
+
} else {
|
|
924
|
+
// When the parent block is empty, state.payloadExpectedWithdrawals holds a batch
|
|
925
|
+
// already deducted from CL balances but never credited on the EL (the envelope
|
|
926
|
+
// was not delivered). The next payload must carry those same withdrawals to
|
|
927
|
+
// restore CL/EL consistency, otherwise validators permanently lose that balance.
|
|
928
|
+
(payloadAttributes as capella.SSEPayloadAttributes["payloadAttributes"]).withdrawals =
|
|
929
|
+
prepareState.payloadExpectedWithdrawals;
|
|
909
930
|
}
|
|
910
|
-
withdrawals = prepareState.getExpectedWithdrawals().expectedWithdrawals;
|
|
911
931
|
} else {
|
|
912
|
-
//
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
// restore CL/EL consistency, otherwise validators permanently lose that balance.
|
|
916
|
-
withdrawals = prepareState.payloadExpectedWithdrawals;
|
|
932
|
+
// withdrawals logic is now fork aware as it changes on electra fork post capella
|
|
933
|
+
(payloadAttributes as capella.SSEPayloadAttributes["payloadAttributes"]).withdrawals =
|
|
934
|
+
prepareState.getExpectedWithdrawals().expectedWithdrawals;
|
|
917
935
|
}
|
|
918
|
-
} else {
|
|
919
|
-
withdrawals = prepareState.getExpectedWithdrawals().expectedWithdrawals;
|
|
920
936
|
}
|
|
921
937
|
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
suggestedFeeRecipient: feeRecipient,
|
|
926
|
-
withdrawals,
|
|
927
|
-
parentBeaconBlockRoot: parentBlockRoot,
|
|
928
|
-
};
|
|
938
|
+
if (ForkSeq[fork] >= ForkSeq.deneb) {
|
|
939
|
+
(payloadAttributes as deneb.SSEPayloadAttributes["payloadAttributes"]).parentBeaconBlockRoot = parentBlockRoot;
|
|
940
|
+
}
|
|
929
941
|
|
|
930
942
|
if (ForkSeq[fork] >= ForkSeq.gloas) {
|
|
931
943
|
if (!isStatePostGloas(prepareState)) {
|
|
@@ -1038,28 +1050,37 @@ export async function produceCommonBlockBody<T extends BlockType>(
|
|
|
1038
1050
|
step: BlockProductionStep.attestations,
|
|
1039
1051
|
});
|
|
1040
1052
|
|
|
1041
|
-
const
|
|
1042
|
-
const parentBlockRoot = fromHex(parentBlock.blockRoot);
|
|
1043
|
-
const previousSlot = slot - 1;
|
|
1044
|
-
const syncAggregate = this.syncContributionAndProofPool.getAggregate(previousSlot, parentBlockRoot);
|
|
1045
|
-
this.metrics?.production.producedSyncAggregateParticipants.observe(
|
|
1046
|
-
syncAggregate.syncCommitteeBits.getTrueBitIndexes().length
|
|
1047
|
-
);
|
|
1048
|
-
endSyncAggregate?.({
|
|
1049
|
-
step: BlockProductionStep.syncAggregate,
|
|
1050
|
-
});
|
|
1051
|
-
|
|
1052
|
-
// Live proposal production is supported from Fulu onward.
|
|
1053
|
-
return {
|
|
1053
|
+
const blockBody: Omit<CommonBlockBody, "blsToExecutionChanges" | "syncAggregate"> = {
|
|
1054
1054
|
randaoReveal,
|
|
1055
1055
|
graffiti,
|
|
1056
|
+
// Eth1 data voting is no longer required since electra
|
|
1056
1057
|
eth1Data: currentState.eth1Data,
|
|
1057
1058
|
proposerSlashings: this.opts.disableProposerSlashings === true ? [] : proposerSlashings,
|
|
1058
1059
|
attesterSlashings,
|
|
1059
1060
|
attestations,
|
|
1061
|
+
// Since electra, deposits are processed by the execution layer,
|
|
1062
|
+
// we no longer support handling deposits from earlier forks.
|
|
1060
1063
|
deposits: [],
|
|
1061
1064
|
voluntaryExits,
|
|
1062
|
-
blsToExecutionChanges,
|
|
1063
|
-
syncAggregate,
|
|
1064
1065
|
};
|
|
1066
|
+
|
|
1067
|
+
if (ForkSeq[fork] >= ForkSeq.capella) {
|
|
1068
|
+
(blockBody as CommonBlockBody).blsToExecutionChanges = blsToExecutionChanges;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
const endSyncAggregate = stepsMetrics?.startTimer();
|
|
1072
|
+
if (ForkSeq[fork] >= ForkSeq.altair) {
|
|
1073
|
+
const parentBlockRoot = fromHex(parentBlock.blockRoot);
|
|
1074
|
+
const previousSlot = slot - 1;
|
|
1075
|
+
const syncAggregate = this.syncContributionAndProofPool.getAggregate(previousSlot, parentBlockRoot);
|
|
1076
|
+
this.metrics?.production.producedSyncAggregateParticipants.observe(
|
|
1077
|
+
syncAggregate.syncCommitteeBits.getTrueBitIndexes().length
|
|
1078
|
+
);
|
|
1079
|
+
(blockBody as CommonBlockBody).syncAggregate = syncAggregate;
|
|
1080
|
+
}
|
|
1081
|
+
endSyncAggregate?.({
|
|
1082
|
+
step: BlockProductionStep.syncAggregate,
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
return blockBody as CommonBlockBody;
|
|
1065
1086
|
}
|