@lodestar/beacon-node 1.48.0-dev.84db2dcfe4 → 1.48.0-dev.9b2790203a
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/blocks/importBlock.d.ts.map +1 -1
- package/lib/chain/blocks/importBlock.js +0 -13
- package/lib/chain/blocks/importBlock.js.map +1 -1
- package/lib/chain/blocks/utils/chainSegment.d.ts +1 -1
- package/lib/chain/blocks/utils/chainSegment.d.ts.map +1 -1
- package/lib/chain/blocks/utils/chainSegment.js +10 -1
- package/lib/chain/blocks/utils/chainSegment.js.map +1 -1
- package/lib/chain/chain.d.ts +5 -0
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +67 -38
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/emitter.d.ts +1 -1
- package/lib/chain/emitter.js +1 -1
- package/lib/chain/errors/gossipValidation.d.ts +2 -1
- package/lib/chain/errors/gossipValidation.d.ts.map +1 -1
- package/lib/chain/errors/gossipValidation.js +1 -0
- package/lib/chain/errors/gossipValidation.js.map +1 -1
- package/lib/chain/validatorMonitor.d.ts +7 -1
- package/lib/chain/validatorMonitor.d.ts.map +1 -1
- package/lib/chain/validatorMonitor.js +22 -5
- package/lib/chain/validatorMonitor.js.map +1 -1
- package/lib/execution/engine/mock.d.ts.map +1 -1
- package/lib/execution/engine/mock.js +4 -1
- package/lib/execution/engine/mock.js.map +1 -1
- package/lib/network/processor/index.d.ts.map +1 -1
- package/lib/network/processor/index.js +11 -0
- package/lib/network/processor/index.js.map +1 -1
- package/lib/network/reqresp/rateLimit.js +2 -1
- package/lib/network/reqresp/rateLimit.js.map +1 -1
- package/package.json +14 -14
- package/src/api/impl/validator/index.ts +44 -43
- package/src/chain/blocks/importBlock.ts +0 -13
- package/src/chain/blocks/utils/chainSegment.ts +10 -1
- package/src/chain/chain.ts +74 -46
- package/src/chain/emitter.ts +1 -1
- package/src/chain/errors/gossipValidation.ts +1 -0
- package/src/chain/validatorMonitor.ts +24 -7
- package/src/execution/engine/mock.ts +4 -1
- package/src/network/processor/index.ts +13 -0
- package/src/network/reqresp/rateLimit.ts +2 -1
|
@@ -22,7 +22,7 @@ export type ChainSegmentResult = {warnings: OrphanedPayloadEnvelope[] | null};
|
|
|
22
22
|
* - Verifies parent root + slot linearity
|
|
23
23
|
* - For gloas: verifies bid.parentBlockHash matches the tracked execution hash; if not, the
|
|
24
24
|
* previous FULL envelope is treated as orphaned (segment continues as if previous slot was EMPTY)
|
|
25
|
-
* - If an envelope exists for this slot: verifies it references this block's root
|
|
25
|
+
* - If an envelope exists for this slot (or the parent's slot): verifies it references this block's root
|
|
26
26
|
* - Advances the tracked execution hash (FULL if envelope present, EMPTY if not)
|
|
27
27
|
*/
|
|
28
28
|
export function assertLinearChainSegment(
|
|
@@ -48,6 +48,15 @@ export function assertLinearChainSegment(
|
|
|
48
48
|
if (parentBlock !== null) {
|
|
49
49
|
const parentPayloadInput = payloadEnvelopes?.get(parentBlock.slot);
|
|
50
50
|
if (parentPayloadInput?.hasPayloadEnvelope()) {
|
|
51
|
+
// Envelopes are served by slot, the one at the parent's slot must reference the parent block. Without this
|
|
52
|
+
// check an envelope of a sibling block is taken as orphaned and only fails downstream in the payload import
|
|
53
|
+
if (parentPayloadInput.blockRootHex !== parentBlock.blockRoot) {
|
|
54
|
+
throw new BlockError(blocks[0].getBlock(), {
|
|
55
|
+
code: BlockErrorCode.ENVELOPE_BLOCK_ROOT_MISMATCH,
|
|
56
|
+
envelopeBlockRoot: parentPayloadInput.blockRootHex,
|
|
57
|
+
blockRoot: parentBlock.blockRoot,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
51
60
|
const parentPayloadBlockHash = parentPayloadInput.getBlockHashHex();
|
|
52
61
|
if (currentExecHash === parentPayloadBlockHash) {
|
|
53
62
|
// Checkpoint-sync first batch: the anchor is stored PENDING with the inherited (grandparent)
|
package/src/chain/chain.ts
CHANGED
|
@@ -1271,59 +1271,65 @@ 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
|
+
}
|
|
1274
1283
|
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
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;
|
|
1280
1290
|
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
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
|
-
}
|
|
1291
|
+
if (!headRootChanged && prevHead.payloadStatus === head.payloadStatus) {
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1298
1294
|
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1295
|
+
try {
|
|
1296
|
+
const previousDutyDependentRoot = this.forkChoice.getDependentRoot(head, EpochDifference.previous);
|
|
1297
|
+
const currentDutyDependentRoot = this.forkChoice.getDependentRoot(head, EpochDifference.current);
|
|
1298
|
+
const epochTransition = computeStartSlotAtEpoch(computeEpochAtSlot(head.slot)) === head.slot;
|
|
1299
|
+
const executionOptimistic = isOptimisticBlock(head);
|
|
1300
|
+
|
|
1301
|
+
if (headRootChanged) {
|
|
1302
|
+
this.emitter.emit(routes.events.EventType.head, {
|
|
1303
|
+
block: head.blockRoot,
|
|
1304
|
+
epochTransition,
|
|
1305
|
+
slot: head.slot,
|
|
1306
|
+
state: head.stateRoot,
|
|
1307
|
+
previousDutyDependentRoot,
|
|
1308
|
+
currentDutyDependentRoot,
|
|
1309
|
+
executionOptimistic,
|
|
1311
1310
|
});
|
|
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
|
-
);
|
|
1319
1311
|
}
|
|
1320
1312
|
|
|
1321
|
-
|
|
1313
|
+
this.emitter.emit(routes.events.EventType.headV2, {
|
|
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
|
+
});
|
|
1322
1326
|
} catch (e) {
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
+
// getDependentRoot() may fail with error: "No block for root" as we can see in holesky non-finality issue
|
|
1328
|
+
this.logger.debug(
|
|
1329
|
+
"Error emitting head/head_v2 event",
|
|
1330
|
+
{slot: head.slot, root: head.blockRoot, headRootChanged},
|
|
1331
|
+
e as Error
|
|
1332
|
+
);
|
|
1327
1333
|
}
|
|
1328
1334
|
}
|
|
1329
1335
|
|
|
@@ -1612,7 +1618,10 @@ export class BeaconChain implements IBeaconChain {
|
|
|
1612
1618
|
this.processShutdownCallback(this.forkChoice.irrecoverableError);
|
|
1613
1619
|
}
|
|
1614
1620
|
|
|
1621
|
+
// updateTime() recomputes the head on epoch-boundary checkpoint pull-up and under fast confirmation
|
|
1622
|
+
const prevHead = this.forkChoice.getHead();
|
|
1615
1623
|
this.forkChoice.updateTime(slot);
|
|
1624
|
+
this.emitHeadEvents(prevHead, this.forkChoice.getHead());
|
|
1616
1625
|
this.metrics?.clockSlot.set(slot);
|
|
1617
1626
|
|
|
1618
1627
|
this.attestationPool.prune(slot);
|
|
@@ -1670,6 +1679,25 @@ export class BeaconChain implements IBeaconChain {
|
|
|
1670
1679
|
|
|
1671
1680
|
private async onForkChoiceFinalized(this: BeaconChain, cp: CheckpointWithHex): Promise<void> {
|
|
1672
1681
|
this.logger.verbose("Fork choice finalized", {epoch: cp.epoch, root: cp.rootHex});
|
|
1682
|
+
this.metrics?.finalizedEpoch.set(cp.epoch);
|
|
1683
|
+
const finalizedBlock = this.forkChoice.getBlockHexDefaultStatus(cp.rootHex);
|
|
1684
|
+
if (finalizedBlock) {
|
|
1685
|
+
// The callback runs synchronously inside fork choice checkpoint updates, defer writing to subscribers
|
|
1686
|
+
callInNextEventLoop(() => {
|
|
1687
|
+
this.emitter.emit(routes.events.EventType.finalizedCheckpoint, {
|
|
1688
|
+
block: cp.rootHex,
|
|
1689
|
+
epoch: cp.epoch,
|
|
1690
|
+
state: finalizedBlock.stateRoot,
|
|
1691
|
+
executionOptimistic: isOptimisticBlock(finalizedBlock),
|
|
1692
|
+
});
|
|
1693
|
+
});
|
|
1694
|
+
} else {
|
|
1695
|
+
this.logger.debug("Finalized block not found in fork choice, skip finalized_checkpoint event", {
|
|
1696
|
+
epoch: cp.epoch,
|
|
1697
|
+
root: cp.rootHex,
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1673
1701
|
const finalizedSlot = computeStartSlotAtEpoch(cp.epoch);
|
|
1674
1702
|
this.seenBlockProposers.prune(finalizedSlot);
|
|
1675
1703
|
|
package/src/chain/emitter.ts
CHANGED
|
@@ -33,7 +33,7 @@ export enum ChainEvent {
|
|
|
33
33
|
/**
|
|
34
34
|
* This event signals that the fork choice store has been updated.
|
|
35
35
|
*
|
|
36
|
-
* This event is guaranteed to be triggered whenever the fork choice
|
|
36
|
+
* This event is guaranteed to be triggered whenever the fork choice finalized checkpoint is updated. This is either in response to a newly processed block or a new clock tick.
|
|
37
37
|
*/
|
|
38
38
|
forkChoiceFinalized = "forkChoice:finalized",
|
|
39
39
|
/**
|
|
@@ -8,6 +8,7 @@ export enum GossipAction {
|
|
|
8
8
|
export enum GossipErrorCode {
|
|
9
9
|
INVALID_SERIALIZED_BYTES_ERROR_CODE = "GOSSIP_ERROR_INVALID_SERIALIZED_BYTES",
|
|
10
10
|
PAST_SLOT = "GOSSIP_ERROR_PAST_SLOT",
|
|
11
|
+
FUTURE_SLOT = "GOSSIP_ERROR_FUTURE_SLOT",
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export class GossipActionError<T extends {code: string}> extends LodestarError<T> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {ChainForkConfig} from "@lodestar/config";
|
|
2
|
-
import {MIN_ATTESTATION_INCLUSION_DELAY, SLOTS_PER_EPOCH} from "@lodestar/params";
|
|
2
|
+
import {MIN_ATTESTATION_INCLUSION_DELAY, SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params";
|
|
3
3
|
import {
|
|
4
4
|
IBeaconStateView,
|
|
5
5
|
ParticipationFlags,
|
|
@@ -1117,7 +1117,11 @@ function isCanonical(rootCache: RootHexCache, block: AttestationBlockInclusion):
|
|
|
1117
1117
|
|
|
1118
1118
|
/** Returns true if root at slot is the same at slot - 1 == there was no new block at slot */
|
|
1119
1119
|
function isMissedSlot(rootCache: RootHexCache, slot: Slot): boolean {
|
|
1120
|
-
|
|
1120
|
+
if (slot <= 0) {
|
|
1121
|
+
return false;
|
|
1122
|
+
}
|
|
1123
|
+
const root = rootCache.getBlockRootAtSlot(slot);
|
|
1124
|
+
return root !== null && root === rootCache.getBlockRootAtSlot(slot - 1);
|
|
1121
1125
|
}
|
|
1122
1126
|
|
|
1123
1127
|
function renderBlockProposalSummary(
|
|
@@ -1131,7 +1135,11 @@ function renderBlockProposalSummary(
|
|
|
1131
1135
|
return "not_submitted";
|
|
1132
1136
|
}
|
|
1133
1137
|
|
|
1134
|
-
|
|
1138
|
+
const canonicalRoot = rootCache.getBlockRootAtSlot(proposalSlot);
|
|
1139
|
+
if (canonicalRoot === null) {
|
|
1140
|
+
return "unknown";
|
|
1141
|
+
}
|
|
1142
|
+
if (canonicalRoot === proposal.blockRoot) {
|
|
1135
1143
|
// Canonical state includes our block
|
|
1136
1144
|
return "canonical";
|
|
1137
1145
|
}
|
|
@@ -1157,14 +1165,23 @@ function renderBlockProposalSummary(
|
|
|
1157
1165
|
* In normal network conditions the same root is read multiple times, specially the target.
|
|
1158
1166
|
*/
|
|
1159
1167
|
export class RootHexCache {
|
|
1160
|
-
private readonly blockRootSlotCache = new Map<Slot, RootHex>();
|
|
1168
|
+
private readonly blockRootSlotCache = new Map<Slot, RootHex | null>();
|
|
1161
1169
|
|
|
1162
1170
|
constructor(private readonly state: IBeaconStateView) {}
|
|
1163
1171
|
|
|
1164
|
-
|
|
1172
|
+
/**
|
|
1173
|
+
* Block root at `slot`, null if the state does not cover it: slots at or after the state's own slot (an inclusion
|
|
1174
|
+
* in a block the head state does not know yet, e.g. an orphaned block, or the slot after the last attestation of
|
|
1175
|
+
* the epoch) or slots older than `SLOTS_PER_HISTORICAL_ROOT`. Callers treat null as unknown instead of throwing
|
|
1176
|
+
* and aborting the summaries of all remaining validators.
|
|
1177
|
+
*/
|
|
1178
|
+
getBlockRootAtSlot(slot: Slot): RootHex | null {
|
|
1165
1179
|
let root = this.blockRootSlotCache.get(slot);
|
|
1166
|
-
if (
|
|
1167
|
-
root =
|
|
1180
|
+
if (root === undefined) {
|
|
1181
|
+
root =
|
|
1182
|
+
slot < this.state.slot && slot >= this.state.slot - SLOTS_PER_HISTORICAL_ROOT
|
|
1183
|
+
? toRootHex(this.state.getBlockRootAtSlot(slot))
|
|
1184
|
+
: null;
|
|
1168
1185
|
this.blockRootSlotCache.set(slot, root);
|
|
1169
1186
|
}
|
|
1170
1187
|
return root;
|
|
@@ -296,7 +296,10 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
|
|
|
296
296
|
|
|
297
297
|
// 5. Client software MUST update its forkchoice state if payloads referenced by forkchoiceState.headBlockHash and
|
|
298
298
|
// forkchoiceState.finalizedBlockHash are VALID.
|
|
299
|
-
|
|
299
|
+
//
|
|
300
|
+
// A zero finalizedBlockHash means "no finalized execution block" (e.g. the finalized checkpoint has no execution
|
|
301
|
+
// payload, pre-merge/pre-TTD). Real EL clients accept this, so the mock must not treat it as an unknown block.
|
|
302
|
+
if (finalizedBlockHash !== ZERO_HASH_HEX && !this.validBlocks.has(finalizedBlockHash)) {
|
|
300
303
|
throw Error(`Unknown finalizedBlockHash ${finalizedBlockHash}`);
|
|
301
304
|
}
|
|
302
305
|
this.headBlockHash = headBlockHash;
|
|
@@ -360,6 +360,19 @@ export class NetworkProcessor {
|
|
|
360
360
|
return;
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
+
// DOS protection: drop far-future messages before allocating any unknown-root tracking entry.
|
|
364
|
+
// Bound each topic to what its gossip validator accepts; only execution_payload_bid accepts the next slot.
|
|
365
|
+
const latestPermissableSlot =
|
|
366
|
+
this.chain.clock.currentSlotWithGossipDisparity + (topicType === GossipType.execution_payload_bid ? 1 : 0);
|
|
367
|
+
if (slot > latestPermissableSlot) {
|
|
368
|
+
// No need to report the dropped job to gossip. It will be eventually pruned from the mcache
|
|
369
|
+
this.metrics?.networkProcessor.gossipValidationError.inc({
|
|
370
|
+
topic: topicType,
|
|
371
|
+
error: GossipErrorCode.FUTURE_SLOT,
|
|
372
|
+
});
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
|
|
363
376
|
message.msgSlot = slot;
|
|
364
377
|
|
|
365
378
|
// this determines whether this message needs to wait for a Block or Envelope
|
|
@@ -126,7 +126,8 @@ function getRequestCountFn<T extends ReqRespMethod>(
|
|
|
126
126
|
const type = requestSszTypeByMethod(fork, config)[method];
|
|
127
127
|
return (reqData: Uint8Array) => {
|
|
128
128
|
try {
|
|
129
|
-
|
|
129
|
+
// A schema-valid request can cost 0 tokens; floor to 1 so it stays charged and bannable, not free.
|
|
130
|
+
return Math.max(1, (type && fn(type.deserialize(reqData))) ?? 1);
|
|
130
131
|
} catch (_e) {
|
|
131
132
|
return 1;
|
|
132
133
|
}
|