@lodestar/beacon-node 2.0.0 → 2.1.0-dev.04f41d12f7
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/rest/base.d.ts.map +1 -1
- package/lib/api/rest/base.js +1 -1
- package/lib/api/rest/base.js.map +1 -1
- package/lib/chain/blocks/importBlock.d.ts.map +1 -1
- package/lib/chain/blocks/importBlock.js +14 -5
- package/lib/chain/blocks/importBlock.js.map +1 -1
- package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
- package/lib/chain/blocks/importExecutionPayload.js +4 -2
- package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +17 -3
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/errors/executionPayloadBid.d.ts +5 -0
- package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
- package/lib/chain/errors/executionPayloadBid.js +1 -0
- package/lib/chain/errors/executionPayloadBid.js.map +1 -1
- package/lib/chain/forkChoice/index.d.ts +11 -2
- package/lib/chain/forkChoice/index.d.ts.map +1 -1
- package/lib/chain/forkChoice/index.js +181 -13
- package/lib/chain/forkChoice/index.js.map +1 -1
- package/lib/chain/opPools/opPool.d.ts +9 -3
- package/lib/chain/opPools/opPool.d.ts.map +1 -1
- package/lib/chain/opPools/opPool.js +22 -16
- package/lib/chain/opPools/opPool.js.map +1 -1
- package/lib/chain/options.js +1 -1
- package/lib/chain/options.js.map +1 -1
- package/lib/chain/seenCache/seenGossipBlockInput.js +1 -1
- package/lib/chain/seenCache/seenGossipBlockInput.js.map +1 -1
- package/lib/chain/validation/block.d.ts.map +1 -1
- package/lib/chain/validation/block.js +8 -5
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/chain/validation/executionPayloadBid.js +11 -1
- package/lib/chain/validation/executionPayloadBid.js.map +1 -1
- package/lib/chain/validation/payloadAttestationMessage.js +2 -2
- package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
- package/lib/chain/validation/proposerSlashing.js +5 -1
- package/lib/chain/validation/proposerSlashing.js.map +1 -1
- package/lib/network/network.js +6 -6
- package/lib/network/network.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +9 -7
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +3 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
- package/lib/sync/range/batch.d.ts.map +1 -1
- package/lib/sync/range/batch.js +5 -1
- package/lib/sync/range/batch.js.map +1 -1
- package/lib/sync/range/range.d.ts.map +1 -1
- package/lib/sync/range/range.js +5 -1
- package/lib/sync/range/range.js.map +1 -1
- package/lib/util/sszBytes.d.ts.map +1 -1
- package/lib/util/sszBytes.js +6 -4
- package/lib/util/sszBytes.js.map +1 -1
- package/package.json +17 -17
- package/src/api/rest/base.ts +5 -1
- package/src/chain/blocks/importBlock.ts +14 -7
- package/src/chain/blocks/importExecutionPayload.ts +4 -2
- package/src/chain/chain.ts +17 -3
- package/src/chain/errors/executionPayloadBid.ts +6 -0
- package/src/chain/forkChoice/index.ts +235 -13
- package/src/chain/opPools/opPool.ts +27 -16
- package/src/chain/options.ts +1 -1
- package/src/chain/seenCache/seenGossipBlockInput.ts +1 -1
- package/src/chain/validation/block.ts +8 -5
- package/src/chain/validation/executionPayloadBid.ts +15 -6
- package/src/chain/validation/payloadAttestationMessage.ts +2 -2
- package/src/chain/validation/proposerSlashing.ts +5 -1
- package/src/network/network.ts +6 -6
- package/src/network/processor/gossipHandlers.ts +12 -7
- package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +4 -1
- package/src/sync/range/batch.ts +5 -1
- package/src/sync/range/range.ts +7 -1
- package/src/util/sszBytes.ts +7 -8
package/src/chain/chain.ts
CHANGED
|
@@ -501,12 +501,14 @@ export class BeaconChain implements IBeaconChain {
|
|
|
501
501
|
});
|
|
502
502
|
|
|
503
503
|
const anchorBlockSlot = anchorState.latestBlockHeader.slot;
|
|
504
|
-
|
|
504
|
+
const anchorBlockFork = config.getForkName(anchorBlockSlot);
|
|
505
|
+
// A pre-Gloas anchor in a state upgraded to Gloas carried its own payload, no envelope follows it
|
|
506
|
+
if (isStatePostGloas(anchorState) && anchorBlockSlot > 0 && isForkPostGloas(anchorBlockFork)) {
|
|
505
507
|
const anchorBid = anchorState.latestExecutionPayloadBid;
|
|
506
508
|
this.seenPayloadEnvelopeInputCache.addFromBid({
|
|
507
509
|
blockRootHex: toRootHex(checkpoint.root),
|
|
508
510
|
slot: anchorBlockSlot,
|
|
509
|
-
forkName:
|
|
511
|
+
forkName: anchorBlockFork,
|
|
510
512
|
proposerIndex: anchorState.latestBlockHeader.proposerIndex,
|
|
511
513
|
bid: anchorBid,
|
|
512
514
|
sampledColumns: this.custodyConfig.sampledColumns,
|
|
@@ -2050,7 +2052,19 @@ export class BeaconChain implements IBeaconChain {
|
|
|
2050
2052
|
}
|
|
2051
2053
|
|
|
2052
2054
|
if (headState) {
|
|
2053
|
-
|
|
2055
|
+
// The finalized checkpoint state may be loaded from disk, it is only needed to prune voluntary exits
|
|
2056
|
+
let finalizedState: IBeaconStateView | Uint8Array | null = null;
|
|
2057
|
+
if (this.opPool.voluntaryExitsSize > 0) {
|
|
2058
|
+
finalizedState = await this.regen.getCheckpointStateOrBytes({epoch: cp.epoch, rootHex: cp.rootHex});
|
|
2059
|
+
if (finalizedState === null) {
|
|
2060
|
+
// A newer finalization can prune this checkpoint state while this handler awaits, its handler prunes exits
|
|
2061
|
+
this.logger.debug("Finalized checkpoint state not available, skip pruning voluntary exits", {
|
|
2062
|
+
epoch: cp.epoch,
|
|
2063
|
+
root: cp.rootHex,
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
this.opPool.pruneAll(blockResult.block, headState, finalizedState);
|
|
2054
2068
|
}
|
|
2055
2069
|
|
|
2056
2070
|
if (headState === null) {
|
|
@@ -22,6 +22,7 @@ export enum ExecutionPayloadBidErrorCode {
|
|
|
22
22
|
PROPOSER_PREFERENCES_FEE_RECIPIENT_MISMATCH = "EXECUTION_PAYLOAD_BID_ERROR_PROPOSER_PREFERENCES_FEE_RECIPIENT_MISMATCH",
|
|
23
23
|
PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH = "EXECUTION_PAYLOAD_BID_ERROR_PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH",
|
|
24
24
|
INCLUSION_LIST_BITS_NOT_INCLUSIVE = "EXECUTION_PAYLOAD_BID_ERROR_INCLUSION_LIST_BITS_NOT_INCLUSIVE",
|
|
25
|
+
UNKNOWN_INCLUSION_LIST_DEPENDENT_ROOT = "EXECUTION_PAYLOAD_BID_ERROR_UNKNOWN_INCLUSION_LIST_DEPENDENT_ROOT",
|
|
25
26
|
BEFORE_INCLUSION_LIST_DEADLINE = "EXECUTION_PAYLOAD_BID_ERROR_BEFORE_INCLUSION_LIST_DEADLINE",
|
|
26
27
|
BEFORE_PAYLOAD_ATTESTATION_DEADLINE = "EXECUTION_PAYLOAD_BID_ERROR_BEFORE_PAYLOAD_ATTESTATION_DEADLINE",
|
|
27
28
|
}
|
|
@@ -95,6 +96,11 @@ export type ExecutionPayloadBidErrorType =
|
|
|
95
96
|
builderIndex: BuilderIndex;
|
|
96
97
|
slot: Slot;
|
|
97
98
|
}
|
|
99
|
+
| {
|
|
100
|
+
code: ExecutionPayloadBidErrorCode.UNKNOWN_INCLUSION_LIST_DEPENDENT_ROOT;
|
|
101
|
+
slot: Slot;
|
|
102
|
+
parentBlockRoot: RootHex;
|
|
103
|
+
}
|
|
98
104
|
| {
|
|
99
105
|
code: ExecutionPayloadBidErrorCode.BEFORE_INCLUSION_LIST_DEADLINE;
|
|
100
106
|
builderIndex: BuilderIndex;
|
|
@@ -5,28 +5,33 @@ import {
|
|
|
5
5
|
ForkChoice,
|
|
6
6
|
ForkChoiceStateGetter,
|
|
7
7
|
ForkChoiceStore,
|
|
8
|
+
IForkChoice,
|
|
8
9
|
JustifiedBalancesGetter,
|
|
10
|
+
NativeForkChoice,
|
|
9
11
|
PayloadStatus,
|
|
10
12
|
ProtoArray,
|
|
11
13
|
ProtoBlock,
|
|
12
14
|
ForkChoiceOpts as RawForkChoiceOpts,
|
|
13
15
|
} from "@lodestar/fork-choice";
|
|
14
|
-
import {ZERO_HASH_HEX} from "@lodestar/params";
|
|
16
|
+
import {ForkSeq, SLOTS_PER_HISTORICAL_ROOT, ZERO_HASH_HEX, isForkPostGloas} from "@lodestar/params";
|
|
15
17
|
import {
|
|
16
18
|
DataAvailabilityStatus,
|
|
17
19
|
IBeaconStateView,
|
|
20
|
+
ZERO_HASH,
|
|
18
21
|
computeEpochAtSlot,
|
|
19
22
|
computeStartSlotAtEpoch,
|
|
20
23
|
isStatePostBellatrix,
|
|
21
24
|
isStatePostGloas,
|
|
22
25
|
} from "@lodestar/state-transition";
|
|
23
|
-
import {Slot, ssz} from "@lodestar/types";
|
|
24
|
-
import {Logger, toRootHex} from "@lodestar/utils";
|
|
26
|
+
import {Slot, phase0, ssz} from "@lodestar/types";
|
|
27
|
+
import {Logger, fromHex, toRootHex} from "@lodestar/utils";
|
|
25
28
|
import {GENESIS_SLOT} from "../../constants/index.js";
|
|
26
29
|
import {Metrics} from "../../metrics/index.js";
|
|
27
30
|
import {ChainEvent, ChainEventEmitter} from "../emitter.js";
|
|
28
31
|
|
|
29
32
|
export type ForkChoiceOpts = RawForkChoiceOpts & {
|
|
33
|
+
/** Use the native (Zig) fork choice store instead of the proto-array */
|
|
34
|
+
nativeForkChoice?: boolean;
|
|
30
35
|
// for testing only
|
|
31
36
|
forkchoiceConstructor?: typeof ForkChoice;
|
|
32
37
|
};
|
|
@@ -58,7 +63,22 @@ export function initializeForkChoice(
|
|
|
58
63
|
stateGetter: ForkChoiceStateGetter,
|
|
59
64
|
metrics: Metrics | null,
|
|
60
65
|
logger?: Logger
|
|
61
|
-
):
|
|
66
|
+
): IForkChoice {
|
|
67
|
+
if (opts.nativeForkChoice) {
|
|
68
|
+
return initializeNativeForkChoice(
|
|
69
|
+
config,
|
|
70
|
+
emitter,
|
|
71
|
+
currentSlot,
|
|
72
|
+
state,
|
|
73
|
+
isFinalizedState,
|
|
74
|
+
opts,
|
|
75
|
+
justifiedBalancesGetter,
|
|
76
|
+
stateGetter,
|
|
77
|
+
metrics,
|
|
78
|
+
logger
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
62
82
|
return isFinalizedState
|
|
63
83
|
? initializeForkChoiceFromFinalizedState(
|
|
64
84
|
config,
|
|
@@ -115,7 +135,7 @@ export function initializeForkChoiceFromFinalizedState(
|
|
|
115
135
|
// production code use ForkChoice constructor directly
|
|
116
136
|
const forkchoiceConstructor = opts.forkchoiceConstructor ?? ForkChoice;
|
|
117
137
|
|
|
118
|
-
const
|
|
138
|
+
const isPostGloasAnchor = isStatePostGloas(state) && isForkPostGloas(config.getForkName(blockHeader.slot));
|
|
119
139
|
|
|
120
140
|
return new forkchoiceConstructor(
|
|
121
141
|
config,
|
|
@@ -164,15 +184,20 @@ export function initializeForkChoiceFromFinalizedState(
|
|
|
164
184
|
// TODO GLOAS: executionPayloadNumber/GasLimit are not tracked in BeaconState post-gloas
|
|
165
185
|
// (EIP-7732 removed latestExecutionPayloadHeader). Using 0 as unavailable fallback —
|
|
166
186
|
// see initializeForkChoiceFromUnfinalizedState for the same caveat on validation.
|
|
187
|
+
// A pre-Gloas anchor's gas limit is kept in the state's bid by the upgrade.
|
|
167
188
|
executionPayloadNumber: isStatePostGloas(state) ? 0 : state.payloadBlockNumber,
|
|
168
|
-
executionPayloadGasLimit:
|
|
189
|
+
executionPayloadGasLimit: isPostGloasAnchor
|
|
190
|
+
? 0
|
|
191
|
+
: isStatePostGloas(state)
|
|
192
|
+
? Number(state.latestExecutionPayloadBid.gasLimit)
|
|
193
|
+
: state.latestExecutionPayloadHeader.gasLimit,
|
|
169
194
|
executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
|
|
170
195
|
}
|
|
171
196
|
: {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
|
|
172
197
|
|
|
173
198
|
dataAvailabilityStatus: DataAvailabilityStatus.PreData,
|
|
174
|
-
payloadStatus:
|
|
175
|
-
parentBlockHash:
|
|
199
|
+
payloadStatus: isPostGloasAnchor ? PayloadStatus.PENDING : PayloadStatus.FULL,
|
|
200
|
+
parentBlockHash: isPostGloasAnchor ? toRootHex(state.latestBlockHash) : null,
|
|
176
201
|
},
|
|
177
202
|
currentSlot
|
|
178
203
|
),
|
|
@@ -183,6 +208,200 @@ export function initializeForkChoiceFromFinalizedState(
|
|
|
183
208
|
);
|
|
184
209
|
}
|
|
185
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Initialize the native fork choice. A finalized anchor is both the justified and the finalized
|
|
213
|
+
* checkpoint, as in the spec's `get_forkchoice_store`. An unfinalized one keeps its state's
|
|
214
|
+
* checkpoints, with stand-ins for the ancestors that connect it to them: nothing is reported as
|
|
215
|
+
* finalized that the chain has not finalized.
|
|
216
|
+
*/
|
|
217
|
+
export function initializeNativeForkChoice(
|
|
218
|
+
config: ChainForkConfig,
|
|
219
|
+
emitter: ChainEventEmitter,
|
|
220
|
+
currentSlot: Slot,
|
|
221
|
+
state: IBeaconStateView,
|
|
222
|
+
isFinalizedState: boolean,
|
|
223
|
+
opts: ForkChoiceOpts,
|
|
224
|
+
justifiedBalancesGetter: JustifiedBalancesGetter,
|
|
225
|
+
stateGetter: ForkChoiceStateGetter,
|
|
226
|
+
metrics: Metrics | null,
|
|
227
|
+
logger?: Logger
|
|
228
|
+
): NativeForkChoice {
|
|
229
|
+
const {blockHeader, checkpoint} = state.computeAnchorCheckpoint();
|
|
230
|
+
const anchorRoot = toRootHex(checkpoint.root);
|
|
231
|
+
const isPostGloas = isStatePostGloas(state);
|
|
232
|
+
// A state upgraded to Gloas through skipped slots still holds a pre-Gloas block, which carried its own payload
|
|
233
|
+
const isPostGloasAnchor = isPostGloas && config.getForkSeq(blockHeader.slot) >= ForkSeq.gloas;
|
|
234
|
+
const bid = isPostGloasAnchor ? state.latestExecutionPayloadBid : null;
|
|
235
|
+
const hasPayload = isStatePostBellatrix(state) && state.isExecutionStateType && state.isMergeTransitionComplete;
|
|
236
|
+
// The state caches the bid of its latest block, except at genesis: the genesis block carries no bid
|
|
237
|
+
const anchorBid = blockHeader.slot === GENESIS_SLOT ? null : bid;
|
|
238
|
+
|
|
239
|
+
// The store aliases no root to genesis, so a checkpoint the chain never moved off genesis is
|
|
240
|
+
// given the genesis block root. Only possible while that root is still in the state's history.
|
|
241
|
+
const withGenesisRoot = (cp: phase0.Checkpoint): phase0.Checkpoint => {
|
|
242
|
+
if (!ssz.Root.equals(cp.root, ZERO_HASH)) return cp;
|
|
243
|
+
if (state.slot > GENESIS_SLOT + SLOTS_PER_HISTORICAL_ROOT) {
|
|
244
|
+
throw Error(
|
|
245
|
+
`The native fork choice cannot start from an unfinalized state at slot ${state.slot} of a chain that never justified a checkpoint: the genesis block root has left the state's block roots. Start without --chain.nativeForkChoice`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
return {epoch: cp.epoch, root: state.getBlockRootAtSlot(GENESIS_SLOT)};
|
|
249
|
+
};
|
|
250
|
+
const justifiedCheckpoint = isFinalizedState ? checkpoint : withGenesisRoot(state.currentJustifiedCheckpoint);
|
|
251
|
+
const finalizedCheckpoint = isFinalizedState ? checkpoint : withGenesisRoot(state.finalizedCheckpoint);
|
|
252
|
+
const justifiedRoot = toRootHex(justifiedCheckpoint.root);
|
|
253
|
+
const finalizedRoot = toRootHex(finalizedCheckpoint.root);
|
|
254
|
+
|
|
255
|
+
if (!isFinalizedState) {
|
|
256
|
+
logger?.warn("Initializing fork choice from unfinalized state", {
|
|
257
|
+
currentSlot,
|
|
258
|
+
stateSlot: state.slot,
|
|
259
|
+
headSlot: blockHeader.slot,
|
|
260
|
+
headRoot: anchorRoot,
|
|
261
|
+
finalizedEpoch: finalizedCheckpoint.epoch,
|
|
262
|
+
finalizedRoot,
|
|
263
|
+
justifiedEpoch: justifiedCheckpoint.epoch,
|
|
264
|
+
justifiedRoot,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const store = new ForkChoiceStore(
|
|
269
|
+
currentSlot,
|
|
270
|
+
justifiedCheckpoint,
|
|
271
|
+
finalizedCheckpoint,
|
|
272
|
+
// For an unfinalized anchor this is not the justified state, but no other state is at hand
|
|
273
|
+
state.getEffectiveBalanceIncrementsZeroInactive(),
|
|
274
|
+
justifiedBalancesGetter,
|
|
275
|
+
stateGetter,
|
|
276
|
+
{
|
|
277
|
+
onJustified: (cp) => emitter.emit(ChainEvent.forkChoiceJustified, cp),
|
|
278
|
+
onFinalized: (cp) => emitter.emit(ChainEvent.forkChoiceFinalized, cp),
|
|
279
|
+
onFastConfirmation: ({block, slot, currentSlot}) =>
|
|
280
|
+
emitter.emit(routes.events.EventType.fastConfirmation, {block, slot, currentSlot}),
|
|
281
|
+
onPtcQuorum: (data) => emitter.emit(ChainEvent.forkChoicePtcQuorum, data),
|
|
282
|
+
}
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
const checkpoints = {
|
|
286
|
+
justifiedEpoch: justifiedCheckpoint.epoch,
|
|
287
|
+
justifiedRoot,
|
|
288
|
+
finalizedEpoch: finalizedCheckpoint.epoch,
|
|
289
|
+
finalizedRoot,
|
|
290
|
+
unrealizedJustifiedEpoch: justifiedCheckpoint.epoch,
|
|
291
|
+
unrealizedJustifiedRoot: justifiedRoot,
|
|
292
|
+
unrealizedFinalizedEpoch: finalizedCheckpoint.epoch,
|
|
293
|
+
unrealizedFinalizedRoot: finalizedRoot,
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const block: ProtoBlock = {
|
|
297
|
+
slot: blockHeader.slot,
|
|
298
|
+
parentRoot: toRootHex(blockHeader.parentRoot),
|
|
299
|
+
stateRoot: toRootHex(blockHeader.stateRoot),
|
|
300
|
+
blockRoot: anchorRoot,
|
|
301
|
+
targetRoot: anchorRoot,
|
|
302
|
+
timeliness: true,
|
|
303
|
+
ptcTimeliness: true,
|
|
304
|
+
importedTimely: true,
|
|
305
|
+
proposerIndex: blockHeader.proposerIndex,
|
|
306
|
+
...checkpoints,
|
|
307
|
+
|
|
308
|
+
...(hasPayload
|
|
309
|
+
? {
|
|
310
|
+
executionPayloadBlockHash: isPostGloas
|
|
311
|
+
? toRootHex(state.latestBlockHash)
|
|
312
|
+
: toRootHex(state.latestExecutionPayloadHeader.blockHash),
|
|
313
|
+
// TODO GLOAS: not tracked in BeaconState post-gloas, see initializeForkChoiceFromFinalizedState
|
|
314
|
+
executionPayloadNumber: isPostGloas ? 0 : state.payloadBlockNumber,
|
|
315
|
+
// The upgrade to Gloas keeps a pre-Gloas block's payload gas limit in the state's bid
|
|
316
|
+
executionPayloadGasLimit: isPostGloasAnchor
|
|
317
|
+
? 0
|
|
318
|
+
: isPostGloas
|
|
319
|
+
? Number(state.latestExecutionPayloadBid.gasLimit)
|
|
320
|
+
: state.latestExecutionPayloadHeader.gasLimit,
|
|
321
|
+
// A Gloas payload is judged when its envelope arrives, the genesis one included
|
|
322
|
+
executionStatus:
|
|
323
|
+
blockHeader.slot === GENESIS_SLOT && !isPostGloasAnchor ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
|
|
324
|
+
}
|
|
325
|
+
: {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
|
|
326
|
+
|
|
327
|
+
dataAvailabilityStatus: DataAvailabilityStatus.PreData,
|
|
328
|
+
payloadStatus: isPostGloasAnchor ? PayloadStatus.PENDING : PayloadStatus.FULL,
|
|
329
|
+
parentBlockHash: bid === null ? null : toRootHex(bid.parentBlockHash),
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// Ancestors of the anchor known by root only: the finalized block, the justified block, the
|
|
333
|
+
// anchor's parent, and for the anchor's epoch and the one before the checkpoint block, which the
|
|
334
|
+
// chain can still justify and which current votes target, and the block before it, the
|
|
335
|
+
// dependent root of the next epoch's duties. Their slots are upper bounds and their payloads
|
|
336
|
+
// unknown, so they carry none.
|
|
337
|
+
const unfinalizedAncestors: ProtoBlock[] = [];
|
|
338
|
+
if (!isFinalizedState) {
|
|
339
|
+
const finalizedSlot = computeStartSlotAtEpoch(finalizedCheckpoint.epoch);
|
|
340
|
+
const candidates: [string, Slot][] = [
|
|
341
|
+
[finalizedRoot, finalizedSlot],
|
|
342
|
+
[justifiedRoot, computeStartSlotAtEpoch(justifiedCheckpoint.epoch)],
|
|
343
|
+
[block.parentRoot, blockHeader.slot - 1],
|
|
344
|
+
];
|
|
345
|
+
const anchorEpoch = computeEpochAtSlot(state.slot);
|
|
346
|
+
for (const epoch of [anchorEpoch - 1, anchorEpoch]) {
|
|
347
|
+
const checkpointSlot = computeStartSlotAtEpoch(epoch);
|
|
348
|
+
for (const slot of [checkpointSlot - 1, checkpointSlot]) {
|
|
349
|
+
if (slot > finalizedSlot && slot < blockHeader.slot) {
|
|
350
|
+
candidates.push([toRootHex(state.getBlockRootAtSlot(slot)), slot]);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
// Roots repeat over skipped slots: a block keeps the lowest slot it is known at
|
|
355
|
+
candidates.sort((a, b) => a[1] - b[1]);
|
|
356
|
+
for (const [blockRoot, slot] of candidates) {
|
|
357
|
+
const isKnown = blockRoot === anchorRoot || unfinalizedAncestors.some((b) => b.blockRoot === blockRoot);
|
|
358
|
+
if (isKnown || blockRoot === ZERO_HASH_HEX) continue;
|
|
359
|
+
const isGloas = config.getForkSeq(slot) >= ForkSeq.gloas;
|
|
360
|
+
const targetSlot = computeStartSlotAtEpoch(computeEpochAtSlot(slot));
|
|
361
|
+
unfinalizedAncestors.push({
|
|
362
|
+
slot,
|
|
363
|
+
blockRoot,
|
|
364
|
+
parentRoot: unfinalizedAncestors.at(-1)?.blockRoot ?? ZERO_HASH_HEX,
|
|
365
|
+
stateRoot: ZERO_HASH_HEX,
|
|
366
|
+
targetRoot: targetSlot === slot ? blockRoot : toRootHex(state.getBlockRootAtSlot(targetSlot)),
|
|
367
|
+
timeliness: false,
|
|
368
|
+
ptcTimeliness: false,
|
|
369
|
+
importedTimely: false,
|
|
370
|
+
proposerIndex: 0,
|
|
371
|
+
...checkpoints,
|
|
372
|
+
executionPayloadBlockHash: null,
|
|
373
|
+
executionStatus: ExecutionStatus.PreMerge,
|
|
374
|
+
dataAvailabilityStatus: DataAvailabilityStatus.PreData,
|
|
375
|
+
payloadStatus: isGloas ? PayloadStatus.PENDING : PayloadStatus.FULL,
|
|
376
|
+
parentBlockHash: isGloas ? ZERO_HASH_HEX : null,
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
return new NativeForkChoice(
|
|
382
|
+
config,
|
|
383
|
+
store,
|
|
384
|
+
{
|
|
385
|
+
block,
|
|
386
|
+
stateSlot: state.slot,
|
|
387
|
+
genesisTime: state.genesisTime,
|
|
388
|
+
genesisValidatorsRoot: state.genesisValidatorsRoot,
|
|
389
|
+
justifiedCheckpoint: isFinalizedState ? state.currentJustifiedCheckpoint : justifiedCheckpoint,
|
|
390
|
+
finalizedCheckpoint: isFinalizedState ? state.finalizedCheckpoint : finalizedCheckpoint,
|
|
391
|
+
unfinalizedAncestors: isFinalizedState ? undefined : unfinalizedAncestors,
|
|
392
|
+
payloadBlockHash: isPostGloasAnchor
|
|
393
|
+
? (anchorBid?.blockHash ?? null)
|
|
394
|
+
: block.executionPayloadBlockHash === null
|
|
395
|
+
? null
|
|
396
|
+
: fromHex(block.executionPayloadBlockHash),
|
|
397
|
+
bidParentBlockHash: anchorBid?.parentBlockHash ?? null,
|
|
398
|
+
},
|
|
399
|
+
metrics,
|
|
400
|
+
opts,
|
|
401
|
+
logger
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
|
186
405
|
/**
|
|
187
406
|
* Initialize forkchoice from an unfinalized state.
|
|
188
407
|
*/
|
|
@@ -217,7 +436,7 @@ export function initializeForkChoiceFromUnfinalizedState(
|
|
|
217
436
|
// this is not the justified state, but there is no other ways to get justified balances
|
|
218
437
|
const justifiedBalances = unfinalizedState.getEffectiveBalanceIncrementsZeroInactive();
|
|
219
438
|
|
|
220
|
-
const
|
|
439
|
+
const isPostGloasAnchor = isStatePostGloas(unfinalizedState) && isForkPostGloas(config.getForkName(blockHeader.slot));
|
|
221
440
|
|
|
222
441
|
const store = new ForkChoiceStore(
|
|
223
442
|
currentSlot,
|
|
@@ -270,17 +489,20 @@ export function initializeForkChoiceFromUnfinalizedState(
|
|
|
270
489
|
// PENDING/EMPTY convention), so gossip bids that reference the head's *own* payload
|
|
271
490
|
// hash won't match this variant anyway and will IGNORE until `onExecutionPayload`
|
|
272
491
|
// upgrades the head to FULL with real values.
|
|
492
|
+
// A pre-Gloas anchor's gas limit is kept in the state's bid by the upgrade.
|
|
273
493
|
executionPayloadNumber: isStatePostGloas(unfinalizedState) ? 0 : unfinalizedState.payloadBlockNumber,
|
|
274
|
-
executionPayloadGasLimit:
|
|
494
|
+
executionPayloadGasLimit: isPostGloasAnchor
|
|
275
495
|
? 0
|
|
276
|
-
: unfinalizedState
|
|
496
|
+
: isStatePostGloas(unfinalizedState)
|
|
497
|
+
? Number(unfinalizedState.latestExecutionPayloadBid.gasLimit)
|
|
498
|
+
: unfinalizedState.latestExecutionPayloadHeader.gasLimit,
|
|
277
499
|
executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
|
|
278
500
|
}
|
|
279
501
|
: {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
|
|
280
502
|
|
|
281
503
|
dataAvailabilityStatus: DataAvailabilityStatus.PreData,
|
|
282
|
-
payloadStatus:
|
|
283
|
-
parentBlockHash:
|
|
504
|
+
payloadStatus: isPostGloasAnchor ? PayloadStatus.PENDING : PayloadStatus.FULL,
|
|
505
|
+
parentBlockHash: isPostGloasAnchor ? toRootHex(unfinalizedState.latestBlockHash) : null,
|
|
284
506
|
};
|
|
285
507
|
|
|
286
508
|
const parentSlot = blockHeader.slot - 1;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
2
|
import {
|
|
3
3
|
BLS_WITHDRAWAL_PREFIX,
|
|
4
|
+
FAR_FUTURE_EPOCH,
|
|
4
5
|
ForkName,
|
|
5
6
|
ForkSeq,
|
|
6
7
|
MAX_ATTESTER_SLASHINGS,
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
getAttesterSlashableIndices,
|
|
18
19
|
getAttesterSlashingSignatureSets,
|
|
19
20
|
getProposerSlashingSignatureSets,
|
|
21
|
+
getValidatorFromStateBytes,
|
|
20
22
|
} from "@lodestar/state-transition";
|
|
21
23
|
import {
|
|
22
24
|
AttesterSlashing,
|
|
@@ -389,12 +391,19 @@ export class OpPool {
|
|
|
389
391
|
}
|
|
390
392
|
|
|
391
393
|
/**
|
|
392
|
-
* Prune all types of transactions given the latest head state
|
|
394
|
+
* Prune all types of transactions given the latest head state and the finalized checkpoint state.
|
|
395
|
+
* `finalizedState` is only needed to prune voluntary exits, and may be null when there are none.
|
|
393
396
|
*/
|
|
394
|
-
pruneAll(
|
|
397
|
+
pruneAll(
|
|
398
|
+
headBlock: SignedBeaconBlock,
|
|
399
|
+
headState: IBeaconStateView,
|
|
400
|
+
finalizedState: IBeaconStateView | Uint8Array | null
|
|
401
|
+
): void {
|
|
395
402
|
this.pruneAttesterSlashings(headState);
|
|
396
403
|
this.pruneProposerSlashings(headState);
|
|
397
|
-
|
|
404
|
+
if (finalizedState !== null) {
|
|
405
|
+
this.pruneVoluntaryExits(finalizedState);
|
|
406
|
+
}
|
|
398
407
|
this.pruneBlsToExecutionChanges(headBlock, headState);
|
|
399
408
|
}
|
|
400
409
|
|
|
@@ -438,21 +447,23 @@ export class OpPool {
|
|
|
438
447
|
|
|
439
448
|
/**
|
|
440
449
|
* Call after finalizing
|
|
441
|
-
* Prune if validator has already exited
|
|
450
|
+
* Prune if validator has already exited in the finalized state, so an exit included only in a block that is later
|
|
451
|
+
* orphaned stays in the pool. The finalized state may be serialized bytes if it is not in memory.
|
|
452
|
+
*
|
|
453
|
+
* Exits are not pruned by fork: from Deneb the signature domain is fixed to Capella (EIP-7044), so a fork transition
|
|
454
|
+
* cannot invalidate an exit verified at a Deneb+ state. Exits verified with a pre-Capella domain before crossing into
|
|
455
|
+
* Deneb are not handled, as only chains that cross the Deneb fork are affected.
|
|
442
456
|
*/
|
|
443
|
-
private pruneVoluntaryExits(
|
|
444
|
-
const headStateFork = this.config.getForkSeq(headState.slot);
|
|
445
|
-
const finalizedEpoch = headState.finalizedCheckpoint.epoch;
|
|
446
|
-
|
|
457
|
+
private pruneVoluntaryExits(finalizedState: IBeaconStateView | Uint8Array): void {
|
|
447
458
|
for (const [key, voluntaryExit] of this.voluntaryExits.entries()) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
if (
|
|
459
|
+
const {validatorIndex} = voluntaryExit.message;
|
|
460
|
+
const finalizedValidator =
|
|
461
|
+
finalizedState instanceof Uint8Array
|
|
462
|
+
? getValidatorFromStateBytes(this.config, finalizedState, validatorIndex)
|
|
463
|
+
: validatorIndex < finalizedState.validatorCount
|
|
464
|
+
? finalizedState.getValidator(validatorIndex)
|
|
465
|
+
: null;
|
|
466
|
+
if (finalizedValidator !== null && finalizedValidator.exitEpoch !== FAR_FUTURE_EPOCH) {
|
|
456
467
|
this.voluntaryExits.delete(key);
|
|
457
468
|
}
|
|
458
469
|
}
|
package/src/chain/options.ts
CHANGED
|
@@ -110,7 +110,6 @@ export const defaultChainOptions: IChainOptions = {
|
|
|
110
110
|
proposerBoost: true,
|
|
111
111
|
proposerBoostReorg: true,
|
|
112
112
|
dedupePayloads: true,
|
|
113
|
-
computeUnrealized: true,
|
|
114
113
|
fastConfirmation: false,
|
|
115
114
|
suggestedFeeRecipient: defaultValidatorOptions.suggestedFeeRecipient,
|
|
116
115
|
graffitiAppend: true,
|
|
@@ -133,6 +132,7 @@ export const defaultChainOptions: IChainOptions = {
|
|
|
133
132
|
// - it helps debug easier when network is unfinalized
|
|
134
133
|
nHistoricalStatesFileDataStore: true,
|
|
135
134
|
nativeStateTransition: true,
|
|
135
|
+
nativeForkChoice: false,
|
|
136
136
|
maxBlockStates: DEFAULT_MAX_BLOCK_STATES,
|
|
137
137
|
maxCPStateEpochsInMemory: DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY,
|
|
138
138
|
maxCPStateEpochsOnDisk: DEFAULT_MAX_CP_STATE_ON_DISK,
|
|
@@ -378,7 +378,7 @@ export class SeenBlockInput {
|
|
|
378
378
|
for (const [, blockInput] of sorted) {
|
|
379
379
|
this.evictBlockInput(blockInput);
|
|
380
380
|
itemsToDelete--;
|
|
381
|
-
if (itemsToDelete <= 0)
|
|
381
|
+
if (itemsToDelete <= 0) break;
|
|
382
382
|
}
|
|
383
383
|
}
|
|
384
384
|
pruneSetToMax(this.verifiedProposerSignatures, MAX_BLOCK_INPUT_CACHE_SIZE);
|
|
@@ -98,13 +98,16 @@ export async function validateGossipBlock(
|
|
|
98
98
|
// If fork choice does *not* consider the parent to be a descendant of the finalized block,
|
|
99
99
|
// then there are two more cases:
|
|
100
100
|
//
|
|
101
|
-
// 1.
|
|
102
|
-
// parent is
|
|
103
|
-
//
|
|
101
|
+
// 1. Fork choice still holds the parent. Because it is *not* in our post-finalization DAG,
|
|
102
|
+
// the parent is either pre-finalization or conflicting with finalization, so the
|
|
103
|
+
// finalized checkpoint is not an ancestor of the block: REJECT.
|
|
104
104
|
// 2. The parent is unknown to us, we probably want to download it since it might actually
|
|
105
105
|
// descend from the finalized root.
|
|
106
|
-
//
|
|
107
|
-
//
|
|
106
|
+
// Blocks that fork choice has already pruned fall into case (2), as the `db.block` database
|
|
107
|
+
// does not keep non-descendants of the finalized block either.
|
|
108
|
+
if (chain.forkChoice.hasBlockHexUnsafe(parentRoot)) {
|
|
109
|
+
throw new BlockGossipError(GossipAction.REJECT, {code: BlockErrorCode.NOT_FINALIZED_DESCENDANT, parentRoot});
|
|
110
|
+
}
|
|
108
111
|
throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.PARENT_BLOCK_UNKNOWN, parentRoot});
|
|
109
112
|
}
|
|
110
113
|
|
|
@@ -214,12 +214,21 @@ async function validateExecutionPayloadBid(
|
|
|
214
214
|
if (isForkPostHeze(chain.config.getForkName(bid.slot))) {
|
|
215
215
|
const {inclusionListBits} = bid as heze.ExecutionPayloadBid;
|
|
216
216
|
const inclusionListSlot = bid.slot - 1;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
217
|
+
let inclusionListDependentRoot: RootHex;
|
|
218
|
+
try {
|
|
219
|
+
inclusionListDependentRoot = getShufflingDependentRoot(
|
|
220
|
+
chain.forkChoice,
|
|
221
|
+
computeEpochAtSlot(inclusionListSlot),
|
|
222
|
+
computeEpochAtSlot(parentBlock.slot),
|
|
223
|
+
parentBlock
|
|
224
|
+
);
|
|
225
|
+
} catch {
|
|
226
|
+
throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
|
|
227
|
+
code: ExecutionPayloadBidErrorCode.UNKNOWN_INCLUSION_LIST_DEPENDENT_ROOT,
|
|
228
|
+
slot: bid.slot,
|
|
229
|
+
parentBlockRoot: bidParentBlockRoot,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
223
232
|
if (
|
|
224
233
|
!chain.inclusionListStore.isInclusionListBitsInclusive(
|
|
225
234
|
inclusionListSlot,
|
|
@@ -105,8 +105,8 @@ async function validatePayloadAttestationMessage(
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
// [REJECT] The message's validator index is within the payload committee in
|
|
108
|
-
// `get_ptc(state, data.slot)`. The `state` is the
|
|
109
|
-
//
|
|
108
|
+
// `get_ptc(state, data.slot)`. The `state` is the post-state of the attested block,
|
|
109
|
+
// so the committee is the one of the block's branch, as in fork choice.
|
|
110
110
|
// The validator may occupy multiple PTC positions because `compute_ptc` samples
|
|
111
111
|
// by effective balance — collect all of them so duplicate votes are counted.
|
|
112
112
|
const validatorCommitteeIndices = state.getIndicesInPayloadTimelinessCommittee(validatorIndex, data.slot);
|
|
@@ -36,7 +36,11 @@ async function validateProposerSlashing(
|
|
|
36
36
|
|
|
37
37
|
// [REJECT] All of the conditions within process_proposer_slashing pass validation.
|
|
38
38
|
try {
|
|
39
|
-
const
|
|
39
|
+
const {proposerIndex} = proposerSlashing.signedHeader1.message;
|
|
40
|
+
if (proposerIndex >= state.validatorCount) {
|
|
41
|
+
throw Error(`Unknown proposer index ${proposerIndex}`);
|
|
42
|
+
}
|
|
43
|
+
const proposer = state.getValidator(proposerIndex);
|
|
40
44
|
// verifySignature = false, verified in batch below
|
|
41
45
|
assertValidProposerSlashing(chain.config, state.slot, proposerSlashing, proposer, false);
|
|
42
46
|
} catch (e) {
|
package/src/network/network.ts
CHANGED
|
@@ -424,8 +424,8 @@ export class Network implements INetwork {
|
|
|
424
424
|
}
|
|
425
425
|
|
|
426
426
|
async publishVoluntaryExit(voluntaryExit: phase0.SignedVoluntaryExit): Promise<number> {
|
|
427
|
-
|
|
428
|
-
const boundary = this.config.getForkBoundaryAtEpoch(
|
|
427
|
+
// An exit stays valid indefinitely but peers unsubscribe from the topics of previous forks
|
|
428
|
+
const boundary = this.config.getForkBoundaryAtEpoch(this.clock.currentEpoch);
|
|
429
429
|
|
|
430
430
|
return this.publishGossip<GossipType.voluntary_exit>({type: GossipType.voluntary_exit, boundary}, voluntaryExit);
|
|
431
431
|
}
|
|
@@ -455,8 +455,8 @@ export class Network implements INetwork {
|
|
|
455
455
|
}
|
|
456
456
|
|
|
457
457
|
async publishProposerSlashing(proposerSlashing: phase0.ProposerSlashing): Promise<number> {
|
|
458
|
-
|
|
459
|
-
const boundary = this.config.getForkBoundaryAtEpoch(
|
|
458
|
+
// The slashed headers can be from a previous fork but peers unsubscribe from the topics of previous forks
|
|
459
|
+
const boundary = this.config.getForkBoundaryAtEpoch(this.clock.currentEpoch);
|
|
460
460
|
|
|
461
461
|
return this.publishGossip<GossipType.proposer_slashing>(
|
|
462
462
|
{type: GossipType.proposer_slashing, boundary},
|
|
@@ -465,8 +465,8 @@ export class Network implements INetwork {
|
|
|
465
465
|
}
|
|
466
466
|
|
|
467
467
|
async publishAttesterSlashing(attesterSlashing: AttesterSlashing): Promise<number> {
|
|
468
|
-
|
|
469
|
-
const boundary = this.config.getForkBoundaryAtEpoch(
|
|
468
|
+
// The slashed attestations can be from a previous fork but peers unsubscribe from the topics of previous forks
|
|
469
|
+
const boundary = this.config.getForkBoundaryAtEpoch(this.clock.currentEpoch);
|
|
470
470
|
|
|
471
471
|
return this.publishGossip<GossipType.attester_slashing>(
|
|
472
472
|
{type: GossipType.attester_slashing, boundary},
|
|
@@ -1295,20 +1295,25 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
1295
1295
|
try {
|
|
1296
1296
|
const delaySec = chain.clock.secFromSlot(payloadAttestationMessage.data.slot, seenTimestampSec);
|
|
1297
1297
|
metrics?.gossipPayloadAttestationMessage.elapsedTimeTillReceived.observe({source: OpSource.gossip}, delaySec);
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
if (isNextSlotProposer) {
|
|
1302
|
-
try {
|
|
1298
|
+
try {
|
|
1299
|
+
const nextSlotProposer = chain.getHeadState().getBeaconProposer(payloadAttestationMessage.data.slot + 1);
|
|
1300
|
+
if (chain.beaconProposerCache.has(nextSlotProposer)) {
|
|
1303
1301
|
const insertOutcome = chain.payloadAttestationPool.add(
|
|
1304
1302
|
payloadAttestationMessage,
|
|
1305
1303
|
validationResult.attDataRootHex,
|
|
1306
1304
|
validationResult.validatorCommitteeIndices
|
|
1307
1305
|
);
|
|
1308
1306
|
metrics?.opPool.payloadAttestationPool.gossipInsertOutcome.inc({insertOutcome});
|
|
1309
|
-
} catch (e) {
|
|
1310
|
-
logger.debug("Error adding to payloadAttestation pool", {}, e as Error);
|
|
1311
1307
|
}
|
|
1308
|
+
} catch (e) {
|
|
1309
|
+
logger.debug(
|
|
1310
|
+
"Error adding to payloadAttestation pool",
|
|
1311
|
+
{
|
|
1312
|
+
slot: payloadAttestationMessage.data.slot,
|
|
1313
|
+
root: toRootHex(payloadAttestationMessage.data.beaconBlockRoot),
|
|
1314
|
+
},
|
|
1315
|
+
e as Error
|
|
1316
|
+
);
|
|
1312
1317
|
}
|
|
1313
1318
|
|
|
1314
1319
|
// Gossip accepts adjacent slots within the clock disparity but fork choice only counts the current slot
|
|
@@ -226,5 +226,8 @@ export function validateDataColumnSidecarsByRangeRequest(
|
|
|
226
226
|
count = config.MAX_REQUEST_BLOCKS_DENEB;
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
|
|
229
|
+
// Spec: sidecars MUST be sent in (slot, column_index) order, so serve each requested column once, ascending
|
|
230
|
+
const sortedColumns = Array.from(new Set(columns)).sort((a, b) => a - b);
|
|
231
|
+
|
|
232
|
+
return {startSlot, count, columns: sortedColumns};
|
|
230
233
|
}
|