@chainsafe/lodestar 1.50.0-dev.1f38fe79fb → 1.50.0-dev.26076bcd3f
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/.git-data.json +1 -1
- package/lib/cmds/beacon/handler.d.ts +1 -0
- package/lib/cmds/beacon/handler.d.ts.map +1 -1
- package/lib/cmds/beacon/handler.js +11 -6
- package/lib/cmds/beacon/handler.js.map +1 -1
- package/lib/cmds/beacon/initBeaconState.d.ts +4 -2
- package/lib/cmds/beacon/initBeaconState.d.ts.map +1 -1
- package/lib/cmds/beacon/initBeaconState.js +15 -10
- package/lib/cmds/beacon/initBeaconState.js.map +1 -1
- package/lib/cmds/beacon/options.d.ts +1 -0
- package/lib/cmds/beacon/options.d.ts.map +1 -1
- package/lib/cmds/beacon/options.js +6 -0
- package/lib/cmds/beacon/options.js.map +1 -1
- package/lib/cmds/beacon/paths.d.ts +4 -0
- package/lib/cmds/beacon/paths.d.ts.map +1 -1
- package/lib/cmds/beacon/paths.js +3 -0
- package/lib/cmds/beacon/paths.js.map +1 -1
- package/lib/cmds/beacon/pubkeysFile.d.ts +10 -0
- package/lib/cmds/beacon/pubkeysFile.d.ts.map +1 -0
- package/lib/cmds/beacon/pubkeysFile.js +39 -0
- package/lib/cmds/beacon/pubkeysFile.js.map +1 -0
- package/lib/cmds/beacon/stateInitialization/checkpointState.js +22 -6
- package/lib/cmds/beacon/stateInitialization/checkpointState.js.map +1 -1
- package/lib/cmds/beacon/stateInitialization/genesisState.d.ts.map +1 -1
- package/lib/cmds/beacon/stateInitialization/genesisState.js +15 -1
- package/lib/cmds/beacon/stateInitialization/genesisState.js.map +1 -1
- package/lib/cmds/beacon/stateInitialization/prepareStateInitialization.d.ts +1 -1
- package/lib/cmds/beacon/stateInitialization/prepareStateInitialization.d.ts.map +1 -1
- package/lib/cmds/beacon/stateInitialization/prepareStateInitialization.js +17 -2
- package/lib/cmds/beacon/stateInitialization/prepareStateInitialization.js.map +1 -1
- package/lib/cmds/beacon/stateInitialization/types.d.ts +4 -2
- package/lib/cmds/beacon/stateInitialization/types.d.ts.map +1 -1
- package/lib/cmds/dev/handler.d.ts.map +1 -1
- package/lib/cmds/dev/handler.js +3 -1
- package/lib/cmds/dev/handler.js.map +1 -1
- package/lib/cmds/dev/options.d.ts +3 -1
- package/lib/cmds/dev/options.d.ts.map +1 -1
- package/lib/cmds/validator/handler.js +6 -1
- package/lib/cmds/validator/handler.js.map +1 -1
- package/lib/cmds/validator/options.js +1 -1
- package/lib/cmds/validator/options.js.map +1 -1
- package/lib/options/beaconNodeOptions/chain.d.ts +2 -1
- package/lib/options/beaconNodeOptions/chain.d.ts.map +1 -1
- package/lib/options/beaconNodeOptions/chain.js +11 -4
- package/lib/options/beaconNodeOptions/chain.js.map +1 -1
- package/lib/options/beaconNodeOptions/execution.d.ts +2 -1
- package/lib/options/beaconNodeOptions/execution.d.ts.map +1 -1
- package/lib/options/beaconNodeOptions/execution.js +9 -1
- package/lib/options/beaconNodeOptions/execution.js.map +1 -1
- package/lib/options/beaconNodeOptions/index.d.ts +3 -1
- package/lib/options/beaconNodeOptions/index.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/cmds/beacon/handler.ts +15 -6
- package/src/cmds/beacon/initBeaconState.ts +29 -10
- package/src/cmds/beacon/options.ts +8 -0
- package/src/cmds/beacon/paths.ts +5 -0
- package/src/cmds/beacon/pubkeysFile.ts +50 -0
- package/src/cmds/beacon/stateInitialization/checkpointState.ts +26 -10
- package/src/cmds/beacon/stateInitialization/genesisState.ts +15 -1
- package/src/cmds/beacon/stateInitialization/prepareStateInitialization.ts +17 -2
- package/src/cmds/beacon/stateInitialization/types.ts +4 -2
- package/src/cmds/dev/handler.ts +3 -1
- package/src/cmds/validator/handler.ts +11 -0
- package/src/cmds/validator/options.ts +1 -1
- package/src/options/beaconNodeOptions/chain.ts +14 -5
- package/src/options/beaconNodeOptions/execution.ts +12 -1
|
@@ -27,6 +27,7 @@ import {initBeaconState} from "./initBeaconState.js";
|
|
|
27
27
|
import {initPrivateKeyAndEnr} from "./initPeerIdAndEnr.js";
|
|
28
28
|
import {BeaconArgs} from "./options.js";
|
|
29
29
|
import {getBeaconPaths} from "./paths.js";
|
|
30
|
+
import {savePubkeysFile} from "./pubkeysFile.js";
|
|
30
31
|
|
|
31
32
|
const DEFAULT_RETENTION_SSZ_OBJECTS_HOURS = 15 * 24;
|
|
32
33
|
const HOURS_TO_MS = 3600 * 1000;
|
|
@@ -78,7 +79,8 @@ export async function beaconHandler(args: BeaconArgs & GlobalArgs): Promise<void
|
|
|
78
79
|
anchorState,
|
|
79
80
|
config: beaconConfig,
|
|
80
81
|
isFinalized,
|
|
81
|
-
|
|
82
|
+
earliestAvailableSlot,
|
|
83
|
+
} = await initBeaconState(args, beaconPaths.dataDir, beaconPaths.pubkeysFile, config, db, logger);
|
|
82
84
|
|
|
83
85
|
const node = await BeaconNode.init({
|
|
84
86
|
opts: options,
|
|
@@ -93,6 +95,7 @@ export async function beaconHandler(args: BeaconArgs & GlobalArgs): Promise<void
|
|
|
93
95
|
peerStoreDir: beaconPaths.peerStoreDir,
|
|
94
96
|
anchorState,
|
|
95
97
|
isAnchorStateFinalized: isFinalized,
|
|
98
|
+
earliestAvailableSlot,
|
|
96
99
|
});
|
|
97
100
|
|
|
98
101
|
// dev debug option to have access to the BN instance
|
|
@@ -139,21 +142,21 @@ export async function beaconHandler(args: BeaconArgs & GlobalArgs): Promise<void
|
|
|
139
142
|
abortController.signal.addEventListener(
|
|
140
143
|
"abort",
|
|
141
144
|
async () => {
|
|
145
|
+
let exitCode = 0;
|
|
142
146
|
try {
|
|
143
147
|
await node.close();
|
|
144
148
|
logger.debug("Beacon node closed");
|
|
145
|
-
// Explicitly exit until active handles issue is resolved
|
|
146
|
-
// See https://github.com/ChainSafe/lodestar/issues/5642
|
|
147
|
-
process.exit(0);
|
|
148
149
|
} catch (e) {
|
|
149
150
|
// If we start from unfinalized state, we don't have checkpoint state so there is this error
|
|
150
151
|
// "No state in cache for finalized checkpoint state epoch"
|
|
151
152
|
logger.warn("Error closing beacon node", {}, e as Error);
|
|
152
153
|
// Make sure db is always closed gracefully
|
|
153
154
|
await db.close();
|
|
154
|
-
|
|
155
|
-
process.exit(1);
|
|
155
|
+
exitCode = 1;
|
|
156
156
|
}
|
|
157
|
+
savePubkeysFile(pubkeyCache, beaconPaths.pubkeysFile, logger);
|
|
158
|
+
// Explicitly exit process due to potential active handles
|
|
159
|
+
process.exit(exitCode);
|
|
157
160
|
},
|
|
158
161
|
{once: true}
|
|
159
162
|
);
|
|
@@ -229,6 +232,12 @@ export async function beaconHandlerInit(args: BeaconArgs & GlobalArgs) {
|
|
|
229
232
|
// Render final options
|
|
230
233
|
const options = beaconNodeOptions.getWithDefaults();
|
|
231
234
|
|
|
235
|
+
if (options.chain.nativeStateTransition && config.GLOAS_FORK_EPOCH !== Infinity) {
|
|
236
|
+
throw Error(
|
|
237
|
+
`--chain.nativeStateTransition does not support Gloas, which is scheduled at epoch ${config.GLOAS_FORK_EPOCH}`
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
232
241
|
return {config, options, beaconPaths, network, version, commit, privateKey, logger};
|
|
233
242
|
}
|
|
234
243
|
|
|
@@ -10,9 +10,11 @@ import {
|
|
|
10
10
|
isWithinWeakSubjectivityPeriodFromSummary,
|
|
11
11
|
readBeaconStateBytesMetadata,
|
|
12
12
|
} from "@lodestar/state-transition";
|
|
13
|
+
import {Slot} from "@lodestar/types";
|
|
13
14
|
import {Logger, formatBytes} from "@lodestar/utils";
|
|
14
15
|
import {GlobalArgs} from "../../options/globalOptions.js";
|
|
15
16
|
import {BeaconArgs} from "./options.js";
|
|
17
|
+
import {loadPubkeysFile} from "./pubkeysFile.js";
|
|
16
18
|
import {StateInitializationError, StateInitializationErrorCode} from "./stateInitialization/errors.js";
|
|
17
19
|
import {prepareGenesisInitialization} from "./stateInitialization/genesisState.js";
|
|
18
20
|
import {
|
|
@@ -26,21 +28,27 @@ import {
|
|
|
26
28
|
StatePreparationContext,
|
|
27
29
|
} from "./stateInitialization/types.js";
|
|
28
30
|
|
|
29
|
-
type InitBeaconStateResult = {
|
|
31
|
+
type InitBeaconStateResult = {
|
|
32
|
+
anchorState: IBeaconStateView;
|
|
33
|
+
config: BeaconConfig;
|
|
34
|
+
isFinalized: boolean;
|
|
35
|
+
earliestAvailableSlot: Slot;
|
|
36
|
+
};
|
|
30
37
|
|
|
31
38
|
/**
|
|
32
39
|
* Select serialized anchor bytes before constructing the state used for validation, persistence, and return.
|
|
33
|
-
* Populates the global `pubkeyCache` with the anchor state's validators.
|
|
40
|
+
* Populates the global `pubkeyCache` with the anchor state's validators, reusing `pubkeysFile` if it matches.
|
|
34
41
|
*/
|
|
35
42
|
export async function initBeaconState(
|
|
36
43
|
args: BeaconArgs & GlobalArgs,
|
|
37
44
|
dataDir: string,
|
|
45
|
+
pubkeysFile: string,
|
|
38
46
|
chainForkConfig: ChainForkConfig,
|
|
39
47
|
db: IBeaconDb,
|
|
40
48
|
logger: Logger
|
|
41
49
|
): Promise<InitBeaconStateResult> {
|
|
42
50
|
const options: StateInitializationOptions = args;
|
|
43
|
-
const
|
|
51
|
+
const nativeStateTransition = options["chain.nativeStateTransition"] ?? false;
|
|
44
52
|
if (
|
|
45
53
|
options.forceCheckpointSync &&
|
|
46
54
|
!(options.checkpointState || options.checkpointSyncUrl || options.unsafeCheckpointState)
|
|
@@ -66,7 +74,12 @@ export async function initBeaconState(
|
|
|
66
74
|
options.lastPersistedCheckpointState
|
|
67
75
|
);
|
|
68
76
|
if (!options.forceCheckpointSync && (!hasCheckpointSource || archived.isWithinWeakSubjectivityPeriod)) {
|
|
69
|
-
return executeStateInitialization(
|
|
77
|
+
return executeStateInitialization(
|
|
78
|
+
prepareArchivedStateInitialization(archived, context),
|
|
79
|
+
nativeStateTransition,
|
|
80
|
+
pubkeysFile,
|
|
81
|
+
logger
|
|
82
|
+
);
|
|
70
83
|
}
|
|
71
84
|
}
|
|
72
85
|
let stateInit = await prepareCheckpointSourceInitialization(options, archived, context);
|
|
@@ -77,7 +90,7 @@ export async function initBeaconState(
|
|
|
77
90
|
? prepareArchivedStateInitialization(archived, context)
|
|
78
91
|
: await prepareGenesisInitialization(options, context);
|
|
79
92
|
}
|
|
80
|
-
return executeStateInitialization(stateInit,
|
|
93
|
+
return executeStateInitialization(stateInit, nativeStateTransition, pubkeysFile, logger);
|
|
81
94
|
}
|
|
82
95
|
|
|
83
96
|
/**
|
|
@@ -122,7 +135,9 @@ async function readLatestArchivedStateBytes({
|
|
|
122
135
|
*/
|
|
123
136
|
async function executeStateInitialization(
|
|
124
137
|
stateInit: StateInitialization,
|
|
125
|
-
|
|
138
|
+
nativeStateTransition: boolean,
|
|
139
|
+
pubkeysFile: string,
|
|
140
|
+
logger: Logger
|
|
126
141
|
): Promise<InitBeaconStateResult> {
|
|
127
142
|
const {config, stateBytes} = stateInit;
|
|
128
143
|
const validatorCount = getValidatorCountFromStateBytes(config, stateBytes);
|
|
@@ -137,10 +152,14 @@ async function executeStateInitialization(
|
|
|
137
152
|
// by its native lock; if this headroom is exceeded, it grows by the same fixed step.
|
|
138
153
|
// The view syncs pubkeys during construction, so capacity must be reserved first.
|
|
139
154
|
const headroomEpochs = (90 * 24 * 60 * 60) / (config.SECONDS_PER_SLOT * SLOTS_PER_EPOCH);
|
|
140
|
-
|
|
141
|
-
|
|
155
|
+
const pubkeyCacheCapacity = validatorCount + MAX_PENDING_DEPOSITS_PER_EPOCH * Math.ceil(headroomEpochs);
|
|
156
|
+
loadPubkeysFile(pubkeyCache, pubkeysFile, pubkeyCacheCapacity, config, stateBytes, validatorCount, logger);
|
|
157
|
+
// unilaterally expand capacity after best-effort pubkey file loading
|
|
158
|
+
pubkeyCache.ensureCapacity(pubkeyCacheCapacity);
|
|
159
|
+
const anchorState = createBeaconStateView({nativeStateTransition, config, stateBytes});
|
|
142
160
|
stateInit.validate(anchorState);
|
|
161
|
+
const earliestAvailableSlot = await stateInit.initializeEarliestAvailableSlot(anchorState);
|
|
143
162
|
await stateInit.persist?.(anchorState, stateBytes);
|
|
144
|
-
stateInit.log(anchorState);
|
|
145
|
-
return {anchorState, config, isFinalized: stateInit.isFinalized};
|
|
163
|
+
stateInit.log(anchorState, nativeStateTransition);
|
|
164
|
+
return {anchorState, config, isFinalized: stateInit.isFinalized, earliestAvailableSlot};
|
|
146
165
|
}
|
|
@@ -21,6 +21,7 @@ type BeaconExtraArgs = {
|
|
|
21
21
|
persistInvalidSszObjectsRetentionHours?: number;
|
|
22
22
|
persistOrphanedBlocksDir?: string;
|
|
23
23
|
peerStoreDir?: string;
|
|
24
|
+
pubkeysFile?: string;
|
|
24
25
|
persistNetworkIdentity?: boolean;
|
|
25
26
|
private?: boolean;
|
|
26
27
|
validatorMonitorLogs?: boolean;
|
|
@@ -141,6 +142,13 @@ export const beaconExtraOptions: CliCommandOptions<BeaconExtraArgs> = {
|
|
|
141
142
|
type: "string",
|
|
142
143
|
},
|
|
143
144
|
|
|
145
|
+
pubkeysFile: {
|
|
146
|
+
hidden: true,
|
|
147
|
+
description: "Pubkey cache file, loaded on startup and saved on graceful shutdown",
|
|
148
|
+
defaultDescription: defaultBeaconPaths.pubkeysFile,
|
|
149
|
+
type: "string",
|
|
150
|
+
},
|
|
151
|
+
|
|
144
152
|
persistNetworkIdentity: {
|
|
145
153
|
description:
|
|
146
154
|
"Whether to reuse the same peer-id across restarts. Validator custody requires custody group count to persist relative to a given ENR. Setting to false will reset ENR and validator custody requirements on restarts.",
|
package/src/cmds/beacon/paths.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type BeaconPathsPartial = Partial<{
|
|
|
9
9
|
dataColumnDir: string;
|
|
10
10
|
persistInvalidSszObjectsDir: string;
|
|
11
11
|
persistOrphanedBlocksDir?: string;
|
|
12
|
+
pubkeysFile: string;
|
|
12
13
|
}>;
|
|
13
14
|
|
|
14
15
|
export type BeaconPaths = {
|
|
@@ -18,6 +19,7 @@ export type BeaconPaths = {
|
|
|
18
19
|
dataColumnDir: string;
|
|
19
20
|
persistInvalidSszObjectsDir: string;
|
|
20
21
|
persistOrphanedBlocksDir: string;
|
|
22
|
+
pubkeysFile: string;
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
/**
|
|
@@ -29,6 +31,7 @@ export type BeaconPaths = {
|
|
|
29
31
|
* ├── beacon.config.json
|
|
30
32
|
* ├── peer-id.json
|
|
31
33
|
* ├── enr
|
|
34
|
+
* ├── pubkeys
|
|
32
35
|
* ├── chain-db
|
|
33
36
|
* └── beacon.log
|
|
34
37
|
* ```
|
|
@@ -48,6 +51,7 @@ export function getBeaconPaths(
|
|
|
48
51
|
const persistInvalidSszObjectsDir = args.persistInvalidSszObjectsDir ?? path.join(beaconDir, "invalidSszObjects");
|
|
49
52
|
const peerStoreDir = args.peerStoreDir ?? path.join(beaconDir, "peerstore");
|
|
50
53
|
const persistOrphanedBlocksDir = args.persistOrphanedBlocksDir ?? path.join(beaconDir, "orphaned_blocks");
|
|
54
|
+
const pubkeysFile = args.pubkeysFile ?? path.join(beaconDir, "pubkeys");
|
|
51
55
|
|
|
52
56
|
return {
|
|
53
57
|
...globalPaths,
|
|
@@ -57,6 +61,7 @@ export function getBeaconPaths(
|
|
|
57
61
|
persistInvalidSszObjectsDir,
|
|
58
62
|
peerStoreDir,
|
|
59
63
|
persistOrphanedBlocksDir,
|
|
64
|
+
pubkeysFile,
|
|
60
65
|
};
|
|
61
66
|
}
|
|
62
67
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {type PubkeyCache} from "@chainsafe/lodestar-z/pubkeys";
|
|
2
|
+
import {ChainForkConfig} from "@lodestar/config";
|
|
3
|
+
import {getValidatorPubkeyFromStateBytes} from "@lodestar/state-transition";
|
|
4
|
+
import {Logger, byteArrayEquals} from "@lodestar/utils";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Best effort load of a trusted pubkey cache saved by a previous run, to skip decompressing every validator
|
|
8
|
+
* pubkey on boot. Must be called before any worker uses the cache.
|
|
9
|
+
*/
|
|
10
|
+
export function loadPubkeysFile(
|
|
11
|
+
pubkeyCache: PubkeyCache,
|
|
12
|
+
filepath: string,
|
|
13
|
+
maxCapacity: number,
|
|
14
|
+
config: ChainForkConfig,
|
|
15
|
+
anchorStateBytes: Uint8Array,
|
|
16
|
+
anchorValidatorCount: number,
|
|
17
|
+
logger: Logger
|
|
18
|
+
): void {
|
|
19
|
+
const start = Date.now();
|
|
20
|
+
try {
|
|
21
|
+
pubkeyCache.load(filepath, maxCapacity);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
logger.debug("Unable to load pubkeys file", {filepath}, e as Error);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// load() only checks framing and checksum, so reject a file from another chain. Checking the endpoints
|
|
28
|
+
// suffices since the registry is append-only.
|
|
29
|
+
const overlap = Math.min(pubkeyCache.size, anchorValidatorCount);
|
|
30
|
+
for (const index of overlap > 0 ? [0, overlap - 1] : []) {
|
|
31
|
+
const anchorPubkey = getValidatorPubkeyFromStateBytes(config, anchorStateBytes, index);
|
|
32
|
+
if (anchorPubkey === null || !byteArrayEquals(pubkeyCache.getPubkeyBytesOrThrow(index), anchorPubkey)) {
|
|
33
|
+
pubkeyCache.reset();
|
|
34
|
+
logger.debug("Discarded pubkeys file not matching anchor state", {filepath, index});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
logger.debug("Loaded pubkeys file", {filepath, count: pubkeyCache.size, durationMs: Date.now() - start});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function savePubkeysFile(pubkeyCache: PubkeyCache, filepath: string, logger: Logger): void {
|
|
43
|
+
const start = Date.now();
|
|
44
|
+
try {
|
|
45
|
+
pubkeyCache.save(filepath);
|
|
46
|
+
logger.debug("Saved pubkeys file", {filepath, count: pubkeyCache.size, durationMs: Date.now() - start});
|
|
47
|
+
} catch (e) {
|
|
48
|
+
logger.debug("Unable to save pubkeys file", {filepath}, e as Error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -186,6 +186,16 @@ function prepareCheckpointInitialization(
|
|
|
186
186
|
const {isFinalized, ignoreWeakSubjectivityCheck} = policy;
|
|
187
187
|
const config = createBeaconConfig(chainForkConfig, metadata.genesisValidatorsRoot);
|
|
188
188
|
const archivedWithinWeakSubjectivityPeriod = useArchived ? archived.isWithinWeakSubjectivityPeriod : null;
|
|
189
|
+
const passedValidation =
|
|
190
|
+
archivedWithinWeakSubjectivityPeriod ?? isWithinWeakSubjectivityPeriodFromSummary(config, weakSubjectivity);
|
|
191
|
+
// Fast-fail stale checkpoints before deserializing the state or reserving pubkey-cache capacity.
|
|
192
|
+
if (!passedValidation && !ignoreWeakSubjectivityCheck) {
|
|
193
|
+
const clockEpoch = computeEpochAtSlot(getCurrentSlot(config, weakSubjectivity.genesisTime));
|
|
194
|
+
throw new StateInitializationError(
|
|
195
|
+
{code: StateInitializationErrorCode.STALE_CHECKPOINT},
|
|
196
|
+
`The selected state with epoch ${weakSubjectivity.checkpointEpoch} is not within weak subjectivity period of ${weakSubjectivity.period} epochs from the current epoch ${clockEpoch}. Please verify your checkpoint source`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
189
199
|
// DB-selected anchors need no persistence, including at slot zero.
|
|
190
200
|
const shouldPersist = isFinalized && !useArchived;
|
|
191
201
|
return {
|
|
@@ -195,15 +205,6 @@ function prepareCheckpointInitialization(
|
|
|
195
205
|
validate(state) {
|
|
196
206
|
// A supplied checkpoint must match even when the period check is ignored.
|
|
197
207
|
if (expectedCheckpoint !== null) assertStateMatchesCheckpoint(state, expectedCheckpoint);
|
|
198
|
-
const passedValidation =
|
|
199
|
-
archivedWithinWeakSubjectivityPeriod ?? isWithinWeakSubjectivityPeriodFromSummary(config, weakSubjectivity);
|
|
200
|
-
if (!passedValidation && !ignoreWeakSubjectivityCheck) {
|
|
201
|
-
const clockEpoch = computeEpochAtSlot(getCurrentSlot(config, weakSubjectivity.genesisTime));
|
|
202
|
-
throw new StateInitializationError(
|
|
203
|
-
{code: StateInitializationErrorCode.STALE_CHECKPOINT},
|
|
204
|
-
`The selected state with epoch ${weakSubjectivity.checkpointEpoch} is not within weak subjectivity period of ${weakSubjectivity.period} epochs from the current epoch ${clockEpoch}. Please verify your checkpoint source`
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
208
|
assertAnchorStateForkMatchesConfig(config, state);
|
|
208
209
|
if (isFinalized) {
|
|
209
210
|
const source = useArchived ? "db" : "checkpoint";
|
|
@@ -222,8 +223,22 @@ function prepareCheckpointInitialization(
|
|
|
222
223
|
}
|
|
223
224
|
}
|
|
224
225
|
},
|
|
226
|
+
async initializeEarliestAvailableSlot(state) {
|
|
227
|
+
const stored = await db.earliestAvailableSlot.get();
|
|
228
|
+
const floor = useArchived ? (stored ?? state.slot) : Math.max(stored ?? 0, state.slot);
|
|
229
|
+
if (stored !== floor) {
|
|
230
|
+
await db.earliestAvailableSlot.set(floor);
|
|
231
|
+
}
|
|
232
|
+
logger.verbose("Initialized earliest available slot", {
|
|
233
|
+
source,
|
|
234
|
+
anchorSlot: state.slot,
|
|
235
|
+
previousSlot: stored,
|
|
236
|
+
earliestAvailableSlot: floor,
|
|
237
|
+
});
|
|
238
|
+
return floor;
|
|
239
|
+
},
|
|
225
240
|
persist: shouldPersist ? (state, bytes) => persistAnchorState(config, db, state, bytes) : null,
|
|
226
|
-
log(state) {
|
|
241
|
+
log(state, nativeStateTransition) {
|
|
227
242
|
const {checkpoint} = state.computeAnchorCheckpoint();
|
|
228
243
|
logger.info("Initialized checkpoint state", {
|
|
229
244
|
source,
|
|
@@ -233,6 +248,7 @@ function prepareCheckpointInitialization(
|
|
|
233
248
|
stateRoot: toRootHex(state.hashTreeRoot()),
|
|
234
249
|
checkpointRoot: toRootHex(checkpoint.root),
|
|
235
250
|
isFinalized,
|
|
251
|
+
nativeStateTransition,
|
|
236
252
|
...(isFinalized ? {} : {lastProcessedSlot: state.latestBlockHeader.slot}),
|
|
237
253
|
});
|
|
238
254
|
},
|
|
@@ -73,12 +73,26 @@ export async function prepareGenesisInitialization(
|
|
|
73
73
|
logger.warn("Checkpoint sync recommended, please use --help to see checkpoint sync options");
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
|
+
async initializeEarliestAvailableSlot(state) {
|
|
77
|
+
const stored = await db.earliestAvailableSlot.get();
|
|
78
|
+
if (stored !== null && stored !== state.slot) {
|
|
79
|
+
logger.warn("Resetting earliest available slot for genesis initialization", {
|
|
80
|
+
previousSlot: stored,
|
|
81
|
+
earliestAvailableSlot: state.slot,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (stored !== state.slot) {
|
|
85
|
+
await db.earliestAvailableSlot.set(state.slot);
|
|
86
|
+
}
|
|
87
|
+
return state.slot;
|
|
88
|
+
},
|
|
76
89
|
persist: (state, bytes) => persistAnchorState(config, db, state, bytes),
|
|
77
|
-
log(state) {
|
|
90
|
+
log(state, nativeStateTransition) {
|
|
78
91
|
logger.info("Initialized genesis state", {
|
|
79
92
|
slot: state.slot,
|
|
80
93
|
stateRoot: toRootHex(state.hashTreeRoot()),
|
|
81
94
|
isFinalized: true,
|
|
95
|
+
nativeStateTransition,
|
|
82
96
|
});
|
|
83
97
|
},
|
|
84
98
|
};
|
|
@@ -11,7 +11,7 @@ import {assertAnchorStateForkMatchesConfig} from "./validation.js";
|
|
|
11
11
|
|
|
12
12
|
export function prepareArchivedStateInitialization(
|
|
13
13
|
{stateBytes, metadata, isWithinWeakSubjectivityPeriod}: ArchivedStateBytes,
|
|
14
|
-
{chainForkConfig, logger}: StatePreparationContext
|
|
14
|
+
{chainForkConfig, db, logger}: StatePreparationContext
|
|
15
15
|
): StateInitialization {
|
|
16
16
|
const config = createBeaconConfig(chainForkConfig, metadata.genesisValidatorsRoot);
|
|
17
17
|
return {
|
|
@@ -34,13 +34,28 @@ export function prepareArchivedStateInitialization(
|
|
|
34
34
|
logger.warn("Checkpoint sync recommended, please use --help to see checkpoint sync options");
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
+
async initializeEarliestAvailableSlot(state) {
|
|
38
|
+
const stored = await db.earliestAvailableSlot.get();
|
|
39
|
+
// we bootstrap the node with archived db, use the previous earliestAvailableSLot
|
|
40
|
+
if (stored !== null) {
|
|
41
|
+
logger.verbose("Reusing persisted earliest available slot", {
|
|
42
|
+
anchorSlot: state.slot,
|
|
43
|
+
earliestAvailableSlot: stored,
|
|
44
|
+
});
|
|
45
|
+
return stored;
|
|
46
|
+
}
|
|
47
|
+
// legacy db: blockArchive.firstKey() is not a safe floor, a past checkpoint sync may have left a gap.
|
|
48
|
+
await db.earliestAvailableSlot.set(state.slot);
|
|
49
|
+
return state.slot;
|
|
50
|
+
},
|
|
37
51
|
persist: null,
|
|
38
|
-
log(state) {
|
|
52
|
+
log(state, nativeStateTransition) {
|
|
39
53
|
logger.info("Initialized state from db", {
|
|
40
54
|
slot: state.slot,
|
|
41
55
|
epoch: computeEpochAtSlot(state.slot),
|
|
42
56
|
stateRoot: toRootHex(state.hashTreeRoot()),
|
|
43
57
|
isFinalized: true,
|
|
58
|
+
nativeStateTransition,
|
|
44
59
|
});
|
|
45
60
|
},
|
|
46
61
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {IBeaconDb} from "@lodestar/beacon-node";
|
|
2
2
|
import {BeaconConfig, ChainForkConfig} from "@lodestar/config";
|
|
3
3
|
import {IBeaconStateView, StateBytesMetadata, WeakSubjectivitySummary} from "@lodestar/state-transition";
|
|
4
|
+
import {Slot} from "@lodestar/types";
|
|
4
5
|
import {Checkpoint} from "@lodestar/types/phase0";
|
|
5
6
|
import {Logger} from "@lodestar/utils";
|
|
6
7
|
import {GlobalArgs} from "../../../options/globalOptions.js";
|
|
@@ -18,7 +19,7 @@ export type StateInitializationOptions = Pick<
|
|
|
18
19
|
| "ignoreWeakSubjectivityCheck"
|
|
19
20
|
| "network"
|
|
20
21
|
| "chain.nHistoricalStatesFileDataStore"
|
|
21
|
-
| "chain.
|
|
22
|
+
| "chain.nativeStateTransition"
|
|
22
23
|
>;
|
|
23
24
|
|
|
24
25
|
export type StatePreparationContext = {
|
|
@@ -53,6 +54,7 @@ export type StateInitialization = {
|
|
|
53
54
|
config: BeaconConfig;
|
|
54
55
|
isFinalized: boolean;
|
|
55
56
|
validate: (state: IBeaconStateView) => void;
|
|
57
|
+
initializeEarliestAvailableSlot: (state: IBeaconStateView) => Promise<Slot>;
|
|
56
58
|
persist: ((state: IBeaconStateView, stateBytes: Uint8Array) => Promise<void>) | null;
|
|
57
|
-
log: (state: IBeaconStateView) => void;
|
|
59
|
+
log: (state: IBeaconStateView, nativeStateTransition: boolean) => void;
|
|
58
60
|
};
|
package/src/cmds/dev/handler.ts
CHANGED
|
@@ -31,7 +31,7 @@ export async function devHandler(args: IDevArgs & GlobalArgs): Promise<void> {
|
|
|
31
31
|
|
|
32
32
|
// Note: defaults to network "dev", to all paths are custom and don't conflict with networks.
|
|
33
33
|
// Flag --reset cleans up the custom dirs on dev stop
|
|
34
|
-
const beaconDbDir = getBeaconPaths(args, network)
|
|
34
|
+
const {dbDir: beaconDbDir, pubkeysFile} = getBeaconPaths(args, network);
|
|
35
35
|
const validatorsDbDir = getValidatorPaths(args, network).validatorsDbDir;
|
|
36
36
|
|
|
37
37
|
// Remove slashing protection db. Otherwise the validators won't be able to propose nor attest
|
|
@@ -39,6 +39,8 @@ export async function devHandler(args: IDevArgs & GlobalArgs): Promise<void> {
|
|
|
39
39
|
if (args.genesisTime === undefined) {
|
|
40
40
|
await rimraf(beaconDbDir);
|
|
41
41
|
await rimraf(validatorsDbDir);
|
|
42
|
+
// Validators deposited in the previous run do not exist on the new chain
|
|
43
|
+
await rimraf(pubkeysFile);
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
mkdir(beaconDbDir);
|
|
@@ -300,6 +300,17 @@ function getProposerConfigFromArgs(
|
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
+
const configs = [valProposerConfig.defaultConfig, ...Object.values(valProposerConfig.proposerConfig ?? {})];
|
|
304
|
+
if (
|
|
305
|
+
configs.some(
|
|
306
|
+
(config) =>
|
|
307
|
+
config.builder?.selection === routes.validator.BuilderSelection.ExecutionOnly &&
|
|
308
|
+
(config.builder.builders ?? []).length > 0
|
|
309
|
+
)
|
|
310
|
+
) {
|
|
311
|
+
throw new YargsError("Builder selection executiononly can not be combined with builders");
|
|
312
|
+
}
|
|
313
|
+
|
|
303
314
|
return valProposerConfig;
|
|
304
315
|
}
|
|
305
316
|
|
|
@@ -267,7 +267,7 @@ export const validatorOptions: CliCommandOptions<IValidatorCliArgs> = {
|
|
|
267
267
|
"builder.selection": {
|
|
268
268
|
type: "string",
|
|
269
269
|
description:
|
|
270
|
-
"Builder block selection strategy `default`, `maxprofit`, `builderalways`, `executionalways`, or
|
|
270
|
+
"Builder block selection strategy `default`, `maxprofit`, `builderalways`, `executionalways`, or `executiononly`",
|
|
271
271
|
defaultDescription: `${defaultOptions.builderSelection}`,
|
|
272
272
|
group: "builder",
|
|
273
273
|
},
|
|
@@ -12,6 +12,7 @@ export type ChainArgs = {
|
|
|
12
12
|
"chain.blsVerifyAllMainThread"?: boolean;
|
|
13
13
|
"chain.disableBlsBatchVerify"?: boolean;
|
|
14
14
|
"chain.persistProducedBlocks"?: boolean;
|
|
15
|
+
"chain.persistProducedPayloadEnvelopes"?: boolean;
|
|
15
16
|
"chain.persistInvalidSszObjects"?: boolean;
|
|
16
17
|
// No need to define chain.persistInvalidSszObjects as part of ChainArgs
|
|
17
18
|
// as this is defined as part of BeaconPaths
|
|
@@ -35,7 +36,7 @@ export type ChainArgs = {
|
|
|
35
36
|
"chain.archiveDataEpochs"?: number;
|
|
36
37
|
"chain.archiveMode": ArchiveMode;
|
|
37
38
|
"chain.nHistoricalStatesFileDataStore"?: boolean;
|
|
38
|
-
"chain.
|
|
39
|
+
"chain.nativeStateTransition"?: boolean;
|
|
39
40
|
"chain.maxBlockStates"?: number;
|
|
40
41
|
"chain.maxCPStateEpochsInMemory"?: number;
|
|
41
42
|
"chain.maxCPStateEpochsOnDisk"?: number;
|
|
@@ -53,6 +54,7 @@ export function parseArgs(args: ChainArgs & CircuitBreakerArgs): IBeaconNodeOpti
|
|
|
53
54
|
blsVerifyAllMainThread: args["chain.blsVerifyAllMainThread"],
|
|
54
55
|
disableBlsBatchVerify: args["chain.disableBlsBatchVerify"],
|
|
55
56
|
persistProducedBlocks: args["chain.persistProducedBlocks"],
|
|
57
|
+
persistProducedPayloadEnvelopes: args["chain.persistProducedPayloadEnvelopes"],
|
|
56
58
|
persistInvalidSszObjects: args["chain.persistInvalidSszObjects"],
|
|
57
59
|
// biome-ignore lint/suspicious/noExplicitAny: We need to use `any` type here
|
|
58
60
|
persistInvalidSszObjectsDir: undefined as any,
|
|
@@ -79,7 +81,7 @@ export function parseArgs(args: ChainArgs & CircuitBreakerArgs): IBeaconNodeOpti
|
|
|
79
81
|
archiveMode: args["chain.archiveMode"] ?? defaultOptions.chain.archiveMode,
|
|
80
82
|
nHistoricalStatesFileDataStore:
|
|
81
83
|
args["chain.nHistoricalStatesFileDataStore"] ?? defaultOptions.chain.nHistoricalStatesFileDataStore,
|
|
82
|
-
|
|
84
|
+
nativeStateTransition: args["chain.nativeStateTransition"] ?? defaultOptions.chain.nativeStateTransition,
|
|
83
85
|
maxBlockStates: args["chain.maxBlockStates"] ?? defaultOptions.chain.maxBlockStates,
|
|
84
86
|
maxCPStateEpochsInMemory: args["chain.maxCPStateEpochsInMemory"] ?? defaultOptions.chain.maxCPStateEpochsInMemory,
|
|
85
87
|
maxCPStateEpochsOnDisk: args["chain.maxCPStateEpochsOnDisk"] ?? defaultOptions.chain.maxCPStateEpochsOnDisk,
|
|
@@ -170,6 +172,13 @@ Will double processing times. Use only for debugging purposes.",
|
|
|
170
172
|
group: "chain",
|
|
171
173
|
},
|
|
172
174
|
|
|
175
|
+
"chain.persistProducedPayloadEnvelopes": {
|
|
176
|
+
hidden: true,
|
|
177
|
+
type: "boolean",
|
|
178
|
+
description: "Persist produced execution payload envelopes as SSZ files for debugging",
|
|
179
|
+
group: "chain",
|
|
180
|
+
},
|
|
181
|
+
|
|
173
182
|
"chain.persistInvalidSszObjects": {
|
|
174
183
|
hidden: true,
|
|
175
184
|
type: "boolean",
|
|
@@ -318,11 +327,11 @@ Will double processing times. Use only for debugging purposes.",
|
|
|
318
327
|
group: "chain",
|
|
319
328
|
},
|
|
320
329
|
|
|
321
|
-
"chain.
|
|
330
|
+
"chain.nativeStateTransition": {
|
|
322
331
|
hidden: true,
|
|
323
|
-
description: "Use native (Zig)
|
|
332
|
+
description: "Use native (Zig) state transition instead of JS implementation",
|
|
324
333
|
type: "boolean",
|
|
325
|
-
default: defaultOptions.chain.
|
|
334
|
+
default: defaultOptions.chain.nativeStateTransition,
|
|
326
335
|
group: "chain",
|
|
327
336
|
},
|
|
328
337
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import {IBeaconNodeOptions, defaultExecutionEngineHttpOpts} from "@lodestar/beacon-node";
|
|
2
|
+
import {EngineApiMode, IBeaconNodeOptions, defaultExecutionEngineHttpOpts, engineApiModes} from "@lodestar/beacon-node";
|
|
3
3
|
import {CliCommandOptions} from "@lodestar/utils";
|
|
4
4
|
import {extractJwtHexSecret} from "../../util/index.js";
|
|
5
5
|
|
|
@@ -8,6 +8,7 @@ export type ExecutionEngineArgs = {
|
|
|
8
8
|
"execution.timeout"?: number;
|
|
9
9
|
"execution.retries": number;
|
|
10
10
|
"execution.retryDelay": number;
|
|
11
|
+
"execution.engineApi"?: EngineApiMode;
|
|
11
12
|
"execution.engineMock"?: boolean;
|
|
12
13
|
jwtSecret?: string;
|
|
13
14
|
jwtId?: string;
|
|
@@ -26,6 +27,7 @@ export function parseArgs(args: ExecutionEngineArgs): IBeaconNodeOptions["execut
|
|
|
26
27
|
timeout: args["execution.timeout"],
|
|
27
28
|
retries: args["execution.retries"],
|
|
28
29
|
retryDelay: args["execution.retryDelay"],
|
|
30
|
+
engineApi: args["execution.engineApi"],
|
|
29
31
|
/**
|
|
30
32
|
* jwtSecret is parsed as hex instead of bytes because the merge with defaults
|
|
31
33
|
* in beaconOptions messes up the bytes array as as index => value object
|
|
@@ -69,6 +71,15 @@ export const options: CliCommandOptions<ExecutionEngineArgs> = {
|
|
|
69
71
|
group: "execution",
|
|
70
72
|
},
|
|
71
73
|
|
|
74
|
+
"execution.engineApi": {
|
|
75
|
+
description:
|
|
76
|
+
"Engine API transport. 'auto' negotiates REST with SSZ for a single execution URL and uses JSON-RPC for multiple URLs or unsupported features. 'ssz' requires a single REST-capable execution URL without JSON-RPC fallback. 'json-rpc' always uses JSON-RPC",
|
|
77
|
+
type: "string",
|
|
78
|
+
choices: engineApiModes,
|
|
79
|
+
default: defaultExecutionEngineHttpOpts.engineApi,
|
|
80
|
+
group: "execution",
|
|
81
|
+
},
|
|
82
|
+
|
|
72
83
|
"execution.engineMock": {
|
|
73
84
|
description: "Set the execution engine to mock mode (development only)",
|
|
74
85
|
type: "boolean",
|