@chainsafe/lodestar 1.50.0-dev.3579e999b5 → 1.50.0-dev.3bd495295e
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 +9 -21
- package/lib/cmds/beacon/handler.js.map +1 -1
- package/lib/cmds/beacon/initBeaconState.d.ts +11 -17
- package/lib/cmds/beacon/initBeaconState.d.ts.map +1 -1
- package/lib/cmds/beacon/initBeaconState.js +83 -275
- package/lib/cmds/beacon/initBeaconState.js.map +1 -1
- package/lib/cmds/beacon/options.d.ts +1 -1
- package/lib/cmds/beacon/options.d.ts.map +1 -1
- package/lib/cmds/beacon/options.js +6 -5
- 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.d.ts +7 -0
- package/lib/cmds/beacon/stateInitialization/checkpointState.d.ts.map +1 -0
- package/lib/cmds/beacon/stateInitialization/checkpointState.js +168 -0
- package/lib/cmds/beacon/stateInitialization/checkpointState.js.map +1 -0
- package/lib/cmds/beacon/stateInitialization/errors.d.ts +17 -0
- package/lib/cmds/beacon/stateInitialization/errors.d.ts.map +1 -0
- package/lib/cmds/beacon/stateInitialization/errors.js +16 -0
- package/lib/cmds/beacon/stateInitialization/errors.js.map +1 -0
- package/lib/cmds/beacon/stateInitialization/genesisState.d.ts +3 -0
- package/lib/cmds/beacon/stateInitialization/genesisState.d.ts.map +1 -0
- package/lib/cmds/beacon/stateInitialization/genesisState.js +65 -0
- package/lib/cmds/beacon/stateInitialization/genesisState.js.map +1 -0
- package/lib/cmds/beacon/stateInitialization/prepareStateInitialization.d.ts +4 -0
- package/lib/cmds/beacon/stateInitialization/prepareStateInitialization.d.ts.map +1 -0
- package/lib/cmds/beacon/stateInitialization/prepareStateInitialization.js +52 -0
- package/lib/cmds/beacon/stateInitialization/prepareStateInitialization.js.map +1 -0
- package/lib/cmds/beacon/stateInitialization/types.d.ts +40 -0
- package/lib/cmds/beacon/stateInitialization/types.d.ts.map +1 -0
- package/lib/cmds/beacon/stateInitialization/types.js +2 -0
- package/lib/cmds/beacon/stateInitialization/types.js.map +1 -0
- package/lib/cmds/beacon/stateInitialization/validation.d.ts +4 -0
- package/lib/cmds/beacon/stateInitialization/validation.d.ts.map +1 -0
- package/lib/cmds/beacon/stateInitialization/validation.js +12 -0
- package/lib/cmds/beacon/stateInitialization/validation.js.map +1 -0
- 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/networks/index.d.ts +3 -9
- package/lib/networks/index.d.ts.map +1 -1
- package/lib/networks/index.js +15 -28
- package/lib/networks/index.js.map +1 -1
- package/package.json +14 -14
- package/src/cmds/beacon/handler.ts +11 -22
- package/src/cmds/beacon/initBeaconState.ts +128 -386
- package/src/cmds/beacon/options.ts +8 -7
- package/src/cmds/beacon/paths.ts +5 -0
- package/src/cmds/beacon/pubkeysFile.ts +50 -0
- package/src/cmds/beacon/stateInitialization/checkpointState.ts +256 -0
- package/src/cmds/beacon/stateInitialization/errors.ts +15 -0
- package/src/cmds/beacon/stateInitialization/genesisState.ts +85 -0
- package/src/cmds/beacon/stateInitialization/prepareStateInitialization.ts +64 -0
- package/src/cmds/beacon/stateInitialization/types.ts +58 -0
- package/src/cmds/beacon/stateInitialization/validation.ts +16 -0
- package/src/cmds/dev/handler.ts +3 -1
- package/src/networks/index.ts +25 -40
package/src/networks/index.ts
CHANGED
|
@@ -4,15 +4,9 @@ import {WireFormat, getClient} from "@lodestar/api";
|
|
|
4
4
|
import {getStateSlotFromBytes} from "@lodestar/beacon-node";
|
|
5
5
|
import {ChainConfig, ChainForkConfig} from "@lodestar/config";
|
|
6
6
|
import {SLOTS_PER_EPOCH} from "@lodestar/params";
|
|
7
|
-
import {
|
|
8
|
-
BeaconStateAllForks,
|
|
9
|
-
computeCheckpointEpochAtStateSlot,
|
|
10
|
-
getLatestBlockRoot,
|
|
11
|
-
loadState,
|
|
12
|
-
} from "@lodestar/state-transition";
|
|
13
|
-
import {Slot, sszTypesFor} from "@lodestar/types";
|
|
7
|
+
import {Slot} from "@lodestar/types";
|
|
14
8
|
import {Checkpoint} from "@lodestar/types/phase0";
|
|
15
|
-
import {Logger, callFnWhenAwait, fetch, formatBytes, fromHex} from "@lodestar/utils";
|
|
9
|
+
import {LodestarError, Logger, callFnWhenAwait, fetch, formatBytes, fromHex} from "@lodestar/utils";
|
|
16
10
|
import {parseBootnodesFile} from "../util/format.js";
|
|
17
11
|
import * as chiado from "./chiado.js";
|
|
18
12
|
import * as dev from "./dev.js";
|
|
@@ -160,15 +154,11 @@ export function readBootnodes(bootnodesFilePath: string): string[] {
|
|
|
160
154
|
/**
|
|
161
155
|
* Fetch weak subjectivity state from a remote beacon node
|
|
162
156
|
*/
|
|
163
|
-
export async function
|
|
157
|
+
export async function fetchWeakSubjectivityStateBytes(
|
|
164
158
|
config: ChainForkConfig,
|
|
165
159
|
logger: Logger,
|
|
166
|
-
{checkpointSyncUrl, wssCheckpoint}: {checkpointSyncUrl: string; wssCheckpoint?: string}
|
|
167
|
-
|
|
168
|
-
lastDbState,
|
|
169
|
-
lastDbValidatorsBytes,
|
|
170
|
-
}: {lastDbState: BeaconStateAllForks | null; lastDbValidatorsBytes: Uint8Array | null}
|
|
171
|
-
): Promise<{wsState: BeaconStateAllForks; wsStateBytes: Uint8Array; wsCheckpoint: Checkpoint}> {
|
|
160
|
+
{checkpointSyncUrl, wssCheckpoint}: {checkpointSyncUrl: string; wssCheckpoint?: string}
|
|
161
|
+
): Promise<{stateBytes: Uint8Array; expectedCheckpoint: Checkpoint | null}> {
|
|
172
162
|
try {
|
|
173
163
|
let wsCheckpoint: Checkpoint | null;
|
|
174
164
|
let stateId: Slot | "finalized";
|
|
@@ -178,7 +168,7 @@ export async function fetchWeakSubjectivityState(
|
|
|
178
168
|
wsCheckpoint = getCheckpointFromArg(wssCheckpoint);
|
|
179
169
|
stateId = wsCheckpoint.epoch * SLOTS_PER_EPOCH;
|
|
180
170
|
} else {
|
|
181
|
-
//
|
|
171
|
+
// Checkpoint identity can be derived after the selected state is constructed.
|
|
182
172
|
stateId = "finalized";
|
|
183
173
|
wsCheckpoint = null;
|
|
184
174
|
}
|
|
@@ -186,33 +176,37 @@ export async function fetchWeakSubjectivityState(
|
|
|
186
176
|
// getStateV2 should be available for all forks including phase0
|
|
187
177
|
const getStatePromise = api.debug.getStateV2({stateId}, {responseWireFormat: WireFormat.ssz});
|
|
188
178
|
|
|
189
|
-
const
|
|
179
|
+
const response = await callFnWhenAwait(
|
|
190
180
|
getStatePromise,
|
|
191
181
|
() => logger.info("Download in progress, please wait..."),
|
|
192
182
|
GET_STATE_LOG_INTERVAL
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
});
|
|
183
|
+
);
|
|
184
|
+
const wsStateBytes = response.ssz();
|
|
185
|
+
const {version} = response.meta();
|
|
196
186
|
|
|
197
187
|
const wsSlot = getStateSlotFromBytes(wsStateBytes);
|
|
198
188
|
const logData = {stateId, size: formatBytes(wsStateBytes.length)};
|
|
199
189
|
logger.info("Download completed", typeof stateId === "number" ? logData : {...logData, slot: wsSlot});
|
|
200
190
|
|
|
201
|
-
|
|
202
|
-
if (
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
191
|
+
const expectedFork = config.getForkName(wsSlot);
|
|
192
|
+
if (version !== expectedFork) {
|
|
193
|
+
throw new LodestarError(
|
|
194
|
+
{code: "CHECKPOINT_FORK_MISMATCH"},
|
|
195
|
+
`Checkpoint sync server returned ${version} state at slot ${wsSlot} but local config expects ${expectedFork}, verify --network or the chain config`
|
|
196
|
+
);
|
|
207
197
|
}
|
|
208
198
|
|
|
209
199
|
return {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
wsCheckpoint: wsCheckpoint ?? getCheckpointFromState(wsState),
|
|
200
|
+
stateBytes: new Uint8Array(wsStateBytes.buffer, wsStateBytes.byteOffset, wsStateBytes.byteLength),
|
|
201
|
+
expectedCheckpoint: wsCheckpoint,
|
|
213
202
|
};
|
|
214
203
|
} catch (e) {
|
|
215
|
-
|
|
204
|
+
const error = new LodestarError(
|
|
205
|
+
{code: "CHECKPOINT_DOWNLOAD_FAILED"},
|
|
206
|
+
"Unable to fetch weak subjectivity state: " + (e as Error).message
|
|
207
|
+
);
|
|
208
|
+
error.cause = e;
|
|
209
|
+
throw error;
|
|
216
210
|
}
|
|
217
211
|
}
|
|
218
212
|
|
|
@@ -220,16 +214,7 @@ export function getCheckpointFromArg(checkpointStr: string): Checkpoint {
|
|
|
220
214
|
const checkpointRegex = /^(?:0x)?([0-9a-f]{64}):([0-9]+)$/;
|
|
221
215
|
const match = checkpointRegex.exec(checkpointStr.toLowerCase());
|
|
222
216
|
if (!match) {
|
|
223
|
-
throw new
|
|
217
|
+
throw new LodestarError({code: "INVALID_CHECKPOINT"}, `Could not parse checkpoint string: ${checkpointStr}`);
|
|
224
218
|
}
|
|
225
219
|
return {root: fromHex(match[1]), epoch: parseInt(match[2])};
|
|
226
220
|
}
|
|
227
|
-
|
|
228
|
-
export function getCheckpointFromState(state: BeaconStateAllForks): Checkpoint {
|
|
229
|
-
return {
|
|
230
|
-
// the correct checkpoint is based on state's slot, its latestBlockHeader's slot's epoch can be
|
|
231
|
-
// behind the state
|
|
232
|
-
epoch: computeCheckpointEpochAtStateSlot(state.slot),
|
|
233
|
-
root: getLatestBlockRoot(state),
|
|
234
|
-
};
|
|
235
|
-
}
|