@lodestar/beacon-node 2.1.0-dev.7fecddd274 → 2.1.0-dev.81778521fa
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/beacon/pool/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/pool/index.js +8 -0
- package/lib/api/impl/beacon/pool/index.js.map +1 -1
- package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/state/index.js +3 -2
- package/lib/api/impl/beacon/state/index.js.map +1 -1
- package/lib/api/impl/beacon/state/utils.js +1 -1
- package/lib/api/impl/beacon/state/utils.js.map +1 -1
- package/lib/api/impl/validator/index.js +1 -1
- package/lib/api/impl/validator/index.js.map +1 -1
- 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/blocks/payloadEnvelopeInput/types.d.ts +2 -1
- package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -1
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +24 -5
- package/lib/chain/chain.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/seenCache/seenPayloadEnvelopeInput.d.ts +11 -2
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +28 -2
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
- package/lib/chain/validation/attestation.d.ts.map +1 -1
- package/lib/chain/validation/attestation.js +4 -2
- package/lib/chain/validation/attestation.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/proposerSlashing.js +5 -1
- package/lib/chain/validation/proposerSlashing.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +24 -14
- 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/chain.d.ts.map +1 -1
- package/lib/sync/range/chain.js +1 -0
- package/lib/sync/range/chain.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/sync/unknownBlock.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +14 -1
- package/lib/sync/unknownBlock.js.map +1 -1
- package/lib/sync/utils/downloadByRange.d.ts +6 -0
- package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRange.js +17 -8
- package/lib/sync/utils/downloadByRange.js.map +1 -1
- package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRoot.js +1 -1
- package/lib/sync/utils/downloadByRoot.js.map +1 -1
- package/lib/sync/utils/pendingBlocksTree.d.ts.map +1 -1
- package/lib/sync/utils/pendingBlocksTree.js +6 -1
- package/lib/sync/utils/pendingBlocksTree.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 -20
- package/src/api/impl/beacon/pool/index.ts +11 -0
- package/src/api/impl/beacon/state/index.ts +3 -7
- package/src/api/impl/beacon/state/utils.ts +1 -1
- package/src/api/impl/validator/index.ts +1 -1
- 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/blocks/payloadEnvelopeInput/types.ts +8 -1
- package/src/chain/chain.ts +29 -5
- 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/seenCache/seenPayloadEnvelopeInput.ts +28 -2
- package/src/chain/validation/attestation.ts +4 -2
- package/src/chain/validation/block.ts +8 -5
- package/src/chain/validation/proposerSlashing.ts +5 -1
- package/src/network/processor/gossipHandlers.ts +40 -22
- package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +4 -1
- package/src/sync/range/chain.ts +1 -0
- package/src/sync/range/range.ts +7 -1
- package/src/sync/unknownBlock.ts +20 -1
- package/src/sync/utils/downloadByRange.ts +30 -7
- package/src/sync/utils/downloadByRoot.ts +12 -9
- package/src/sync/utils/pendingBlocksTree.ts +6 -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,
|
|
@@ -2039,7 +2041,15 @@ export class BeaconChain implements IBeaconChain {
|
|
|
2039
2041
|
this.seenBlockProposers.prune(finalizedSlot);
|
|
2040
2042
|
|
|
2041
2043
|
// Update validator custody to account for effective balance changes
|
|
2042
|
-
|
|
2044
|
+
try {
|
|
2045
|
+
await this.updateValidatorsCustodyRequirement(cp);
|
|
2046
|
+
} catch (e) {
|
|
2047
|
+
this.logger.warn(
|
|
2048
|
+
"Error updating validators custody requirement",
|
|
2049
|
+
{epoch: cp.epoch, root: cp.rootHex},
|
|
2050
|
+
e as Error
|
|
2051
|
+
);
|
|
2052
|
+
}
|
|
2043
2053
|
|
|
2044
2054
|
// TODO: Improve using regen here
|
|
2045
2055
|
const {blockRoot, stateRoot, slot} = this.forkChoice.getHead();
|
|
@@ -2050,7 +2060,19 @@ export class BeaconChain implements IBeaconChain {
|
|
|
2050
2060
|
}
|
|
2051
2061
|
|
|
2052
2062
|
if (headState) {
|
|
2053
|
-
|
|
2063
|
+
// The finalized checkpoint state may be loaded from disk, it is only needed to prune voluntary exits
|
|
2064
|
+
let finalizedState: IBeaconStateView | Uint8Array | null = null;
|
|
2065
|
+
if (this.opPool.voluntaryExitsSize > 0) {
|
|
2066
|
+
finalizedState = await this.regen.getCheckpointStateOrBytes({epoch: cp.epoch, rootHex: cp.rootHex});
|
|
2067
|
+
if (finalizedState === null) {
|
|
2068
|
+
// A newer finalization can prune this checkpoint state while this handler awaits, its handler prunes exits
|
|
2069
|
+
this.logger.debug("Finalized checkpoint state not available, skip pruning voluntary exits", {
|
|
2070
|
+
epoch: cp.epoch,
|
|
2071
|
+
root: cp.rootHex,
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
this.opPool.pruneAll(blockResult.block, headState, finalizedState);
|
|
2054
2076
|
}
|
|
2055
2077
|
|
|
2056
2078
|
if (headState === null) {
|
|
@@ -2133,7 +2155,9 @@ export class BeaconChain implements IBeaconChain {
|
|
|
2133
2155
|
if (stateOrBytes instanceof Uint8Array) {
|
|
2134
2156
|
effectiveBalances = getEffectiveBalancesFromStateBytes(this.config, stateOrBytes, validatorIndices);
|
|
2135
2157
|
} else {
|
|
2136
|
-
effectiveBalances = validatorIndices.map((index) =>
|
|
2158
|
+
effectiveBalances = validatorIndices.map((index) =>
|
|
2159
|
+
index < stateOrBytes.validatorCount ? stateOrBytes.getValidator(index).effectiveBalance : 0
|
|
2160
|
+
);
|
|
2137
2161
|
}
|
|
2138
2162
|
}
|
|
2139
2163
|
|
|
@@ -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);
|
|
@@ -64,6 +64,7 @@ export class SeenPayloadEnvelopeInput {
|
|
|
64
64
|
private readonly metrics: Metrics | null;
|
|
65
65
|
private readonly logger?: Logger;
|
|
66
66
|
private payloadInputs = new Map<RootHex, PayloadEnvelopeInput>();
|
|
67
|
+
private readonly unvalidatedRoots = new Set<RootHex>();
|
|
67
68
|
// Dedup concurrent DB reloads of the same root so callers share one reconstructed object.
|
|
68
69
|
private readonly reloading = new Map<RootHex, Promise<PayloadEnvelopeInput | undefined>>();
|
|
69
70
|
|
|
@@ -127,9 +128,17 @@ export class SeenPayloadEnvelopeInput {
|
|
|
127
128
|
});
|
|
128
129
|
};
|
|
129
130
|
|
|
130
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Set `unvalidated` for a block of which only the proposer signature is verified, e.g. one retained for unknown
|
|
133
|
+
* parent sync. Such entries are evicted first when the cache is over its max size, until the block passes gossip
|
|
134
|
+
* validation or is imported. Adding an existing entry without `unvalidated` promotes it without replacing it.
|
|
135
|
+
*/
|
|
136
|
+
add(props: Omit<CreateFromBlockProps, "daOutOfRange">, opts?: {unvalidated?: boolean}): PayloadEnvelopeInput {
|
|
131
137
|
const existing = this.payloadInputs.get(props.blockRootHex);
|
|
132
138
|
if (existing !== undefined) {
|
|
139
|
+
if (!opts?.unvalidated) {
|
|
140
|
+
this.unvalidatedRoots.delete(props.blockRootHex);
|
|
141
|
+
}
|
|
133
142
|
this.logger?.verbose("SeenPayloadEnvelopeInput.add reused existing entry", {
|
|
134
143
|
slot: existing.slot,
|
|
135
144
|
root: props.blockRootHex,
|
|
@@ -139,6 +148,9 @@ export class SeenPayloadEnvelopeInput {
|
|
|
139
148
|
const daOutOfRange = isDaOutOfRange(this.config, props.forkName, props.block.message.slot, this.clock.currentEpoch);
|
|
140
149
|
const input = PayloadEnvelopeInput.createFromBlock({...props, daOutOfRange});
|
|
141
150
|
this.payloadInputs.set(props.blockRootHex, input);
|
|
151
|
+
if (opts?.unvalidated) {
|
|
152
|
+
this.unvalidatedRoots.add(props.blockRootHex);
|
|
153
|
+
}
|
|
142
154
|
this.metrics?.seenCache.payloadEnvelopeInput.created.inc({source: props.source});
|
|
143
155
|
this.logger?.verbose("SeenPayloadEnvelopeInput.add created new entry", {
|
|
144
156
|
slot: input.slot,
|
|
@@ -300,12 +312,25 @@ export class SeenPayloadEnvelopeInput {
|
|
|
300
312
|
|
|
301
313
|
/**
|
|
302
314
|
* Bound this cache to have at most MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE items.
|
|
303
|
-
* Evicts
|
|
315
|
+
* Evicts entries of unvalidated blocks that are not imported yet first, then the rest by insertion order so a
|
|
316
|
+
* just-reloaded old-slot entry is not evicted right after.
|
|
304
317
|
* On unstable network, we may need to query an evicted item, UnknownBlockInput will recover
|
|
305
318
|
* it from db via getOrReload() api. Runs after every single insert, so it evicts ~1 per call.
|
|
306
319
|
*/
|
|
307
320
|
private pruneToMaxSize(): void {
|
|
308
321
|
let evicted = 0;
|
|
322
|
+
for (const blockRootHex of this.unvalidatedRoots) {
|
|
323
|
+
if (this.payloadInputs.size <= MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE) {
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
const input = this.payloadInputs.get(blockRootHex);
|
|
327
|
+
if (input === undefined || this.forkChoice.hasBlockHex(blockRootHex)) {
|
|
328
|
+
this.unvalidatedRoots.delete(blockRootHex);
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
this.evictPayloadInput(input, "capUnvalidated");
|
|
332
|
+
evicted++;
|
|
333
|
+
}
|
|
309
334
|
for (const input of this.payloadInputs.values()) {
|
|
310
335
|
if (this.payloadInputs.size <= MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE) {
|
|
311
336
|
break;
|
|
@@ -331,5 +356,6 @@ export class SeenPayloadEnvelopeInput {
|
|
|
331
356
|
});
|
|
332
357
|
this.serializedCache.delete(payloadInput.getSerializedCacheKeys());
|
|
333
358
|
this.payloadInputs.delete(payloadInput.blockRootHex);
|
|
359
|
+
this.unvalidatedRoots.delete(payloadInput.blockRootHex);
|
|
334
360
|
}
|
|
335
361
|
}
|
|
@@ -261,10 +261,12 @@ async function validateAttestationNoSignatureCheck(
|
|
|
261
261
|
const attSlot = attestationOrBytes.attSlot;
|
|
262
262
|
attDataKey = getSeenAttDataKeyFromGossipAttestation(attestationOrBytes);
|
|
263
263
|
const committeeIndexForLookup = isForkPostElectra(fork)
|
|
264
|
-
?
|
|
264
|
+
? getCommitteeIndexFromAttestationOrBytes(fork, attestationOrBytes)
|
|
265
265
|
: PRE_ELECTRA_SINGLE_ATTESTATION_COMMITTEE_INDEX;
|
|
266
266
|
const cachedAttData =
|
|
267
|
-
attDataKey !== null
|
|
267
|
+
attDataKey !== null && committeeIndexForLookup !== null
|
|
268
|
+
? chain.seenAttestationDatas.get(attSlot, committeeIndexForLookup, attDataKey)
|
|
269
|
+
: null;
|
|
268
270
|
if (cachedAttData === null) {
|
|
269
271
|
const attestation = sszDeserializeSingleAttestation(fork, attestationOrBytes.serializedData);
|
|
270
272
|
// only deserialize on the first AttestationData that's not cached
|
|
@@ -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
|
|
|
@@ -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) {
|