@lodestar/state-transition 1.50.0-dev.023ad6c012 → 1.50.0-dev.040a952dd7
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/processParentExecutionPayload.d.ts.map +1 -1
- package/lib/block/processParentExecutionPayload.js +17 -16
- package/lib/block/processParentExecutionPayload.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +22 -21
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +71 -71
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/interface.d.ts +34 -21
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/stateView/interface.js.map +1 -1
- package/lib/stateView/nativeBeaconStateView.d.ts +92 -100
- package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
- package/lib/stateView/nativeBeaconStateView.js +339 -368
- package/lib/stateView/nativeBeaconStateView.js.map +1 -1
- package/lib/stateView/stateViewFactory.d.ts +6 -5
- package/lib/stateView/stateViewFactory.d.ts.map +1 -1
- package/lib/stateView/stateViewFactory.js +12 -8
- package/lib/stateView/stateViewFactory.js.map +1 -1
- package/package.json +7 -7
- package/src/block/processParentExecutionPayload.ts +18 -17
- package/src/index.ts +3 -1
- package/src/stateView/beaconStateView.ts +75 -76
- package/src/stateView/interface.ts +61 -21
- package/src/stateView/nativeBeaconStateView.ts +354 -375
- package/src/stateView/stateViewFactory.ts +21 -12
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import bindings from "@chainsafe/lodestar-z";
|
|
1
2
|
import {pubkeyCache} from "@chainsafe/lodestar-z/pubkeys";
|
|
2
3
|
import {BeaconConfig} from "@lodestar/config";
|
|
3
4
|
import {createCachedBeaconState} from "../cache/stateCache.js";
|
|
4
5
|
import {getStateTypeFromBytes} from "../util/sszBytes.js";
|
|
5
6
|
import {BeaconStateView} from "./beaconStateView.js";
|
|
6
|
-
import {IBeaconStateView} from "./interface.js";
|
|
7
|
+
import {IBeaconStateView, IBeaconStateViewNative} from "./interface.js";
|
|
8
|
+
import {NativeBeaconStateView} from "./nativeBeaconStateView.js";
|
|
7
9
|
|
|
8
10
|
// ---- createBeaconStateView (startup path) ----
|
|
9
11
|
|
|
10
12
|
type CreateBeaconStateViewOpts = {
|
|
11
|
-
|
|
13
|
+
nativeStateTransition: boolean;
|
|
12
14
|
config: BeaconConfig;
|
|
13
15
|
stateBytes: Uint8Array;
|
|
14
16
|
};
|
|
@@ -18,12 +20,11 @@ type CreateBeaconStateViewOpts = {
|
|
|
18
20
|
*
|
|
19
21
|
* Caller must reserve pubkey capacity before calling this function.
|
|
20
22
|
*
|
|
21
|
-
* Set `
|
|
23
|
+
* Set `nativeStateTransition: true` to use the native (Zig) implementation.
|
|
22
24
|
*/
|
|
23
25
|
export function createBeaconStateView(opts: CreateBeaconStateViewOpts): IBeaconStateView {
|
|
24
|
-
if (opts.
|
|
25
|
-
|
|
26
|
-
// TODO: return a new instance of NativeBeaconStateView
|
|
26
|
+
if (opts.nativeStateTransition) {
|
|
27
|
+
return createNativeBeaconStateView(opts.config, opts.stateBytes);
|
|
27
28
|
}
|
|
28
29
|
const {config, stateBytes} = opts;
|
|
29
30
|
const state = getStateTypeFromBytes(config, stateBytes).deserializeToViewDU(stateBytes);
|
|
@@ -34,28 +35,36 @@ export function createBeaconStateView(opts: CreateBeaconStateViewOpts): IBeaconS
|
|
|
34
35
|
// ---- createBeaconStateViewForHistoricalRegen (regen path) ----
|
|
35
36
|
|
|
36
37
|
type RegenNodeJSOpts = {
|
|
37
|
-
|
|
38
|
+
nativeStateTransition: false;
|
|
38
39
|
config: BeaconConfig;
|
|
39
40
|
stateBytes: Uint8Array;
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
type RegenNativeOpts = {
|
|
43
|
-
|
|
44
|
+
nativeStateTransition: true;
|
|
45
|
+
config: BeaconConfig;
|
|
44
46
|
stateBytes: Uint8Array;
|
|
45
47
|
};
|
|
46
48
|
|
|
47
49
|
/**
|
|
48
50
|
* Create a BeaconStateView from raw SSZ bytes. Used in the historical state regen worker thread.
|
|
49
51
|
*
|
|
50
|
-
* Set `
|
|
52
|
+
* Set `nativeStateTransition: true` to use the native (Zig) implementation.
|
|
51
53
|
*/
|
|
52
54
|
export function createBeaconStateViewForHistoricalRegen(opts: RegenNodeJSOpts | RegenNativeOpts): IBeaconStateView {
|
|
53
|
-
if (opts.
|
|
54
|
-
|
|
55
|
-
// TODO: return a new instance of NativeBeaconStateView
|
|
55
|
+
if (opts.nativeStateTransition) {
|
|
56
|
+
return createNativeBeaconStateView(opts.config, opts.stateBytes);
|
|
56
57
|
}
|
|
57
58
|
const {config, stateBytes} = opts;
|
|
58
59
|
const state = getStateTypeFromBytes(config, stateBytes).deserializeToViewDU(stateBytes);
|
|
59
60
|
const cachedState = createCachedBeaconState(state, {config, pubkeyCache}, {skipSyncPubkeys: true});
|
|
60
61
|
return new BeaconStateView(cachedState);
|
|
61
62
|
}
|
|
63
|
+
|
|
64
|
+
function createNativeBeaconStateView(config: BeaconConfig, stateBytes: Uint8Array): IBeaconStateView {
|
|
65
|
+
const nativeConfig = new bindings.BeaconConfig(config, config.genesisValidatorsRoot);
|
|
66
|
+
return new NativeBeaconStateView(
|
|
67
|
+
config,
|
|
68
|
+
bindings.BeaconStateView.createFromBytes(stateBytes, nativeConfig) as IBeaconStateViewNative
|
|
69
|
+
);
|
|
70
|
+
}
|