@lodestar/state-transition 1.42.0-dev.98c97772c8 → 1.42.0-dev.a5906cd323
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/block/processAttestationsAltair.d.ts +2 -1
- package/lib/block/processAttestationsAltair.d.ts.map +1 -1
- package/lib/block/processAttestationsAltair.js +5 -3
- package/lib/block/processAttestationsAltair.js.map +1 -1
- package/lib/signatureSets/index.d.ts +2 -2
- package/lib/signatureSets/index.d.ts.map +1 -1
- package/lib/signatureSets/index.js +1 -2
- package/lib/signatureSets/index.js.map +1 -1
- package/lib/slot/upgradeStateToAltair.d.ts.map +1 -1
- package/lib/slot/upgradeStateToAltair.js +2 -1
- package/lib/slot/upgradeStateToAltair.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +6 -9
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +8 -32
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/index.d.ts +1 -0
- package/lib/stateView/index.d.ts.map +1 -1
- package/lib/stateView/index.js +1 -0
- package/lib/stateView/index.js.map +1 -1
- package/lib/stateView/interface.d.ts +12 -8
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/stateView/stateViewFactory.d.ts +40 -0
- package/lib/stateView/stateViewFactory.d.ts.map +1 -0
- package/lib/stateView/stateViewFactory.js +46 -0
- package/lib/stateView/stateViewFactory.js.map +1 -0
- package/lib/util/rootCache.d.ts +2 -2
- package/lib/util/rootCache.d.ts.map +1 -1
- package/lib/util/rootCache.js +2 -3
- package/lib/util/rootCache.js.map +1 -1
- package/lib/util/shuffling.d.ts +2 -1
- package/lib/util/shuffling.d.ts.map +1 -1
- package/lib/util/shuffling.js +2 -2
- package/lib/util/shuffling.js.map +1 -1
- package/package.json +7 -7
- package/src/block/processAttestationsAltair.ts +7 -4
- package/src/signatureSets/index.ts +3 -4
- package/src/slot/upgradeStateToAltair.ts +2 -1
- package/src/stateView/beaconStateView.ts +16 -48
- package/src/stateView/index.ts +1 -0
- package/src/stateView/interface.ts +10 -5
- package/src/stateView/stateViewFactory.ts +78 -0
- package/src/util/rootCache.ts +4 -5
- package/src/util/shuffling.ts +5 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stateViewFactory.d.ts","sourceRoot":"","sources":["../../src/stateView/stateViewFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAC,WAAW,EAAoB,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AAIhD,KAAK,UAAU,GAAG;IAChB,SAAS,EAAE,KAAK,CAAC;IACjB,WAAW,EAAE,mBAAmB,CAAC;IACjC,MAAM,EAAE,YAAY,CAAC;IACrB,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,KAAK,UAAU,GAAG;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,GAAG,gBAAgB,CAOrF;AAeD,KAAK,eAAe,GAAG;IACrB,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,EAAE,YAAY,CAAC;IACrB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,SAAS,EAAE,IAAI,CAAC;IAChB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,uCAAuC,CAAC,IAAI,EAAE,eAAe,GAAG,eAAe,GAAG,gBAAgB,CASjH"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createPubkeyCache } from "../cache/pubkeyCache.js";
|
|
2
|
+
import { createCachedBeaconState } from "../cache/stateCache.js";
|
|
3
|
+
import { getStateTypeFromBytes } from "../util/sszBytes.js";
|
|
4
|
+
import { BeaconStateView } from "./beaconStateView.js";
|
|
5
|
+
/**
|
|
6
|
+
* Create a BeaconStateView from a pre-deserialized state. Used at node startup.
|
|
7
|
+
*
|
|
8
|
+
* The caller is responsible for creating and populating `pubkeyCache` (it is also
|
|
9
|
+
* passed separately to BeaconNode.init, so it must live outside this factory).
|
|
10
|
+
*
|
|
11
|
+
* Set `useNative: true` to use the native (Zig) implementation once available.
|
|
12
|
+
*/
|
|
13
|
+
export function createBeaconStateView(opts) {
|
|
14
|
+
if (opts.useNative) {
|
|
15
|
+
throw new Error("Native (Zig) BeaconStateView not yet implemented");
|
|
16
|
+
}
|
|
17
|
+
const { anchorState, config, pubkeyCache } = opts;
|
|
18
|
+
const cachedState = createCachedBeaconState(anchorState, { config, pubkeyCache }, { skipSyncPubkeys: true });
|
|
19
|
+
return new BeaconStateView(cachedState);
|
|
20
|
+
}
|
|
21
|
+
// ---- createBeaconStateViewForHistoricalRegen (regen path) ----
|
|
22
|
+
// Reused across all historical state regen calls in the worker thread
|
|
23
|
+
const pubkeyCacheRegen = createPubkeyCache();
|
|
24
|
+
function syncPubkeyCache(state, pubkeyCache) {
|
|
25
|
+
const newCount = state.validators.length;
|
|
26
|
+
for (let i = pubkeyCache.size; i < newCount; i++) {
|
|
27
|
+
const pubkey = state.validators.getReadonly(i).pubkey;
|
|
28
|
+
pubkeyCache.set(i, pubkey);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a BeaconStateView from raw SSZ bytes. Used in the historical state regen worker thread.
|
|
33
|
+
*
|
|
34
|
+
* Set `useNative: true` to use the native (Zig) implementation once available.
|
|
35
|
+
*/
|
|
36
|
+
export function createBeaconStateViewForHistoricalRegen(opts) {
|
|
37
|
+
if (opts.useNative) {
|
|
38
|
+
throw new Error("Native (Zig) BeaconStateView not yet implemented");
|
|
39
|
+
}
|
|
40
|
+
const { config, stateBytes } = opts;
|
|
41
|
+
const state = getStateTypeFromBytes(config, stateBytes).deserializeToViewDU(stateBytes);
|
|
42
|
+
syncPubkeyCache(state, pubkeyCacheRegen);
|
|
43
|
+
const cachedState = createCachedBeaconState(state, { config, pubkeyCache: pubkeyCacheRegen }, { skipSyncPubkeys: true });
|
|
44
|
+
return new BeaconStateView(cachedState);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=stateViewFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stateViewFactory.js","sourceRoot":"","sources":["../../src/stateView/stateViewFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,iBAAiB,EAAC,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAC,uBAAuB,EAAC,MAAM,wBAAwB,CAAC;AAE/D,OAAO,EAAC,qBAAqB,EAAC,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC;AAiBrD;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAA6B,EAAoB;IACrF,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IACD,MAAM,EAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAC,GAAG,IAAI,CAAC;IAChD,MAAM,WAAW,GAAG,uBAAuB,CAAC,WAAW,EAAE,EAAC,MAAM,EAAE,WAAW,EAAC,EAAE,EAAC,eAAe,EAAE,IAAI,EAAC,CAAC,CAAC;IACzG,OAAO,IAAI,eAAe,CAAC,WAAW,CAAC,CAAC;AAAA,CACzC;AAED,iEAAiE;AAEjE,sEAAsE;AACtE,MAAM,gBAAgB,GAAG,iBAAiB,EAAE,CAAC;AAE7C,SAAS,eAAe,CAAC,KAA0B,EAAE,WAAwB,EAAQ;IACnF,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC;IACzC,KAAK,IAAI,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;QACjD,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QACtD,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;AAAA,CACF;AAaD;;;;GAIG;AACH,MAAM,UAAU,uCAAuC,CAAC,IAAuC,EAAoB;IACjH,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IACD,MAAM,EAAC,MAAM,EAAE,UAAU,EAAC,GAAG,IAAI,CAAC;IAClC,MAAM,KAAK,GAAG,qBAAqB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;IACxF,eAAe,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACzC,MAAM,WAAW,GAAG,uBAAuB,CAAC,KAAK,EAAE,EAAC,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAC,EAAE,EAAC,eAAe,EAAE,IAAI,EAAC,CAAC,CAAC;IACrH,OAAO,IAAI,eAAe,CAAC,WAAW,CAAC,CAAC;AAAA,CACzC"}
|
package/lib/util/rootCache.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Epoch, Root, Slot, phase0 } from "@lodestar/types";
|
|
2
|
-
import {
|
|
2
|
+
import { IBeaconStateView } from "../stateView/interface.js";
|
|
3
3
|
/**
|
|
4
4
|
* Cache to prevent accessing the state tree to fetch block roots repeteadly.
|
|
5
5
|
* In normal network conditions the same root is read multiple times, specially the target.
|
|
@@ -10,7 +10,7 @@ export declare class RootCache {
|
|
|
10
10
|
readonly previousJustifiedCheckpoint: phase0.Checkpoint;
|
|
11
11
|
private readonly blockRootEpochCache;
|
|
12
12
|
private readonly blockRootSlotCache;
|
|
13
|
-
constructor(state:
|
|
13
|
+
constructor(state: IBeaconStateView);
|
|
14
14
|
getBlockRoot(epoch: Epoch): Root;
|
|
15
15
|
getBlockRootAtSlot(slot: Slot): Root;
|
|
16
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rootCache.d.ts","sourceRoot":"","sources":["../../src/util/rootCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAC,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"rootCache.d.ts","sourceRoot":"","sources":["../../src/util/rootCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAC,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAE3D;;;GAGG;AACH,qBAAa,SAAS;IAMR,OAAO,CAAC,QAAQ,CAAC,KAAK;IALlC,QAAQ,CAAC,0BAA0B,EAAE,MAAM,CAAC,UAAU,CAAC;IACvD,QAAQ,CAAC,2BAA2B,EAAE,MAAM,CAAC,UAAU,CAAC;IACxD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA0B;IAC9D,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAyB;IAE5D,YAA6B,KAAK,EAAE,gBAAgB,EAGnD;IAED,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAO/B;IAED,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAOnC;CACF"}
|
package/lib/util/rootCache.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getBlockRoot, getBlockRootAtSlot } from "./blockRoot.js";
|
|
2
1
|
/**
|
|
3
2
|
* Cache to prevent accessing the state tree to fetch block roots repeteadly.
|
|
4
3
|
* In normal network conditions the same root is read multiple times, specially the target.
|
|
@@ -17,7 +16,7 @@ export class RootCache {
|
|
|
17
16
|
getBlockRoot(epoch) {
|
|
18
17
|
let root = this.blockRootEpochCache.get(epoch);
|
|
19
18
|
if (!root) {
|
|
20
|
-
root =
|
|
19
|
+
root = this.state.getBlockRootAtEpoch(epoch);
|
|
21
20
|
this.blockRootEpochCache.set(epoch, root);
|
|
22
21
|
}
|
|
23
22
|
return root;
|
|
@@ -25,7 +24,7 @@ export class RootCache {
|
|
|
25
24
|
getBlockRootAtSlot(slot) {
|
|
26
25
|
let root = this.blockRootSlotCache.get(slot);
|
|
27
26
|
if (!root) {
|
|
28
|
-
root =
|
|
27
|
+
root = this.state.getBlockRootAtSlot(slot);
|
|
29
28
|
this.blockRootSlotCache.set(slot, root);
|
|
30
29
|
}
|
|
31
30
|
return root;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rootCache.js","sourceRoot":"","sources":["../../src/util/rootCache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rootCache.js","sourceRoot":"","sources":["../../src/util/rootCache.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,OAAO,SAAS;IAMS,KAAK;IALzB,0BAA0B,CAAoB;IAC9C,2BAA2B,CAAoB;IACvC,mBAAmB,GAAG,IAAI,GAAG,EAAe,CAAC;IAC7C,kBAAkB,GAAG,IAAI,GAAG,EAAc,CAAC;IAE5D,YAA6B,KAAuB,EAAE;qBAAzB,KAAK;QAChC,IAAI,CAAC,0BAA0B,GAAG,KAAK,CAAC,0BAA0B,CAAC;QACnE,IAAI,CAAC,2BAA2B,GAAG,KAAK,CAAC,2BAA2B,CAAC;IAAA,CACtE;IAED,YAAY,CAAC,KAAY,EAAQ;QAC/B,IAAI,IAAI,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;YAC7C,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,IAAI,CAAC;IAAA,CACb;IAED,kBAAkB,CAAC,IAAU,EAAQ;QACnC,IAAI,IAAI,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,IAAI,CAAC;IAAA,CACb;CACF"}
|
package/lib/util/shuffling.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ForkName, ForkSeq } from "@lodestar/params";
|
|
|
2
2
|
import { Attestation, CommitteeIndex, Epoch, IndexedAttestation, Root, Slot, ValidatorIndex } from "@lodestar/types";
|
|
3
3
|
import { LodestarError } from "@lodestar/utils";
|
|
4
4
|
import { CachedBeaconStateAllForks } from "../cache/stateCache.js";
|
|
5
|
+
import { IBeaconStateView } from "../stateView/interface.js";
|
|
5
6
|
import { EpochShuffling } from "./epochShuffling.js";
|
|
6
7
|
/**
|
|
7
8
|
* Returns the block root which decided the proposer shuffling for the current epoch. This root
|
|
@@ -10,7 +11,7 @@ import { EpochShuffling } from "./epochShuffling.js";
|
|
|
10
11
|
* Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
|
|
11
12
|
* It should be set to the latest block applied to this `state` or the genesis block root.
|
|
12
13
|
*/
|
|
13
|
-
export declare function proposerShufflingDecisionRoot(fork: ForkName, state:
|
|
14
|
+
export declare function proposerShufflingDecisionRoot(fork: ForkName, state: IBeaconStateView): Root | null;
|
|
14
15
|
/**
|
|
15
16
|
* Returns the block root which decided the attester shuffling for the given `requestedEpoch`.
|
|
16
17
|
* This root can be used to key that attester shuffling.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shuffling.d.ts","sourceRoot":"","sources":["../../src/util/shuffling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAkC,MAAM,kBAAkB,CAAC;AACpF,OAAO,EACL,WAAW,EACX,cAAc,EACd,KAAK,EACL,kBAAkB,EAClB,IAAI,EACJ,IAAI,EACJ,cAAc,EAEf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,yBAAyB,EAAC,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"shuffling.d.ts","sourceRoot":"","sources":["../../src/util/shuffling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAkC,MAAM,kBAAkB,CAAC;AACpF,OAAO,EACL,WAAW,EACX,cAAc,EACd,KAAK,EACL,kBAAkB,EAClB,IAAI,EACJ,IAAI,EACJ,cAAc,EAEf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,yBAAyB,EAAC,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAG3D,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAEnD;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAMlG;AAaD;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,CAMlH;AAsCD,MAAM,WAAW,YAA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return null;
|
|
16
16
|
}
|
|
17
|
-
return getBlockRootAtSlot(
|
|
17
|
+
return state.getBlockRootAtSlot(decisionSlot);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Returns the slot at which the proposer shuffling was decided. The block root at this slot
|
|
@@ -22,7 +22,7 @@ export function proposerShufflingDecisionRoot(fork, state) {
|
|
|
22
22
|
*/
|
|
23
23
|
function proposerShufflingDecisionSlot(fork, state) {
|
|
24
24
|
// After fulu, the decision slot is in previous epoch due to deterministic proposer lookahead
|
|
25
|
-
const epoch = isForkPostFulu(fork) ? state.
|
|
25
|
+
const epoch = isForkPostFulu(fork) ? state.epoch - 1 : state.epoch;
|
|
26
26
|
const startSlot = computeStartSlotAtEpoch(epoch);
|
|
27
27
|
return Math.max(startSlot - 1, 0);
|
|
28
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shuffling.js","sourceRoot":"","sources":["../../src/util/shuffling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,OAAO,EAAE,eAAe,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAWpF,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"shuffling.js","sourceRoot":"","sources":["../../src/util/shuffling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,OAAO,EAAE,eAAe,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAWpF,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAC,uBAAuB,EAAC,MAAM,YAAY,CAAC;AAGnD;;;;;;GAMG;AACH,MAAM,UAAU,6BAA6B,CAAC,IAAc,EAAE,KAAuB,EAAe;IAClG,MAAM,YAAY,GAAG,6BAA6B,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAChE,IAAI,KAAK,CAAC,IAAI,KAAK,YA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E,MAAM,UAAU,GAAG,EAAE,CAAC;IAEtB,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,IAAI,cAAc,CAAC,MAAM,EAAE,CAAC;YACnC,MAAM,IAAI,cAAc,CAAC;gBACvB,IAAI,EAAE,kBAAkB,CAAC,4BAA4B;gBACrD,KAAK;gBACL,QAAQ,EAAE,cAAc,CAAC,MAAM;aAChC,CAAC,CAAC;QACL,CAAC;QACD,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,UAAU,CAAC;AAAA,CACnB;SAEW,kBAAkB;AAA9B,IAAY,kBAEX;AAFD,WAAY,kBAAkB;IAC5B,mGAA6E,CAAA;AAAC,CAChF,EAFY,kBAAkB,KAAlB,kBAAkB,QAE7B;AAQD,MAAM,OAAO,cAAe,SAAQ,aAAiC;CAAG"}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ChainSafe/lodestar/issues"
|
|
13
13
|
},
|
|
14
|
-
"version": "1.42.0-dev.
|
|
14
|
+
"version": "1.42.0-dev.a5906cd323",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -67,14 +67,14 @@
|
|
|
67
67
|
"@chainsafe/pubkey-index-map": "^3.0.0",
|
|
68
68
|
"@chainsafe/ssz": "^1.2.2",
|
|
69
69
|
"@chainsafe/swap-or-not-shuffle": "^1.2.1",
|
|
70
|
-
"@lodestar/config": "^1.42.0-dev.
|
|
71
|
-
"@lodestar/params": "^1.42.0-dev.
|
|
72
|
-
"@lodestar/types": "^1.42.0-dev.
|
|
73
|
-
"@lodestar/utils": "^1.42.0-dev.
|
|
70
|
+
"@lodestar/config": "^1.42.0-dev.a5906cd323",
|
|
71
|
+
"@lodestar/params": "^1.42.0-dev.a5906cd323",
|
|
72
|
+
"@lodestar/types": "^1.42.0-dev.a5906cd323",
|
|
73
|
+
"@lodestar/utils": "^1.42.0-dev.a5906cd323",
|
|
74
74
|
"@vekexasia/bigint-buffer2": "^1.1.1"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@lodestar/api": "^1.42.0-dev.
|
|
77
|
+
"@lodestar/api": "^1.42.0-dev.a5906cd323"
|
|
78
78
|
},
|
|
79
79
|
"keywords": [
|
|
80
80
|
"ethereum",
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"beacon",
|
|
83
83
|
"blockchain"
|
|
84
84
|
],
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "f47a02b4f589709ae17191d787b92a78723ee400"
|
|
86
86
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {BitArray} from "@chainsafe/ssz";
|
|
1
2
|
import {
|
|
2
3
|
EFFECTIVE_BALANCE_INCREMENT,
|
|
3
4
|
ForkSeq,
|
|
@@ -17,6 +18,7 @@ import {Attestation, Epoch, phase0} from "@lodestar/types";
|
|
|
17
18
|
import {byteArrayEquals, intSqrt} from "@lodestar/utils";
|
|
18
19
|
import {BeaconStateTransitionMetrics} from "../metrics.js";
|
|
19
20
|
import {getAttestationWithIndicesSignatureSet} from "../signatureSets/indexedAttestation.js";
|
|
21
|
+
import {BeaconStateView} from "../stateView/beaconStateView.js";
|
|
20
22
|
import {CachedBeaconStateAltair, CachedBeaconStateGloas} from "../types.js";
|
|
21
23
|
import {isAttestationSameSlot, isAttestationSameSlotRootCache} from "../util/gloas.js";
|
|
22
24
|
import {increaseBalance, verifySignatureSet} from "../util/index.js";
|
|
@@ -41,7 +43,7 @@ export function processAttestationsAltair(
|
|
|
41
43
|
const {epochCtx} = state;
|
|
42
44
|
const {effectiveBalanceIncrements} = epochCtx;
|
|
43
45
|
const stateSlot = state.slot;
|
|
44
|
-
const rootCache = new RootCache(state);
|
|
46
|
+
const rootCache = new RootCache(new BeaconStateView(state));
|
|
45
47
|
const currentEpoch = epochCtx.epoch;
|
|
46
48
|
|
|
47
49
|
// Process all attestations first and then increase the balance of the proposer once
|
|
@@ -80,7 +82,7 @@ export function processAttestationsAltair(
|
|
|
80
82
|
stateSlot - data.slot,
|
|
81
83
|
epochCtx.epoch,
|
|
82
84
|
rootCache,
|
|
83
|
-
fork >= ForkSeq.gloas ? (state as CachedBeaconStateGloas).executionPayloadAvailability
|
|
85
|
+
fork >= ForkSeq.gloas ? (state as CachedBeaconStateGloas).executionPayloadAvailability : null
|
|
84
86
|
);
|
|
85
87
|
|
|
86
88
|
// For each participant, update their participation
|
|
@@ -177,7 +179,7 @@ export function getAttestationParticipationStatus(
|
|
|
177
179
|
inclusionDelay: number,
|
|
178
180
|
currentEpoch: Epoch,
|
|
179
181
|
rootCache: RootCache,
|
|
180
|
-
executionPayloadAvailability:
|
|
182
|
+
executionPayloadAvailability: BitArray | null
|
|
181
183
|
): number {
|
|
182
184
|
const justifiedCheckpoint =
|
|
183
185
|
data.target.epoch === currentEpoch ? rootCache.currentJustifiedCheckpoint : rootCache.previousJustifiedCheckpoint;
|
|
@@ -221,7 +223,8 @@ export function getAttestationParticipationStatus(
|
|
|
221
223
|
throw new Error(`data index must be 0 or 1 index=${data.index}`);
|
|
222
224
|
}
|
|
223
225
|
|
|
224
|
-
isMatchingPayload =
|
|
226
|
+
isMatchingPayload =
|
|
227
|
+
Boolean(data.index) === executionPayloadAvailability.get(data.slot % SLOTS_PER_HISTORICAL_ROOT);
|
|
225
228
|
}
|
|
226
229
|
|
|
227
230
|
isMatchingHead = isMatchingHead && isMatchingPayload;
|
|
@@ -3,8 +3,7 @@ import {ForkSeq} from "@lodestar/params";
|
|
|
3
3
|
import {IndexedAttestation, SignedBeaconBlock, altair, capella} from "@lodestar/types";
|
|
4
4
|
import {getSyncCommitteeSignatureSet} from "../block/processSyncCommittee.js";
|
|
5
5
|
import {SyncCommitteeCache} from "../cache/syncCommitteeCache.js";
|
|
6
|
-
import {
|
|
7
|
-
import {CachedBeaconStateAllForks} from "../types.js";
|
|
6
|
+
import {IBeaconStateView} from "../stateView/interface.js";
|
|
8
7
|
import {ISignatureSet} from "../util/index.js";
|
|
9
8
|
import {getAttesterSlashingsSignatureSets} from "./attesterSlashings.js";
|
|
10
9
|
import {getBlsToExecutionChangeSignatureSets} from "./blsToExecutionChange.js";
|
|
@@ -32,7 +31,7 @@ export * from "./voluntaryExits.js";
|
|
|
32
31
|
export function getBlockSignatureSets(
|
|
33
32
|
config: BeaconConfig,
|
|
34
33
|
currentSyncCommitteeIndexed: SyncCommitteeCache,
|
|
35
|
-
state:
|
|
34
|
+
state: IBeaconStateView,
|
|
36
35
|
signedBlock: SignedBeaconBlock,
|
|
37
36
|
indexedAttestations: IndexedAttestation[],
|
|
38
37
|
opts?: {
|
|
@@ -48,7 +47,7 @@ export function getBlockSignatureSets(
|
|
|
48
47
|
...getProposerSlashingsSignatureSets(config, signedBlock),
|
|
49
48
|
...getAttesterSlashingsSignatureSets(config, signedBlock),
|
|
50
49
|
...getAttestationsSignatureSets(config, signedBlock, indexedAttestations),
|
|
51
|
-
...getVoluntaryExitsSignatureSets(config,
|
|
50
|
+
...getVoluntaryExitsSignatureSets(config, state, signedBlock),
|
|
52
51
|
];
|
|
53
52
|
|
|
54
53
|
if (!opts?.skipProposerSignature) {
|
|
@@ -3,6 +3,7 @@ import {ForkSeq} from "@lodestar/params";
|
|
|
3
3
|
import {ssz} from "@lodestar/types";
|
|
4
4
|
import {getAttestationParticipationStatus} from "../block/processAttestationsAltair.js";
|
|
5
5
|
import {getCachedBeaconState} from "../cache/stateCache.js";
|
|
6
|
+
import {BeaconStateView} from "../stateView/beaconStateView.js";
|
|
6
7
|
import {CachedBeaconStateAltair, CachedBeaconStatePhase0} from "../types.js";
|
|
7
8
|
import {RootCache, newZeroedArray} from "../util/index.js";
|
|
8
9
|
import {getNextSyncCommittee} from "../util/syncCommittee.js";
|
|
@@ -125,7 +126,7 @@ function translateParticipation(
|
|
|
125
126
|
pendingAttesations: CompositeViewDU<typeof ssz.phase0.EpochAttestations>
|
|
126
127
|
): void {
|
|
127
128
|
const {epochCtx} = state;
|
|
128
|
-
const rootCache = new RootCache(state);
|
|
129
|
+
const rootCache = new RootCache(new BeaconStateView(state));
|
|
129
130
|
const epochParticipation = state.previousEpochParticipation;
|
|
130
131
|
|
|
131
132
|
for (const attestation of pendingAttesations.getAllReadonly()) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {CompactMultiProof, ProofType, Tree, createProof} from "@chainsafe/persistent-merkle-tree";
|
|
2
|
-
import {ByteViews} from "@chainsafe/ssz";
|
|
2
|
+
import {BitArray, ByteViews} from "@chainsafe/ssz";
|
|
3
3
|
import {BeaconConfig} from "@lodestar/config";
|
|
4
4
|
import {ForkSeq, SLOTS_PER_HISTORICAL_ROOT, isForkPostGloas} from "@lodestar/params";
|
|
5
5
|
import {
|
|
6
6
|
BeaconBlock,
|
|
7
|
+
BeaconState,
|
|
7
8
|
BlindedBeaconBlock,
|
|
8
9
|
BuilderIndex,
|
|
9
10
|
Bytes32,
|
|
@@ -33,7 +34,6 @@ import {VoluntaryExitValidity, getVoluntaryExitValidity} from "../block/processV
|
|
|
33
34
|
import {getExpectedWithdrawals} from "../block/processWithdrawals.js";
|
|
34
35
|
import {EffectiveBalanceIncrements} from "../cache/effectiveBalanceIncrements.js";
|
|
35
36
|
import {EpochTransitionCacheOpts} from "../cache/epochTransitionCache.js";
|
|
36
|
-
import {PubkeyCache, createPubkeyCache} from "../cache/pubkeyCache.js";
|
|
37
37
|
import {RewardCache} from "../cache/rewardCache.js";
|
|
38
38
|
import {
|
|
39
39
|
CachedBeaconStateAllForks,
|
|
@@ -47,7 +47,6 @@ import {
|
|
|
47
47
|
isStateValidatorsNodesPopulated,
|
|
48
48
|
} from "../cache/stateCache.js";
|
|
49
49
|
import {SyncCommitteeCache} from "../cache/syncCommitteeCache.js";
|
|
50
|
-
import {BeaconStateAllForks} from "../cache/types.js";
|
|
51
50
|
import {computeUnrealizedCheckpoints} from "../epoch/computeUnrealizedCheckpoints.js";
|
|
52
51
|
import {getFinalizedRootProof, getSyncCommitteesWitness} from "../lightClient/proofs.js";
|
|
53
52
|
import {SyncCommitteeWitness} from "../lightClient/types.js";
|
|
@@ -64,7 +63,6 @@ import {isExecutionEnabled, isExecutionStateType, isMergeTransitionComplete} fro
|
|
|
64
63
|
import {canBuilderCoverBid} from "../util/gloas.js";
|
|
65
64
|
import {loadState} from "../util/loadState/loadState.js";
|
|
66
65
|
import {getRandaoMix} from "../util/seed.js";
|
|
67
|
-
import {getStateTypeFromBytes} from "../util/sszBytes.js";
|
|
68
66
|
import {getLatestWeakSubjectivityCheckpointEpoch} from "../util/weakSubjectivity.js";
|
|
69
67
|
import {IBeaconStateView} from "./interface.js";
|
|
70
68
|
|
|
@@ -92,7 +90,7 @@ export class BeaconStateView implements IBeaconStateView {
|
|
|
92
90
|
// fulu
|
|
93
91
|
private _proposerLookahead: fulu.ProposerLookahead | null = null;
|
|
94
92
|
// gloas
|
|
95
|
-
private _executionPayloadAvailability:
|
|
93
|
+
private _executionPayloadAvailability: BitArray | null = null;
|
|
96
94
|
private _latestExecutionPayloadBid: ExecutionPayloadBid | null = null;
|
|
97
95
|
|
|
98
96
|
constructor(readonly cachedState: CachedBeaconStateAllForks) {
|
|
@@ -357,15 +355,15 @@ export class BeaconStateView implements IBeaconStateView {
|
|
|
357
355
|
|
|
358
356
|
// gloas
|
|
359
357
|
|
|
360
|
-
get executionPayloadAvailability():
|
|
358
|
+
get executionPayloadAvailability(): BitArray {
|
|
361
359
|
if (this.config.getForkSeq(this.cachedState.slot) < ForkSeq.gloas) {
|
|
362
360
|
throw new Error("executionPayloadAvailability is not available before GLOAS");
|
|
363
361
|
}
|
|
364
362
|
|
|
365
363
|
if (this._executionPayloadAvailability === null) {
|
|
366
|
-
this._executionPayloadAvailability = (
|
|
367
|
-
.
|
|
368
|
-
|
|
364
|
+
this._executionPayloadAvailability = (
|
|
365
|
+
this.cachedState as CachedBeaconStateGloas
|
|
366
|
+
).executionPayloadAvailability.toValue();
|
|
369
367
|
}
|
|
370
368
|
|
|
371
369
|
return this._executionPayloadAvailability;
|
|
@@ -404,7 +402,7 @@ export class BeaconStateView implements IBeaconStateView {
|
|
|
404
402
|
* Return the index of the validator in the PTC committee for the given slot.
|
|
405
403
|
* return -1 if validator is not in the PTC committee for the given slot.
|
|
406
404
|
*/
|
|
407
|
-
|
|
405
|
+
getIndexInPayloadTimelinessCommittee(validatorIndex: ValidatorIndex, slot: Slot): number {
|
|
408
406
|
if (this.config.getForkSeq(this.cachedState.slot) < ForkSeq.gloas) {
|
|
409
407
|
throw new Error("PTC committees are not supported before GLOAS");
|
|
410
408
|
}
|
|
@@ -503,6 +501,10 @@ export class BeaconStateView implements IBeaconStateView {
|
|
|
503
501
|
return this.cachedState.epochCtx.syncProposerReward;
|
|
504
502
|
}
|
|
505
503
|
|
|
504
|
+
getIndexedSyncCommittee(slot: Slot): SyncCommitteeCache {
|
|
505
|
+
return this.cachedState.epochCtx.getIndexedSyncCommittee(slot);
|
|
506
|
+
}
|
|
507
|
+
|
|
506
508
|
getIndexedSyncCommitteeAtEpoch(epoch: Epoch): SyncCommitteeCache {
|
|
507
509
|
return this.cachedState.epochCtx.getIndexedSyncCommitteeAtEpoch(epoch);
|
|
508
510
|
}
|
|
@@ -713,6 +715,10 @@ export class BeaconStateView implements IBeaconStateView {
|
|
|
713
715
|
return new BeaconStateView(cachedState);
|
|
714
716
|
}
|
|
715
717
|
|
|
718
|
+
toValue(): BeaconState {
|
|
719
|
+
return this.cachedState.toValue();
|
|
720
|
+
}
|
|
721
|
+
|
|
716
722
|
serialize(): Uint8Array {
|
|
717
723
|
return this.cachedState.serialize();
|
|
718
724
|
}
|
|
@@ -778,41 +784,3 @@ export class BeaconStateView implements IBeaconStateView {
|
|
|
778
784
|
return new BeaconStateView(postPayloadState);
|
|
779
785
|
}
|
|
780
786
|
}
|
|
781
|
-
|
|
782
|
-
/**
|
|
783
|
-
* Create BeaconStateView for historical state regen, no need to sync pubkey cache there.
|
|
784
|
-
*/
|
|
785
|
-
export function createBeaconStateViewForHistoricalRegen(
|
|
786
|
-
config: BeaconConfig,
|
|
787
|
-
stateBytes: Uint8Array
|
|
788
|
-
): IBeaconStateView {
|
|
789
|
-
const state = getStateTypeFromBytes(config, stateBytes).deserializeToViewDU(stateBytes);
|
|
790
|
-
|
|
791
|
-
const pubkeyCache = createPubkeyCache();
|
|
792
|
-
syncPubkeyCache(state, pubkeyCache);
|
|
793
|
-
const cachedState = createCachedBeaconState(
|
|
794
|
-
state,
|
|
795
|
-
{
|
|
796
|
-
config,
|
|
797
|
-
pubkeyCache,
|
|
798
|
-
},
|
|
799
|
-
{
|
|
800
|
-
skipSyncPubkeys: true,
|
|
801
|
-
}
|
|
802
|
-
);
|
|
803
|
-
|
|
804
|
-
return new BeaconStateView(cachedState);
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
/**
|
|
808
|
-
* Populate a PubkeyIndexMap with any new entries based on a BeaconState
|
|
809
|
-
*/
|
|
810
|
-
function syncPubkeyCache(state: BeaconStateAllForks, pubkeyCache: PubkeyCache): void {
|
|
811
|
-
// Get the validators sub tree once for all the loop
|
|
812
|
-
|
|
813
|
-
const newCount = state.validators.length;
|
|
814
|
-
for (let i = pubkeyCache.size; i < newCount; i++) {
|
|
815
|
-
const pubkey = state.validators.getReadonly(i).pubkey;
|
|
816
|
-
pubkeyCache.set(i, pubkey);
|
|
817
|
-
}
|
|
818
|
-
}
|
package/src/stateView/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {CompactMultiProof} from "@chainsafe/persistent-merkle-tree";
|
|
2
|
-
import {ByteViews} from "@chainsafe/ssz";
|
|
2
|
+
import {BitArray, ByteViews} from "@chainsafe/ssz";
|
|
3
3
|
import {
|
|
4
4
|
BeaconBlock,
|
|
5
|
+
BeaconState,
|
|
5
6
|
BlindedBeaconBlock,
|
|
6
7
|
BuilderIndex,
|
|
7
8
|
Bytes32,
|
|
@@ -93,11 +94,11 @@ export interface IBeaconStateView {
|
|
|
93
94
|
proposerLookahead: fulu.ProposerLookahead;
|
|
94
95
|
|
|
95
96
|
// gloas
|
|
96
|
-
executionPayloadAvailability:
|
|
97
|
+
executionPayloadAvailability: BitArray;
|
|
97
98
|
latestExecutionPayloadBid: ExecutionPayloadBid;
|
|
98
99
|
getBuilder(index: BuilderIndex): gloas.Builder;
|
|
99
100
|
canBuilderCoverBid(builderIndex: BuilderIndex, bidAmount: number): boolean;
|
|
100
|
-
|
|
101
|
+
getIndexInPayloadTimelinessCommittee(validatorIndex: ValidatorIndex, slot: Slot): number;
|
|
101
102
|
|
|
102
103
|
// Shuffling and committees
|
|
103
104
|
getShufflingAtEpoch(epoch: Epoch): EpochShuffling;
|
|
@@ -110,12 +111,11 @@ export interface IBeaconStateView {
|
|
|
110
111
|
getCurrentShuffling(): EpochShuffling;
|
|
111
112
|
getNextShuffling(): EpochShuffling;
|
|
112
113
|
|
|
113
|
-
//
|
|
114
|
+
// Proposer shuffling
|
|
114
115
|
previousProposers: ValidatorIndex[] | null;
|
|
115
116
|
currentProposers: ValidatorIndex[];
|
|
116
117
|
nextProposers: ValidatorIndex[];
|
|
117
118
|
getBeaconProposer(slot: Slot): ValidatorIndex;
|
|
118
|
-
computeAnchorCheckpoint(): {checkpoint: phase0.Checkpoint; blockHeader: phase0.BeaconBlockHeader};
|
|
119
119
|
|
|
120
120
|
// Sync committees
|
|
121
121
|
currentSyncCommittee: altair.SyncCommittee;
|
|
@@ -123,6 +123,8 @@ export interface IBeaconStateView {
|
|
|
123
123
|
currentSyncCommitteeIndexed: SyncCommitteeCache;
|
|
124
124
|
syncProposerReward: number;
|
|
125
125
|
getIndexedSyncCommitteeAtEpoch(epoch: Epoch): SyncCommitteeCache;
|
|
126
|
+
/** Get indexed sync committee with slot+1 offset for duty lookups */
|
|
127
|
+
getIndexedSyncCommittee(slot: Slot): SyncCommitteeCache;
|
|
126
128
|
|
|
127
129
|
// Validators and balances
|
|
128
130
|
effectiveBalanceIncrements: EffectiveBalanceIncrements;
|
|
@@ -149,6 +151,7 @@ export interface IBeaconStateView {
|
|
|
149
151
|
expectedWithdrawals: capella.Withdrawal[];
|
|
150
152
|
processedBuilderWithdrawalsCount: number;
|
|
151
153
|
processedPartialWithdrawalsCount: number;
|
|
154
|
+
processedBuildersSweepCount: number;
|
|
152
155
|
processedValidatorSweepCount: number;
|
|
153
156
|
};
|
|
154
157
|
|
|
@@ -180,6 +183,7 @@ export interface IBeaconStateView {
|
|
|
180
183
|
justifiedCheckpoint: phase0.Checkpoint;
|
|
181
184
|
finalizedCheckpoint: phase0.Checkpoint;
|
|
182
185
|
};
|
|
186
|
+
computeAnchorCheckpoint(): {checkpoint: phase0.Checkpoint; blockHeader: phase0.BeaconBlockHeader};
|
|
183
187
|
|
|
184
188
|
// this is for backward compatible
|
|
185
189
|
clonedCount: number;
|
|
@@ -190,6 +194,7 @@ export interface IBeaconStateView {
|
|
|
190
194
|
|
|
191
195
|
// Serialization
|
|
192
196
|
loadOtherState(stateBytes: Uint8Array, seedValidatorsBytes?: Uint8Array): IBeaconStateView;
|
|
197
|
+
toValue(): BeaconState;
|
|
193
198
|
serialize(): Uint8Array;
|
|
194
199
|
serializedSize(): number;
|
|
195
200
|
serializeToBytes(output: ByteViews, offset: number): number;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {BeaconConfig} from "@lodestar/config";
|
|
2
|
+
import {PubkeyCache, createPubkeyCache} from "../cache/pubkeyCache.js";
|
|
3
|
+
import {createCachedBeaconState} from "../cache/stateCache.js";
|
|
4
|
+
import {BeaconStateAllForks} from "../cache/types.js";
|
|
5
|
+
import {getStateTypeFromBytes} from "../util/sszBytes.js";
|
|
6
|
+
import {BeaconStateView} from "./beaconStateView.js";
|
|
7
|
+
import {IBeaconStateView} from "./interface.js";
|
|
8
|
+
|
|
9
|
+
// ---- createBeaconStateView (startup path) ----
|
|
10
|
+
|
|
11
|
+
type NodeJSOpts = {
|
|
12
|
+
useNative: false;
|
|
13
|
+
anchorState: BeaconStateAllForks;
|
|
14
|
+
config: BeaconConfig;
|
|
15
|
+
pubkeyCache: PubkeyCache;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type NativeOpts = {
|
|
19
|
+
useNative: true;
|
|
20
|
+
stateBytes: Uint8Array;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Create a BeaconStateView from a pre-deserialized state. Used at node startup.
|
|
25
|
+
*
|
|
26
|
+
* The caller is responsible for creating and populating `pubkeyCache` (it is also
|
|
27
|
+
* passed separately to BeaconNode.init, so it must live outside this factory).
|
|
28
|
+
*
|
|
29
|
+
* Set `useNative: true` to use the native (Zig) implementation once available.
|
|
30
|
+
*/
|
|
31
|
+
export function createBeaconStateView(opts: NodeJSOpts | NativeOpts): IBeaconStateView {
|
|
32
|
+
if (opts.useNative) {
|
|
33
|
+
throw new Error("Native (Zig) BeaconStateView not yet implemented");
|
|
34
|
+
}
|
|
35
|
+
const {anchorState, config, pubkeyCache} = opts;
|
|
36
|
+
const cachedState = createCachedBeaconState(anchorState, {config, pubkeyCache}, {skipSyncPubkeys: true});
|
|
37
|
+
return new BeaconStateView(cachedState);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ---- createBeaconStateViewForHistoricalRegen (regen path) ----
|
|
41
|
+
|
|
42
|
+
// Reused across all historical state regen calls in the worker thread
|
|
43
|
+
const pubkeyCacheRegen = createPubkeyCache();
|
|
44
|
+
|
|
45
|
+
function syncPubkeyCache(state: BeaconStateAllForks, pubkeyCache: PubkeyCache): void {
|
|
46
|
+
const newCount = state.validators.length;
|
|
47
|
+
for (let i = pubkeyCache.size; i < newCount; i++) {
|
|
48
|
+
const pubkey = state.validators.getReadonly(i).pubkey;
|
|
49
|
+
pubkeyCache.set(i, pubkey);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type RegenNodeJSOpts = {
|
|
54
|
+
useNative: false;
|
|
55
|
+
config: BeaconConfig;
|
|
56
|
+
stateBytes: Uint8Array;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
type RegenNativeOpts = {
|
|
60
|
+
useNative: true;
|
|
61
|
+
stateBytes: Uint8Array;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Create a BeaconStateView from raw SSZ bytes. Used in the historical state regen worker thread.
|
|
66
|
+
*
|
|
67
|
+
* Set `useNative: true` to use the native (Zig) implementation once available.
|
|
68
|
+
*/
|
|
69
|
+
export function createBeaconStateViewForHistoricalRegen(opts: RegenNodeJSOpts | RegenNativeOpts): IBeaconStateView {
|
|
70
|
+
if (opts.useNative) {
|
|
71
|
+
throw new Error("Native (Zig) BeaconStateView not yet implemented");
|
|
72
|
+
}
|
|
73
|
+
const {config, stateBytes} = opts;
|
|
74
|
+
const state = getStateTypeFromBytes(config, stateBytes).deserializeToViewDU(stateBytes);
|
|
75
|
+
syncPubkeyCache(state, pubkeyCacheRegen);
|
|
76
|
+
const cachedState = createCachedBeaconState(state, {config, pubkeyCache: pubkeyCacheRegen}, {skipSyncPubkeys: true});
|
|
77
|
+
return new BeaconStateView(cachedState);
|
|
78
|
+
}
|
package/src/util/rootCache.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {Epoch, Root, Slot, phase0} from "@lodestar/types";
|
|
2
|
-
import {
|
|
3
|
-
import {getBlockRoot, getBlockRootAtSlot} from "./blockRoot.js";
|
|
2
|
+
import {IBeaconStateView} from "../stateView/interface.js";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Cache to prevent accessing the state tree to fetch block roots repeteadly.
|
|
@@ -12,7 +11,7 @@ export class RootCache {
|
|
|
12
11
|
private readonly blockRootEpochCache = new Map<Epoch, Root>();
|
|
13
12
|
private readonly blockRootSlotCache = new Map<Slot, Root>();
|
|
14
13
|
|
|
15
|
-
constructor(private readonly state:
|
|
14
|
+
constructor(private readonly state: IBeaconStateView) {
|
|
16
15
|
this.currentJustifiedCheckpoint = state.currentJustifiedCheckpoint;
|
|
17
16
|
this.previousJustifiedCheckpoint = state.previousJustifiedCheckpoint;
|
|
18
17
|
}
|
|
@@ -20,7 +19,7 @@ export class RootCache {
|
|
|
20
19
|
getBlockRoot(epoch: Epoch): Root {
|
|
21
20
|
let root = this.blockRootEpochCache.get(epoch);
|
|
22
21
|
if (!root) {
|
|
23
|
-
root =
|
|
22
|
+
root = this.state.getBlockRootAtEpoch(epoch);
|
|
24
23
|
this.blockRootEpochCache.set(epoch, root);
|
|
25
24
|
}
|
|
26
25
|
return root;
|
|
@@ -29,7 +28,7 @@ export class RootCache {
|
|
|
29
28
|
getBlockRootAtSlot(slot: Slot): Root {
|
|
30
29
|
let root = this.blockRootSlotCache.get(slot);
|
|
31
30
|
if (!root) {
|
|
32
|
-
root =
|
|
31
|
+
root = this.state.getBlockRootAtSlot(slot);
|
|
33
32
|
this.blockRootSlotCache.set(slot, root);
|
|
34
33
|
}
|
|
35
34
|
return root;
|