@lodestar/beacon-node 1.40.0-dev.c1d3b3c5cc → 1.40.0-dev.c7b6a784da
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/lodestar/index.d.ts.map +1 -1
- package/lib/api/impl/lodestar/index.js +0 -2
- package/lib/api/impl/lodestar/index.js.map +1 -1
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +9 -8
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/chain.d.ts +1 -1
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +9 -9
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/prepareNextSlot.js +6 -4
- package/lib/chain/prepareNextSlot.js.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.d.ts +3 -2
- package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +5 -3
- package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
- package/lib/chain/regen/interface.d.ts +2 -8
- package/lib/chain/regen/interface.d.ts.map +1 -1
- package/lib/chain/regen/interface.js +0 -1
- package/lib/chain/regen/interface.js.map +1 -1
- package/lib/chain/regen/queued.d.ts +1 -2
- package/lib/chain/regen/queued.d.ts.map +1 -1
- package/lib/chain/regen/queued.js +2 -16
- package/lib/chain/regen/queued.js.map +1 -1
- package/lib/chain/regen/regen.d.ts +3 -7
- package/lib/chain/regen/regen.d.ts.map +1 -1
- package/lib/chain/regen/regen.js +3 -16
- package/lib/chain/regen/regen.js.map +1 -1
- package/lib/chain/validation/blobSidecar.js +1 -1
- package/lib/chain/validation/blobSidecar.js.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.js +1 -1
- package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
- package/lib/db/repositories/checkpointState.js +0 -1
- package/lib/db/repositories/checkpointState.js.map +1 -1
- package/package.json +15 -15
- package/src/api/impl/lodestar/index.ts +0 -3
- package/src/api/impl/validator/index.ts +12 -11
- package/src/chain/chain.ts +9 -19
- package/src/chain/prepareNextSlot.ts +6 -6
- package/src/chain/produceBlock/produceBlockBody.ts +7 -5
- package/src/chain/regen/interface.ts +1 -12
- package/src/chain/regen/queued.ts +3 -23
- package/src/chain/regen/regen.ts +4 -24
- package/src/chain/validation/blobSidecar.ts +1 -1
- package/src/chain/validation/dataColumnSidecar.ts +1 -1
- package/src/db/repositories/checkpointState.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {ChainForkConfig} from "@lodestar/config";
|
|
2
|
-
import {getSafeExecutionBlockHash} from "@lodestar/fork-choice";
|
|
2
|
+
import {ProtoBlock, getSafeExecutionBlockHash} from "@lodestar/fork-choice";
|
|
3
3
|
import {
|
|
4
4
|
ForkName,
|
|
5
5
|
ForkPostBellatrix,
|
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
electra,
|
|
44
44
|
fulu,
|
|
45
45
|
} from "@lodestar/types";
|
|
46
|
-
import {Logger, sleep, toHex, toPubkeyHex, toRootHex} from "@lodestar/utils";
|
|
46
|
+
import {Logger, fromHex, sleep, toHex, toPubkeyHex, toRootHex} from "@lodestar/utils";
|
|
47
47
|
import {ZERO_HASH_HEX} from "../../constants/index.js";
|
|
48
48
|
import {numToQuantity} from "../../execution/engine/utils.js";
|
|
49
49
|
import {
|
|
@@ -86,7 +86,7 @@ export type BlockAttributes = {
|
|
|
86
86
|
randaoReveal: BLSSignature;
|
|
87
87
|
graffiti: Bytes32;
|
|
88
88
|
slot: Slot;
|
|
89
|
-
|
|
89
|
+
parentBlock: ProtoBlock;
|
|
90
90
|
feeRecipient?: string;
|
|
91
91
|
};
|
|
92
92
|
|
|
@@ -155,13 +155,14 @@ export async function produceBlockBody<T extends BlockType>(
|
|
|
155
155
|
const {
|
|
156
156
|
slot: blockSlot,
|
|
157
157
|
feeRecipient: requestedFeeRecipient,
|
|
158
|
-
|
|
158
|
+
parentBlock,
|
|
159
159
|
proposerIndex,
|
|
160
160
|
proposerPubKey,
|
|
161
161
|
commonBlockBodyPromise,
|
|
162
162
|
} = blockAttr;
|
|
163
163
|
let executionPayloadValue: Wei;
|
|
164
164
|
let blockBody: AssembledBodyType<T>;
|
|
165
|
+
const parentBlockRoot = fromHex(parentBlock.blockRoot);
|
|
165
166
|
// even though shouldOverrideBuilder is relevant for the engine response, for simplicity of typing
|
|
166
167
|
// we just return it undefined for the builder which anyway doesn't get consumed downstream
|
|
167
168
|
let shouldOverrideBuilder: boolean | undefined;
|
|
@@ -637,7 +638,7 @@ export async function produceCommonBlockBody<T extends BlockType>(
|
|
|
637
638
|
this: BeaconChain,
|
|
638
639
|
blockType: T,
|
|
639
640
|
currentState: CachedBeaconStateAllForks,
|
|
640
|
-
{randaoReveal, graffiti, slot,
|
|
641
|
+
{randaoReveal, graffiti, slot, parentBlock}: BlockAttributes
|
|
641
642
|
): Promise<CommonBlockBody> {
|
|
642
643
|
const stepsMetrics =
|
|
643
644
|
blockType === BlockType.Full
|
|
@@ -691,6 +692,7 @@ export async function produceCommonBlockBody<T extends BlockType>(
|
|
|
691
692
|
|
|
692
693
|
const endSyncAggregate = stepsMetrics?.startTimer();
|
|
693
694
|
if (ForkSeq[fork] >= ForkSeq.altair) {
|
|
695
|
+
const parentBlockRoot = fromHex(parentBlock.blockRoot);
|
|
694
696
|
const previousSlot = slot - 1;
|
|
695
697
|
const syncAggregate = this.syncContributionAndProofPool.getAggregate(previousSlot, parentBlockRoot);
|
|
696
698
|
this.metrics?.production.producedSyncAggregateParticipants.observe(
|
|
@@ -26,7 +26,6 @@ export enum RegenFnName {
|
|
|
26
26
|
getBlockSlotState = "getBlockSlotState",
|
|
27
27
|
getState = "getState",
|
|
28
28
|
getPreState = "getPreState",
|
|
29
|
-
getCheckpointState = "getCheckpointState",
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
export type StateRegenerationOpts = {
|
|
@@ -63,21 +62,11 @@ export interface IStateRegeneratorInternal {
|
|
|
63
62
|
rCaller: RegenCaller
|
|
64
63
|
): Promise<CachedBeaconStateAllForks>;
|
|
65
64
|
|
|
66
|
-
/**
|
|
67
|
-
* Return a valid checkpoint state
|
|
68
|
-
* This will always return a state with `state.slot % SLOTS_PER_EPOCH === 0`
|
|
69
|
-
*/
|
|
70
|
-
getCheckpointState(
|
|
71
|
-
cp: phase0.Checkpoint,
|
|
72
|
-
opts: StateRegenerationOpts,
|
|
73
|
-
rCaller: RegenCaller
|
|
74
|
-
): Promise<CachedBeaconStateAllForks>;
|
|
75
|
-
|
|
76
65
|
/**
|
|
77
66
|
* Return the state of `blockRoot` processed to slot `slot`
|
|
78
67
|
*/
|
|
79
68
|
getBlockSlotState(
|
|
80
|
-
|
|
69
|
+
block: ProtoBlock,
|
|
81
70
|
slot: Slot,
|
|
82
71
|
opts: StateRegenerationOpts,
|
|
83
72
|
rCaller: RegenCaller
|
|
@@ -5,7 +5,7 @@ import {BeaconBlock, Epoch, RootHex, Slot, phase0} from "@lodestar/types";
|
|
|
5
5
|
import {Logger, toRootHex} from "@lodestar/utils";
|
|
6
6
|
import {Metrics} from "../../metrics/index.js";
|
|
7
7
|
import {JobItemQueue} from "../../util/queue/index.js";
|
|
8
|
-
import {CheckpointHex
|
|
8
|
+
import {CheckpointHex} from "../stateCache/index.js";
|
|
9
9
|
import {BlockStateCache, CheckpointStateCache} from "../stateCache/types.js";
|
|
10
10
|
import {RegenError, RegenErrorCode} from "./errors.js";
|
|
11
11
|
import {
|
|
@@ -220,24 +220,6 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
220
220
|
return this.jobQueue.push({key: "getPreState", args: [block, opts, rCaller]});
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
-
async getCheckpointState(
|
|
224
|
-
cp: phase0.Checkpoint,
|
|
225
|
-
opts: StateRegenerationOpts,
|
|
226
|
-
rCaller: RegenCaller
|
|
227
|
-
): Promise<CachedBeaconStateAllForks> {
|
|
228
|
-
this.metrics?.regenFnCallTotal.inc({caller: rCaller, entrypoint: RegenFnName.getCheckpointState});
|
|
229
|
-
|
|
230
|
-
// First attempt to fetch the state from cache before queueing
|
|
231
|
-
const checkpointState = this.checkpointStateCache.get(toCheckpointHex(cp));
|
|
232
|
-
if (checkpointState) {
|
|
233
|
-
return checkpointState;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// The state is not immediately available in the caches, enqueue the job
|
|
237
|
-
this.metrics?.regenFnQueuedTotal.inc({caller: rCaller, entrypoint: RegenFnName.getCheckpointState});
|
|
238
|
-
return this.jobQueue.push({key: "getCheckpointState", args: [cp, opts, rCaller]});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
223
|
/**
|
|
242
224
|
* Get state of provided `blockRoot` and dial forward to `slot`
|
|
243
225
|
* Use this api with care because we don't want the queue to be busy
|
|
@@ -245,7 +227,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
245
227
|
* @returns
|
|
246
228
|
*/
|
|
247
229
|
async getBlockSlotState(
|
|
248
|
-
|
|
230
|
+
block: ProtoBlock,
|
|
249
231
|
slot: Slot,
|
|
250
232
|
opts: StateRegenerationOpts,
|
|
251
233
|
rCaller: RegenCaller
|
|
@@ -253,7 +235,7 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
253
235
|
this.metrics?.regenFnCallTotal.inc({caller: rCaller, entrypoint: RegenFnName.getBlockSlotState});
|
|
254
236
|
|
|
255
237
|
// The state is not immediately available in the caches, enqueue the job
|
|
256
|
-
return this.jobQueue.push({key: "getBlockSlotState", args: [
|
|
238
|
+
return this.jobQueue.push({key: "getBlockSlotState", args: [block, slot, opts, rCaller]});
|
|
257
239
|
}
|
|
258
240
|
|
|
259
241
|
async getState(stateRoot: RootHex, rCaller: RegenCaller): Promise<CachedBeaconStateAllForks> {
|
|
@@ -281,8 +263,6 @@ export class QueuedStateRegenerator implements IStateRegenerator {
|
|
|
281
263
|
switch (regenRequest.key) {
|
|
282
264
|
case "getPreState":
|
|
283
265
|
return await this.regen.getPreState(...regenRequest.args);
|
|
284
|
-
case "getCheckpointState":
|
|
285
|
-
return await this.regen.getCheckpointState(...regenRequest.args);
|
|
286
266
|
case "getBlockSlotState":
|
|
287
267
|
return await this.regen.getBlockSlotState(...regenRequest.args);
|
|
288
268
|
case "getState":
|
package/src/chain/regen/regen.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
processSlots,
|
|
12
12
|
stateTransition,
|
|
13
13
|
} from "@lodestar/state-transition";
|
|
14
|
-
import {BeaconBlock, RootHex, SignedBeaconBlock, Slot
|
|
14
|
+
import {BeaconBlock, RootHex, SignedBeaconBlock, Slot} from "@lodestar/types";
|
|
15
15
|
import {Logger, fromHex, toRootHex} from "@lodestar/utils";
|
|
16
16
|
import {IBeaconDb} from "../../db/index.js";
|
|
17
17
|
import {Metrics} from "../../metrics/index.js";
|
|
@@ -74,45 +74,24 @@ export class StateRegenerator implements IStateRegeneratorInternal {
|
|
|
74
74
|
// We may have the checkpoint state with parent root inside the checkpoint state cache
|
|
75
75
|
// through gossip validation.
|
|
76
76
|
if (parentEpoch < blockEpoch) {
|
|
77
|
-
return this.
|
|
77
|
+
return this.getBlockSlotState(parentBlock, block.slot, opts, regenCaller, allowDiskReload);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
// Otherwise, get the state normally.
|
|
81
81
|
return this.getState(parentBlock.stateRoot, regenCaller, allowDiskReload);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
/**
|
|
85
|
-
* Get state after block `cp.root` dialed forward to first slot of `cp.epoch`
|
|
86
|
-
*/
|
|
87
|
-
async getCheckpointState(
|
|
88
|
-
cp: phase0.Checkpoint,
|
|
89
|
-
opts: StateRegenerationOpts,
|
|
90
|
-
regenCaller: RegenCaller,
|
|
91
|
-
allowDiskReload = false
|
|
92
|
-
): Promise<CachedBeaconStateAllForks> {
|
|
93
|
-
const checkpointStartSlot = computeStartSlotAtEpoch(cp.epoch);
|
|
94
|
-
return this.getBlockSlotState(toRootHex(cp.root), checkpointStartSlot, opts, regenCaller, allowDiskReload);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
84
|
/**
|
|
98
85
|
* Get state after block `blockRoot` dialed forward to `slot`
|
|
99
86
|
* - allowDiskReload should be used with care, as it will cause the state to be reloaded from disk
|
|
100
87
|
*/
|
|
101
88
|
async getBlockSlotState(
|
|
102
|
-
|
|
89
|
+
block: ProtoBlock,
|
|
103
90
|
slot: Slot,
|
|
104
91
|
opts: StateRegenerationOpts,
|
|
105
92
|
regenCaller: RegenCaller,
|
|
106
93
|
allowDiskReload = false
|
|
107
94
|
): Promise<CachedBeaconStateAllForks> {
|
|
108
|
-
const block = this.modules.forkChoice.getBlockHex(blockRoot);
|
|
109
|
-
if (!block) {
|
|
110
|
-
throw new RegenError({
|
|
111
|
-
code: RegenErrorCode.BLOCK_NOT_IN_FORKCHOICE,
|
|
112
|
-
blockRoot,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
95
|
if (slot < block.slot) {
|
|
117
96
|
throw new RegenError({
|
|
118
97
|
code: RegenErrorCode.SLOT_BEFORE_BLOCK_SLOT,
|
|
@@ -121,6 +100,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
|
|
|
121
100
|
});
|
|
122
101
|
}
|
|
123
102
|
|
|
103
|
+
const {blockRoot} = block;
|
|
124
104
|
const {checkpointStateCache} = this.modules;
|
|
125
105
|
const epoch = computeEpochAtSlot(slot);
|
|
126
106
|
const latestCheckpointStateCtx = allowDiskReload
|
|
@@ -124,7 +124,7 @@ export async function validateGossipBlobSidecar(
|
|
|
124
124
|
// [IGNORE] The block's parent (defined by block.parent_root) has been seen (via both gossip and non-gossip sources) (a client MAY queue blocks for processing once the parent block is retrieved).
|
|
125
125
|
// [REJECT] The block's parent (defined by block.parent_root) passes validation.
|
|
126
126
|
const blockState = await chain.regen
|
|
127
|
-
.getBlockSlotState(
|
|
127
|
+
.getBlockSlotState(parentBlock, blobSlot, {dontTransferCache: true}, RegenCaller.validateGossipBlock)
|
|
128
128
|
.catch(() => {
|
|
129
129
|
throw new BlobSidecarGossipError(GossipAction.IGNORE, {
|
|
130
130
|
code: BlobSidecarErrorCode.PARENT_UNKNOWN,
|
|
@@ -106,7 +106,7 @@ export async function validateGossipDataColumnSidecar(
|
|
|
106
106
|
// this is something we should change this in the future to make the code airtight to the spec.
|
|
107
107
|
// 7) [REJECT] The sidecar's block's parent passes validation.
|
|
108
108
|
const blockState = await chain.regen
|
|
109
|
-
.getBlockSlotState(
|
|
109
|
+
.getBlockSlotState(parentBlock, blockHeader.slot, {dontTransferCache: true}, RegenCaller.validateGossipDataColumn)
|
|
110
110
|
.catch(() => {
|
|
111
111
|
throw new DataColumnSidecarGossipError(GossipAction.IGNORE, {
|
|
112
112
|
code: DataColumnSidecarErrorCode.PARENT_UNKNOWN,
|
|
@@ -9,7 +9,7 @@ import {Bucket, getBucketNameByValue} from "../buckets.js";
|
|
|
9
9
|
export class CheckpointStateRepository extends BinaryRepository<Uint8Array> {
|
|
10
10
|
constructor(config: ChainForkConfig, db: Db) {
|
|
11
11
|
const bucket = Bucket.allForks_checkpointState;
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
super(config, db, bucket, getBucketNameByValue(bucket));
|
|
14
14
|
}
|
|
15
15
|
}
|