@chainsafe/lodestar 1.50.0-dev.fef46df5ba → 1.50.0
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 +2 -2
- 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 +26 -13
- 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.js +24 -8
- package/lib/cmds/beacon/stateInitialization/checkpointState.js.map +1 -1
- package/lib/cmds/beacon/stateInitialization/genesisState.d.ts +1 -1
- package/lib/cmds/beacon/stateInitialization/genesisState.d.ts.map +1 -1
- package/lib/cmds/beacon/stateInitialization/genesisState.js +17 -3
- package/lib/cmds/beacon/stateInitialization/genesisState.js.map +1 -1
- package/lib/cmds/beacon/stateInitialization/prepareStateInitialization.d.ts +2 -2
- package/lib/cmds/beacon/stateInitialization/prepareStateInitialization.d.ts.map +1 -1
- package/lib/cmds/beacon/stateInitialization/prepareStateInitialization.js +20 -8
- 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/index.js +0 -0
- package/lib/networks/index.d.ts.map +1 -1
- package/lib/networks/index.js +5 -0
- package/lib/networks/index.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 +40 -13
- 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 +28 -12
- package/src/cmds/beacon/stateInitialization/genesisState.ts +18 -4
- package/src/cmds/beacon/stateInitialization/prepareStateInitialization.ts +21 -8
- package/src/cmds/beacon/stateInitialization/types.ts +4 -3
- 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/networks/index.ts +9 -0
- package/src/options/beaconNodeOptions/chain.ts +14 -5
- package/src/options/beaconNodeOptions/execution.ts +12 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../../../src/options/beaconNodeOptions/execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,
|
|
1
|
+
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../../../src/options/beaconNodeOptions/execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAoC,8BAA8B,EAAE,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAExH,OAAO,EAAC,mBAAmB,EAAC,MAAM,qBAAqB,CAAC;AAaxD,MAAM,UAAU,SAAS,CAAC,IAAyB;IACjD,IAAI,IAAI,CAAC,sBAAsB,CAAC,EAAE,CAAC;QACjC,sEAAsE;QACtE,OAAO;YACL,IAAI,EAAE,MAAM;SACb,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,gBAAgB,CAAC;QAC5B,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC;QAClC,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC;QAClC,UAAU,EAAE,IAAI,CAAC,sBAAsB,CAAC;QACxC,SAAS,EAAE,IAAI,CAAC,qBAAqB,CAAC;QACtC;;;WAGG;QACH,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,mBAAmB,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS;QAC/G,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAA2C;IAC7D,gBAAgB,EAAE;QAChB,WAAW,EAAE,qCAAqC;QAClD,OAAO,EAAE,8BAA8B,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;QACtD,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,IAAI;QACZ,MAAM,EAAE,CAAC,IAAc,EAAY,EAAE;QACnC,0CAA0C;QAC1C,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACzC,KAAK,EAAE,WAAW;KACnB;IAED,mBAAmB,EAAE;QACnB,WAAW,EAAE,8DAA8D;QAC3E,IAAI,EAAE,QAAQ;QACd,kBAAkB,EAAE,MAAM,CAAC,8BAA8B,CAAC,OAAO,CAAC;QAClE,KAAK,EAAE,WAAW;KACnB;IAED,mBAAmB,EAAE;QACnB,KAAK,EAAE,CAAC,yBAAyB,CAAC;QAClC,WAAW,EAAE,qDAAqD;QAClE,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,8BAA8B,CAAC,OAAO;QAC/C,KAAK,EAAE,WAAW;KACnB;IAED,sBAAsB,EAAE;QACtB,WAAW,EAAE,4FAA4F;QACzG,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,8BAA8B,CAAC,UAAU;QAClD,KAAK,EAAE,WAAW;KACnB;IAED,qBAAqB,EAAE;QACrB,WAAW,EACT,6PAA6P;QAC/P,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,cAAc;QACvB,OAAO,EAAE,8BAA8B,CAAC,SAAS;QACjD,KAAK,EAAE,WAAW;KACnB;IAED,sBAAsB,EAAE;QACtB,WAAW,EAAE,0DAA0D;QACvE,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,WAAW;KACnB;IAED,SAAS,EAAE;QACT,WAAW,EACT,mQAAmQ;QACrQ,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,WAAW;KACnB;IAED,KAAK,EAAE;QACL,WAAW,EACT,+JAA+J;QACjK,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,WAAW;KACnB;CACF,CAAC"}
|
|
@@ -43,6 +43,7 @@ export declare const beaconNodeOptions: {
|
|
|
43
43
|
"chain.blsVerifyAllMainThread": import("@lodestar/utils").CliOptionDefinition<boolean | undefined>;
|
|
44
44
|
"chain.disableBlsBatchVerify": import("@lodestar/utils").CliOptionDefinition<boolean | undefined>;
|
|
45
45
|
"chain.persistProducedBlocks": import("@lodestar/utils").CliOptionDefinition<boolean | undefined>;
|
|
46
|
+
"chain.persistProducedPayloadEnvelopes": import("@lodestar/utils").CliOptionDefinition<boolean | undefined>;
|
|
46
47
|
"chain.persistInvalidSszObjects": import("@lodestar/utils").CliOptionDefinition<boolean | undefined>;
|
|
47
48
|
"chain.persistOrphanedBlocks": import("@lodestar/utils").CliOptionDefinition<boolean | undefined>;
|
|
48
49
|
"chain.dedupePayloads": import("@lodestar/utils").CliOptionDefinition<boolean | undefined>;
|
|
@@ -67,7 +68,7 @@ export declare const beaconNodeOptions: {
|
|
|
67
68
|
demandOption: true;
|
|
68
69
|
});
|
|
69
70
|
"chain.nHistoricalStatesFileDataStore": import("@lodestar/utils").CliOptionDefinition<boolean | undefined>;
|
|
70
|
-
"chain.
|
|
71
|
+
"chain.nativeStateTransition": import("@lodestar/utils").CliOptionDefinition<boolean | undefined>;
|
|
71
72
|
"chain.maxBlockStates": import("@lodestar/utils").CliOptionDefinition<number | undefined>;
|
|
72
73
|
"chain.maxCPStateEpochsInMemory": import("@lodestar/utils").CliOptionDefinition<number | undefined>;
|
|
73
74
|
"chain.maxCPStateEpochsOnDisk": import("@lodestar/utils").CliOptionDefinition<number | undefined>;
|
|
@@ -88,6 +89,7 @@ export declare const beaconNodeOptions: {
|
|
|
88
89
|
"execution.retryDelay": import("@lodestar/utils").CliOptionDefinition<number> & (Required<Pick<import("yargs").Options, "default">> | {
|
|
89
90
|
demandOption: true;
|
|
90
91
|
});
|
|
92
|
+
"execution.engineApi": import("@lodestar/utils").CliOptionDefinition<import("@lodestar/beacon-node").EngineApiMode | undefined>;
|
|
91
93
|
"execution.engineMock": import("@lodestar/utils").CliOptionDefinition<boolean | undefined>;
|
|
92
94
|
jwtSecret: import("@lodestar/utils").CliOptionDefinition<string | undefined>;
|
|
93
95
|
jwtId: import("@lodestar/utils").CliOptionDefinition<string | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/options/beaconNodeOptions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC,OAAO,GACtC,KAAK,CAAC,SAAS,GACf,IAAI,CAAC,QAAQ,GACb,SAAS,CAAC,mBAAmB,GAC7B,OAAO,CAAC,oBAAoB,GAC5B,OAAO,CAAC,WAAW,GACnB,UAAU,CAAC,cAAc,GACzB,OAAO,CAAC,WAAW,GACnB,IAAI,CAAC,QAAQ,CAAC;AAEhB,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,cAAc,GAAG,gBAAgB,CAAC,kBAAkB,CAAC,CAa9F;AAED,eAAO,MAAM,iBAAiB
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/options/beaconNodeOptions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC,OAAO,GACtC,KAAK,CAAC,SAAS,GACf,IAAI,CAAC,QAAQ,GACb,SAAS,CAAC,mBAAmB,GAC7B,OAAO,CAAC,oBAAoB,GAC5B,OAAO,CAAC,WAAW,GACnB,UAAU,CAAC,cAAc,GACzB,OAAO,CAAC,WAAW,GACnB,IAAI,CAAC,QAAQ,CAAC;AAEhB,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,cAAc,GAAG,gBAAgB,CAAC,kBAAkB,CAAC,CAa9F;AAED,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAU7B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainsafe/lodestar",
|
|
3
|
-
"version": "1.50.0
|
|
3
|
+
"version": "1.50.0",
|
|
4
4
|
"description": "Command line interface for lodestar",
|
|
5
5
|
"author": "ChainSafe Systems",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -63,22 +63,22 @@
|
|
|
63
63
|
"@chainsafe/enr": "^6.0.2",
|
|
64
64
|
"@chainsafe/lodestar-z": "catalog:",
|
|
65
65
|
"@chainsafe/persistent-merkle-tree": "^1.3.1",
|
|
66
|
-
"@chainsafe/ssz": "^1.8.
|
|
66
|
+
"@chainsafe/ssz": "^1.8.1",
|
|
67
67
|
"@chainsafe/threads": "^1.11.3",
|
|
68
68
|
"@libp2p/crypto": "^5.1.23",
|
|
69
69
|
"@libp2p/interface": "^3.3.0",
|
|
70
70
|
"@libp2p/peer-id": "^6.0.15",
|
|
71
|
-
"@lodestar/api": "^1.50.0
|
|
72
|
-
"@lodestar/beacon-node": "^1.50.0
|
|
73
|
-
"@lodestar/builder": "^1.50.0
|
|
74
|
-
"@lodestar/config": "^1.50.0
|
|
75
|
-
"@lodestar/db": "^1.50.0
|
|
76
|
-
"@lodestar/logger": "^1.50.0
|
|
77
|
-
"@lodestar/params": "^1.50.0
|
|
78
|
-
"@lodestar/state-transition": "^1.50.0
|
|
79
|
-
"@lodestar/types": "^1.50.0
|
|
80
|
-
"@lodestar/utils": "^1.50.0
|
|
81
|
-
"@lodestar/validator": "^1.50.0
|
|
71
|
+
"@lodestar/api": "^1.50.0",
|
|
72
|
+
"@lodestar/beacon-node": "^1.50.0",
|
|
73
|
+
"@lodestar/builder": "^1.50.0",
|
|
74
|
+
"@lodestar/config": "^1.50.0",
|
|
75
|
+
"@lodestar/db": "^1.50.0",
|
|
76
|
+
"@lodestar/logger": "^1.50.0",
|
|
77
|
+
"@lodestar/params": "^1.50.0",
|
|
78
|
+
"@lodestar/state-transition": "^1.50.0",
|
|
79
|
+
"@lodestar/types": "^1.50.0",
|
|
80
|
+
"@lodestar/utils": "^1.50.0",
|
|
81
|
+
"@lodestar/validator": "^1.50.0",
|
|
82
82
|
"@multiformats/multiaddr": "^13.0.1",
|
|
83
83
|
"deepmerge": "^4.3.1",
|
|
84
84
|
"ethers": "^6.7.0",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"devDependencies": {
|
|
95
95
|
"@chainsafe/as-sha256": "^1.2.5",
|
|
96
96
|
"@ethereumjs/rlp": "^4.0.1",
|
|
97
|
-
"@lodestar/test-utils": "^1.50.0
|
|
97
|
+
"@lodestar/test-utils": "^1.50.0",
|
|
98
98
|
"@types/debug": "^4.1.7",
|
|
99
99
|
"@types/inquirer": "^9.0.3",
|
|
100
100
|
"@types/js-yaml": "^4.0.5",
|
|
@@ -108,5 +108,5 @@
|
|
|
108
108
|
"web3": "^4.0.3",
|
|
109
109
|
"web3-eth-accounts": "^4.0.3"
|
|
110
110
|
},
|
|
111
|
-
"gitHead": "
|
|
111
|
+
"gitHead": "003bd66543fa65b5c1e954eec9e8077054c226dc"
|
|
112
112
|
}
|
|
@@ -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,13 +10,16 @@ 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";
|
|
19
|
+
import {prepareGenesisInitialization} from "./stateInitialization/genesisState.js";
|
|
17
20
|
import {
|
|
18
21
|
prepareArchivedStateInitialization,
|
|
19
|
-
|
|
22
|
+
prepareCheckpointSourceInitialization,
|
|
20
23
|
} from "./stateInitialization/prepareStateInitialization.js";
|
|
21
24
|
import {
|
|
22
25
|
ArchivedStateBytes,
|
|
@@ -25,21 +28,27 @@ import {
|
|
|
25
28
|
StatePreparationContext,
|
|
26
29
|
} from "./stateInitialization/types.js";
|
|
27
30
|
|
|
28
|
-
type InitBeaconStateResult = {
|
|
31
|
+
type InitBeaconStateResult = {
|
|
32
|
+
anchorState: IBeaconStateView;
|
|
33
|
+
config: BeaconConfig;
|
|
34
|
+
isFinalized: boolean;
|
|
35
|
+
earliestAvailableSlot: Slot;
|
|
36
|
+
};
|
|
29
37
|
|
|
30
38
|
/**
|
|
31
39
|
* Select serialized anchor bytes before constructing the state used for validation, persistence, and return.
|
|
32
|
-
* 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.
|
|
33
41
|
*/
|
|
34
42
|
export async function initBeaconState(
|
|
35
43
|
args: BeaconArgs & GlobalArgs,
|
|
36
44
|
dataDir: string,
|
|
45
|
+
pubkeysFile: string,
|
|
37
46
|
chainForkConfig: ChainForkConfig,
|
|
38
47
|
db: IBeaconDb,
|
|
39
48
|
logger: Logger
|
|
40
49
|
): Promise<InitBeaconStateResult> {
|
|
41
50
|
const options: StateInitializationOptions = args;
|
|
42
|
-
const
|
|
51
|
+
const nativeStateTransition = options["chain.nativeStateTransition"] ?? false;
|
|
43
52
|
if (
|
|
44
53
|
options.forceCheckpointSync &&
|
|
45
54
|
!(options.checkpointState || options.checkpointSyncUrl || options.unsafeCheckpointState)
|
|
@@ -65,11 +74,23 @@ export async function initBeaconState(
|
|
|
65
74
|
options.lastPersistedCheckpointState
|
|
66
75
|
);
|
|
67
76
|
if (!options.forceCheckpointSync && (!hasCheckpointSource || archived.isWithinWeakSubjectivityPeriod)) {
|
|
68
|
-
return executeStateInitialization(
|
|
77
|
+
return executeStateInitialization(
|
|
78
|
+
prepareArchivedStateInitialization(archived, context),
|
|
79
|
+
nativeStateTransition,
|
|
80
|
+
pubkeysFile,
|
|
81
|
+
logger
|
|
82
|
+
);
|
|
69
83
|
}
|
|
70
84
|
}
|
|
71
|
-
|
|
72
|
-
|
|
85
|
+
let stateInit = await prepareCheckpointSourceInitialization(options, archived, context);
|
|
86
|
+
if (stateInit === null) {
|
|
87
|
+
// Without a usable checkpoint state, resume from the db as if no checkpoint source was set instead of genesis
|
|
88
|
+
stateInit =
|
|
89
|
+
archived !== null
|
|
90
|
+
? prepareArchivedStateInitialization(archived, context)
|
|
91
|
+
: await prepareGenesisInitialization(options, context);
|
|
92
|
+
}
|
|
93
|
+
return executeStateInitialization(stateInit, nativeStateTransition, pubkeysFile, logger);
|
|
73
94
|
}
|
|
74
95
|
|
|
75
96
|
/**
|
|
@@ -97,7 +118,7 @@ async function readLatestArchivedStateBytes({
|
|
|
97
118
|
if (weakSubjectivity === null) {
|
|
98
119
|
throw new StateInitializationError(
|
|
99
120
|
{code: StateInitializationErrorCode.MALFORMED_STATE_BYTES},
|
|
100
|
-
|
|
121
|
+
`Cannot extract weak subjectivity summary from archived state bytes, expected ${chainForkConfig.getForkName(metadata.slot)} state at slot ${metadata.slot}, possible fork or network mismatch`
|
|
101
122
|
);
|
|
102
123
|
}
|
|
103
124
|
return {
|
|
@@ -114,7 +135,9 @@ async function readLatestArchivedStateBytes({
|
|
|
114
135
|
*/
|
|
115
136
|
async function executeStateInitialization(
|
|
116
137
|
stateInit: StateInitialization,
|
|
117
|
-
|
|
138
|
+
nativeStateTransition: boolean,
|
|
139
|
+
pubkeysFile: string,
|
|
140
|
+
logger: Logger
|
|
118
141
|
): Promise<InitBeaconStateResult> {
|
|
119
142
|
const {config, stateBytes} = stateInit;
|
|
120
143
|
const validatorCount = getValidatorCountFromStateBytes(config, stateBytes);
|
|
@@ -129,10 +152,14 @@ async function executeStateInitialization(
|
|
|
129
152
|
// by its native lock; if this headroom is exceeded, it grows by the same fixed step.
|
|
130
153
|
// The view syncs pubkeys during construction, so capacity must be reserved first.
|
|
131
154
|
const headroomEpochs = (90 * 24 * 60 * 60) / (config.SECONDS_PER_SLOT * SLOTS_PER_EPOCH);
|
|
132
|
-
|
|
133
|
-
|
|
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});
|
|
134
160
|
stateInit.validate(anchorState);
|
|
161
|
+
const earliestAvailableSlot = await stateInit.initializeEarliestAvailableSlot(anchorState);
|
|
135
162
|
await stateInit.persist?.(anchorState, stateBytes);
|
|
136
|
-
stateInit.log(anchorState);
|
|
137
|
-
return {anchorState, config, isFinalized: stateInit.isFinalized};
|
|
163
|
+
stateInit.log(anchorState, nativeStateTransition);
|
|
164
|
+
return {anchorState, config, isFinalized: stateInit.isFinalized, earliestAvailableSlot};
|
|
138
165
|
}
|
|
@@ -4,7 +4,6 @@ import {LogArgs, logOptions} from "../../options/logOptions.js";
|
|
|
4
4
|
import {BeaconPaths, defaultBeaconPaths} from "./paths.js";
|
|
5
5
|
|
|
6
6
|
type BeaconExtraArgs = {
|
|
7
|
-
forceGenesis?: boolean;
|
|
8
7
|
genesisStateFile?: string;
|
|
9
8
|
configFile?: string;
|
|
10
9
|
bootnodesFile?: string;
|
|
@@ -22,6 +21,7 @@ type BeaconExtraArgs = {
|
|
|
22
21
|
persistInvalidSszObjectsRetentionHours?: number;
|
|
23
22
|
persistOrphanedBlocksDir?: string;
|
|
24
23
|
peerStoreDir?: string;
|
|
24
|
+
pubkeysFile?: string;
|
|
25
25
|
persistNetworkIdentity?: boolean;
|
|
26
26
|
private?: boolean;
|
|
27
27
|
validatorMonitorLogs?: boolean;
|
|
@@ -30,12 +30,6 @@ type BeaconExtraArgs = {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
export const beaconExtraOptions: CliCommandOptions<BeaconExtraArgs> = {
|
|
33
|
-
forceGenesis: {
|
|
34
|
-
description: "Force beacon to create genesis without file",
|
|
35
|
-
type: "boolean",
|
|
36
|
-
hidden: true,
|
|
37
|
-
},
|
|
38
|
-
|
|
39
33
|
genesisStateFile: {
|
|
40
34
|
description: "Path or URL to download a genesis state file in ssz-encoded format",
|
|
41
35
|
type: "string",
|
|
@@ -148,6 +142,13 @@ export const beaconExtraOptions: CliCommandOptions<BeaconExtraArgs> = {
|
|
|
148
142
|
type: "string",
|
|
149
143
|
},
|
|
150
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
|
+
|
|
151
152
|
persistNetworkIdentity: {
|
|
152
153
|
description:
|
|
153
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
|
+
}
|
|
@@ -178,7 +178,7 @@ function prepareCheckpointInitialization(
|
|
|
178
178
|
if (weakSubjectivity === null) {
|
|
179
179
|
throw new StateInitializationError(
|
|
180
180
|
{code: StateInitializationErrorCode.MALFORMED_STATE_BYTES},
|
|
181
|
-
`Cannot extract weak subjectivity summary from ${candidate.source}`
|
|
181
|
+
`Cannot extract weak subjectivity summary from ${candidate.source}, expected ${chainForkConfig.getForkName(metadata.slot)} state at slot ${metadata.slot}, possible fork or network mismatch`
|
|
182
182
|
);
|
|
183
183
|
}
|
|
184
184
|
const expectedCheckpoint = useArchived ? null : candidate.expectedCheckpoint;
|
|
@@ -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,17 +205,8 @@ 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
|
-
|
|
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
|
-
}
|
|
208
|
+
assertAnchorStateForkMatchesConfig(config, state);
|
|
207
209
|
if (isFinalized) {
|
|
208
|
-
assertAnchorStateForkMatchesConfig(config, state);
|
|
209
210
|
const source = useArchived ? "db" : "checkpoint";
|
|
210
211
|
const logData = {
|
|
211
212
|
slot: state.slot,
|
|
@@ -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
|
},
|
|
@@ -15,11 +15,11 @@ import {StateInitialization, StateInitializationOptions, StatePreparationContext
|
|
|
15
15
|
import {assertAnchorStateForkMatchesConfig} from "./validation.js";
|
|
16
16
|
|
|
17
17
|
export async function prepareGenesisInitialization(
|
|
18
|
-
options: Pick<StateInitializationOptions, "genesisStateFile" | "network"
|
|
18
|
+
options: Pick<StateInitializationOptions, "genesisStateFile" | "network">,
|
|
19
19
|
{chainForkConfig, db, logger}: StatePreparationContext
|
|
20
20
|
): Promise<StateInitialization> {
|
|
21
21
|
const source = options.genesisStateFile || getGenesisFileUrl(options.network || defaultNetwork);
|
|
22
|
-
if (!source
|
|
22
|
+
if (!source) {
|
|
23
23
|
throw new StateInitializationError(
|
|
24
24
|
{code: StateInitializationErrorCode.MISSING_INITIALIZATION_SOURCE},
|
|
25
25
|
"Failed to initialize beacon state, please provide a genesis state file or use checkpoint sync"
|
|
@@ -40,7 +40,7 @@ export async function prepareGenesisInitialization(
|
|
|
40
40
|
if (weakSubjectivity === null) {
|
|
41
41
|
throw new StateInitializationError(
|
|
42
42
|
{code: StateInitializationErrorCode.MALFORMED_STATE_BYTES},
|
|
43
|
-
|
|
43
|
+
`Cannot extract weak subjectivity summary from genesis state bytes, expected ${chainForkConfig.getForkName(metadata.slot)} state at slot ${metadata.slot}, possible fork or network mismatch`
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
const config = createBeaconConfig(chainForkConfig, metadata.genesisValidatorsRoot);
|
|
@@ -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
|
};
|
|
@@ -6,13 +6,12 @@ import {
|
|
|
6
6
|
prepareCheckpointFileInitialization,
|
|
7
7
|
prepareUnfinalizedCheckpointInitialization,
|
|
8
8
|
} from "./checkpointState.js";
|
|
9
|
-
import {prepareGenesisInitialization} from "./genesisState.js";
|
|
10
9
|
import {ArchivedStateBytes, StateInitialization, StateInitializationOptions, StatePreparationContext} from "./types.js";
|
|
11
10
|
import {assertAnchorStateForkMatchesConfig} from "./validation.js";
|
|
12
11
|
|
|
13
12
|
export function prepareArchivedStateInitialization(
|
|
14
13
|
{stateBytes, metadata, isWithinWeakSubjectivityPeriod}: ArchivedStateBytes,
|
|
15
|
-
{chainForkConfig, logger}: StatePreparationContext
|
|
14
|
+
{chainForkConfig, db, logger}: StatePreparationContext
|
|
16
15
|
): StateInitialization {
|
|
17
16
|
const config = createBeaconConfig(chainForkConfig, metadata.genesisValidatorsRoot);
|
|
18
17
|
return {
|
|
@@ -35,23 +34,38 @@ export function prepareArchivedStateInitialization(
|
|
|
35
34
|
logger.warn("Checkpoint sync recommended, please use --help to see checkpoint sync options");
|
|
36
35
|
}
|
|
37
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
|
+
},
|
|
38
51
|
persist: null,
|
|
39
|
-
log(state) {
|
|
52
|
+
log(state, nativeStateTransition) {
|
|
40
53
|
logger.info("Initialized state from db", {
|
|
41
54
|
slot: state.slot,
|
|
42
55
|
epoch: computeEpochAtSlot(state.slot),
|
|
43
56
|
stateRoot: toRootHex(state.hashTreeRoot()),
|
|
44
57
|
isFinalized: true,
|
|
58
|
+
nativeStateTransition,
|
|
45
59
|
});
|
|
46
60
|
},
|
|
47
61
|
};
|
|
48
62
|
}
|
|
49
63
|
|
|
50
|
-
export async function
|
|
64
|
+
export async function prepareCheckpointSourceInitialization(
|
|
51
65
|
options: StateInitializationOptions,
|
|
52
66
|
archived: ArchivedStateBytes | null,
|
|
53
67
|
context: StatePreparationContext
|
|
54
|
-
): Promise<StateInitialization> {
|
|
68
|
+
): Promise<StateInitialization | null> {
|
|
55
69
|
if (options.checkpointState) {
|
|
56
70
|
return prepareCheckpointFileInitialization(options.checkpointState, options, archived, context);
|
|
57
71
|
}
|
|
@@ -59,8 +73,7 @@ export async function prepareCheckpointOrGenesisInitialization(
|
|
|
59
73
|
return prepareCheckpointApiInitialization(options.checkpointSyncUrl, options, archived, context);
|
|
60
74
|
}
|
|
61
75
|
if (options.lastPersistedCheckpointState || options.unsafeCheckpointState) {
|
|
62
|
-
|
|
63
|
-
if (stateInit !== null) return stateInit;
|
|
76
|
+
return prepareUnfinalizedCheckpointInitialization(options, archived, context);
|
|
64
77
|
}
|
|
65
|
-
return
|
|
78
|
+
return null;
|
|
66
79
|
}
|
|
@@ -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";
|
|
@@ -16,10 +17,9 @@ export type StateInitializationOptions = Pick<
|
|
|
16
17
|
| "wssCheckpoint"
|
|
17
18
|
| "forceCheckpointSync"
|
|
18
19
|
| "ignoreWeakSubjectivityCheck"
|
|
19
|
-
| "forceGenesis"
|
|
20
20
|
| "network"
|
|
21
21
|
| "chain.nHistoricalStatesFileDataStore"
|
|
22
|
-
| "chain.
|
|
22
|
+
| "chain.nativeStateTransition"
|
|
23
23
|
>;
|
|
24
24
|
|
|
25
25
|
export type StatePreparationContext = {
|
|
@@ -54,6 +54,7 @@ export type StateInitialization = {
|
|
|
54
54
|
config: BeaconConfig;
|
|
55
55
|
isFinalized: boolean;
|
|
56
56
|
validate: (state: IBeaconStateView) => void;
|
|
57
|
+
initializeEarliestAvailableSlot: (state: IBeaconStateView) => Promise<Slot>;
|
|
57
58
|
persist: ((state: IBeaconStateView, stateBytes: Uint8Array) => Promise<void>) | null;
|
|
58
|
-
log: (state: IBeaconStateView) => void;
|
|
59
|
+
log: (state: IBeaconStateView, nativeStateTransition: boolean) => void;
|
|
59
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);
|