@lodestar/state-transition 1.50.0-dev.11028e782c → 1.50.0-dev.15ca1827f4
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/indexedBuilderState.d.ts +19 -0
- package/lib/block/indexedBuilderState.d.ts.map +1 -0
- package/lib/block/indexedBuilderState.js +60 -0
- package/lib/block/indexedBuilderState.js.map +1 -0
- package/lib/block/processBuilderDepositRequest.d.ts +2 -2
- package/lib/block/processBuilderDepositRequest.d.ts.map +1 -1
- package/lib/block/processBuilderDepositRequest.js +5 -4
- package/lib/block/processBuilderDepositRequest.js.map +1 -1
- package/lib/block/processBuilderExitRequest.d.ts +2 -2
- package/lib/block/processBuilderExitRequest.d.ts.map +1 -1
- package/lib/block/processBuilderExitRequest.js +4 -3
- package/lib/block/processBuilderExitRequest.js.map +1 -1
- package/lib/block/processParentExecutionPayload.d.ts.map +1 -1
- package/lib/block/processParentExecutionPayload.js +23 -18
- package/lib/block/processParentExecutionPayload.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/rewards/attestationsRewards.d.ts.map +1 -1
- package/lib/rewards/attestationsRewards.js +8 -1
- package/lib/rewards/attestationsRewards.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/lib/util/gloas.d.ts +11 -14
- package/lib/util/gloas.d.ts.map +1 -1
- package/lib/util/gloas.js +2 -42
- package/lib/util/gloas.js.map +1 -1
- package/lib/util/index.d.ts +1 -1
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +1 -1
- package/lib/util/index.js.map +1 -1
- package/lib/util/sszBytes.d.ts +2 -0
- package/lib/util/sszBytes.d.ts.map +1 -1
- package/lib/util/sszBytes.js +14 -1
- package/lib/util/sszBytes.js.map +1 -1
- package/package.json +7 -7
- package/src/block/indexedBuilderState.ts +65 -0
- package/src/block/processBuilderDepositRequest.ts +6 -17
- package/src/block/processBuilderExitRequest.ts +5 -9
- package/src/block/processParentExecutionPayload.ts +27 -23
- package/src/index.ts +4 -1
- package/src/rewards/attestationsRewards.ts +8 -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
- package/src/util/gloas.ts +2 -53
- package/src/util/index.ts +1 -0
- package/src/util/sszBytes.ts +19 -1
|
@@ -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
|
+
}
|
package/src/util/gloas.ts
CHANGED
|
@@ -178,21 +178,6 @@ export function initiateBuilderExit(state: CachedBeaconStateGloas, builderIndex:
|
|
|
178
178
|
builder.withdrawableEpoch = currentEpoch + state.config.MIN_BUILDER_WITHDRAWABILITY_DELAY;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
/**
|
|
182
|
-
* Find the index of a builder by their public key.
|
|
183
|
-
* Returns null if not found.
|
|
184
|
-
*
|
|
185
|
-
* May consider builder pubkey cache if performance becomes an issue.
|
|
186
|
-
*/
|
|
187
|
-
export function findBuilderIndexByPubkey(state: CachedBeaconStateGloas, pubkey: Uint8Array): BuilderIndex | null {
|
|
188
|
-
for (let i = 0; i < state.builders.length; i++) {
|
|
189
|
-
if (byteArrayEquals(state.builders.getReadonly(i).pubkey, pubkey)) {
|
|
190
|
-
return i;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
181
|
/**
|
|
197
182
|
* Use cached block roots to avoid repeated state root lookups while matching the spec's is_attestation_same_slot behavior.
|
|
198
183
|
*/
|
|
@@ -248,41 +233,6 @@ export function getPtcWindowEpochCacheData(state: CachedBeaconStateGloas): {
|
|
|
248
233
|
};
|
|
249
234
|
}
|
|
250
235
|
|
|
251
|
-
/**
|
|
252
|
-
* Add a new builder to the builders registry. Reuses slots from exited and fully withdrawn
|
|
253
|
-
* builders when available, otherwise appends.
|
|
254
|
-
*
|
|
255
|
-
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.11/specs/gloas/beacon-chain.md#new-add_builder_to_registry
|
|
256
|
-
*/
|
|
257
|
-
export function addBuilderToRegistry(
|
|
258
|
-
state: CachedBeaconStateGloas,
|
|
259
|
-
pubkey: Uint8Array,
|
|
260
|
-
version: number,
|
|
261
|
-
executionAddress: Uint8Array,
|
|
262
|
-
amount: number,
|
|
263
|
-
slot: number
|
|
264
|
-
): void {
|
|
265
|
-
const currentEpoch = computeEpochAtSlot(state.slot);
|
|
266
|
-
const depositEpoch = computeEpochAtSlot(slot);
|
|
267
|
-
|
|
268
|
-
let builderIndex = state.builders.length;
|
|
269
|
-
for (let i = 0; i < state.builders.length; i++) {
|
|
270
|
-
const builder = state.builders.getReadonly(i);
|
|
271
|
-
if (builder.withdrawableEpoch <= currentEpoch && builder.balance === 0) {
|
|
272
|
-
builderIndex = i;
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const newBuilder = createBuilderView(pubkey, version, executionAddress, amount, depositEpoch);
|
|
278
|
-
|
|
279
|
-
if (builderIndex < state.builders.length) {
|
|
280
|
-
state.builders.set(builderIndex, newBuilder);
|
|
281
|
-
} else {
|
|
282
|
-
state.builders.push(newBuilder);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
236
|
/**
|
|
287
237
|
* Append a new builder to the registry without scanning for a reusable slot.
|
|
288
238
|
*
|
|
@@ -301,10 +251,9 @@ export function appendBuilderToRegistry(
|
|
|
301
251
|
}
|
|
302
252
|
|
|
303
253
|
/**
|
|
304
|
-
* Build a Builder view
|
|
305
|
-
* and the append-only {@link appendBuilderToRegistry} so both paths produce an identical view.
|
|
254
|
+
* Build a Builder view from builder fields.
|
|
306
255
|
*/
|
|
307
|
-
function createBuilderView(
|
|
256
|
+
export function createBuilderView(
|
|
308
257
|
pubkey: Uint8Array,
|
|
309
258
|
version: number,
|
|
310
259
|
executionAddress: Uint8Array,
|
package/src/util/index.ts
CHANGED
package/src/util/sszBytes.ts
CHANGED
|
@@ -19,7 +19,8 @@ const ROOT_SIZE = 32;
|
|
|
19
19
|
* withdrawable_epoch: Epoch [fixed - 8 bytes]
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
const
|
|
22
|
+
const PUBKEY_SIZE = 48;
|
|
23
|
+
const VALIDATOR_EFFECTIVE_BALANCE_OFFSET = PUBKEY_SIZE + ROOT_SIZE;
|
|
23
24
|
const VALIDATOR_ACTIVATION_EPOCH_OFFSET = VALIDATOR_EFFECTIVE_BALANCE_OFFSET + UINT64_SIZE + 1 + UINT64_SIZE;
|
|
24
25
|
const VALIDATOR_EXIT_EPOCH_OFFSET = VALIDATOR_ACTIVATION_EPOCH_OFFSET + UINT64_SIZE;
|
|
25
26
|
export const VALIDATOR_BYTES_SIZE = VALIDATOR_EXIT_EPOCH_OFFSET + UINT64_SIZE + UINT64_SIZE;
|
|
@@ -118,6 +119,23 @@ export function getValidatorCountFromStateBytes(config: ChainForkConfig, stateBy
|
|
|
118
119
|
return range === null ? null : (range.end - range.start) / VALIDATOR_BYTES_SIZE;
|
|
119
120
|
}
|
|
120
121
|
|
|
122
|
+
/** Returns a view into `stateBytes`, or null if the index is not in the registry. */
|
|
123
|
+
export function getValidatorPubkeyFromStateBytes(
|
|
124
|
+
config: ChainForkConfig,
|
|
125
|
+
stateBytes: Uint8Array,
|
|
126
|
+
index: number
|
|
127
|
+
): Uint8Array | null {
|
|
128
|
+
const range = getValidatorsRangeFromStateBytes(stateBytes, getStateTypeFromBytes(config, stateBytes));
|
|
129
|
+
if (range === null) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
const start = range.start + index * VALIDATOR_BYTES_SIZE;
|
|
133
|
+
if (index < 0 || start >= range.end) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
return stateBytes.subarray(start, start + PUBKEY_SIZE);
|
|
137
|
+
}
|
|
138
|
+
|
|
121
139
|
function getValidatorsRangeFromStateBytes(
|
|
122
140
|
stateBytes: Uint8Array,
|
|
123
141
|
stateType: SSZTypesFor<ForkAll, "BeaconState">
|