@lodestar/state-transition 1.50.0-dev.033e6b7138 → 1.50.0-dev.03c05fa09a
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/index.d.ts.map +1 -1
- package/lib/block/index.js +1 -1
- package/lib/block/index.js.map +1 -1
- 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/processDeposit.d.ts +2 -2
- package/lib/block/processDeposit.d.ts.map +1 -1
- package/lib/block/processDeposit.js.map +1 -1
- package/lib/block/processEth1Data.d.ts +3 -3
- package/lib/block/processEth1Data.d.ts.map +1 -1
- package/lib/block/processEth1Data.js.map +1 -1
- package/lib/block/processOperations.d.ts.map +1 -1
- package/lib/block/processOperations.js +8 -6
- package/lib/block/processOperations.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/block/processProposerSlashing.d.ts.map +1 -1
- package/lib/block/processProposerSlashing.js +0 -23
- package/lib/block/processProposerSlashing.js.map +1 -1
- package/lib/block/slashValidator.d.ts.map +1 -1
- package/lib/block/slashValidator.js +11 -0
- package/lib/block/slashValidator.js.map +1 -1
- package/lib/cache/stateCache.d.ts +2 -1
- package/lib/cache/stateCache.d.ts.map +1 -1
- package/lib/cache/stateCache.js.map +1 -1
- package/lib/cache/types.d.ts +2 -1
- package/lib/cache/types.d.ts.map +1 -1
- package/lib/epoch/index.d.ts.map +1 -1
- package/lib/epoch/index.js +3 -1
- package/lib/epoch/index.js.map +1 -1
- package/lib/epoch/processEth1DataReset.d.ts +2 -2
- package/lib/epoch/processEth1DataReset.d.ts.map +1 -1
- package/lib/epoch/processEth1DataReset.js.map +1 -1
- package/lib/epoch/processPendingDeposits.d.ts.map +1 -1
- package/lib/epoch/processPendingDeposits.js +8 -4
- package/lib/epoch/processPendingDeposits.js.map +1 -1
- package/lib/index.d.ts +4 -2
- 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/signatureSets/index.d.ts.map +1 -1
- package/lib/signatureSets/index.js +2 -2
- package/lib/signatureSets/index.js.map +1 -1
- package/lib/signatureSets/voluntaryExits.d.ts +2 -6
- package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
- package/lib/signatureSets/voluntaryExits.js +2 -32
- package/lib/signatureSets/voluntaryExits.js.map +1 -1
- package/lib/slot/upgradeStateToHeze.d.ts.map +1 -1
- package/lib/slot/upgradeStateToHeze.js +4 -4
- package/lib/slot/upgradeStateToHeze.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +23 -21
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +77 -71
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/interface.d.ts +37 -21
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/stateView/interface.js.map +1 -1
- package/lib/stateView/nativeBeaconStateView.d.ts +94 -100
- package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
- package/lib/stateView/nativeBeaconStateView.js +353 -368
- package/lib/stateView/nativeBeaconStateView.js.map +1 -1
- package/lib/stateView/stateViewFactory.d.ts +10 -17
- package/lib/stateView/stateViewFactory.d.ts.map +1 -1
- package/lib/stateView/stateViewFactory.js +17 -13
- package/lib/stateView/stateViewFactory.js.map +1 -1
- package/lib/types.d.ts +2 -2
- package/lib/types.d.ts.map +1 -1
- package/lib/util/blindedBlock.d.ts +1 -1
- package/lib/util/blindedBlock.d.ts.map +1 -1
- package/lib/util/blindedBlock.js +5 -2
- package/lib/util/blindedBlock.js.map +1 -1
- package/lib/util/clock.d.ts +5 -0
- package/lib/util/clock.d.ts.map +1 -1
- package/lib/util/clock.js +19 -16
- package/lib/util/clock.js.map +1 -1
- package/lib/util/deposit.d.ts +2 -2
- package/lib/util/deposit.d.ts.map +1 -1
- package/lib/util/deposit.js.map +1 -1
- package/lib/util/genesis.d.ts.map +1 -1
- package/lib/util/genesis.js +46 -23
- package/lib/util/genesis.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 -0
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +1 -0
- package/lib/util/index.js.map +1 -1
- package/lib/util/slot.d.ts +3 -1
- package/lib/util/slot.d.ts.map +1 -1
- package/lib/util/slot.js +4 -0
- package/lib/util/slot.js.map +1 -1
- package/lib/util/sszBytes.d.ts +16 -17
- package/lib/util/sszBytes.d.ts.map +1 -1
- package/lib/util/sszBytes.js +93 -20
- package/lib/util/sszBytes.js.map +1 -1
- package/lib/util/weakSubjectivity.d.ts +11 -6
- package/lib/util/weakSubjectivity.d.ts.map +1 -1
- package/lib/util/weakSubjectivity.js +22 -28
- package/lib/util/weakSubjectivity.js.map +1 -1
- package/package.json +8 -8
- package/src/block/index.ts +4 -3
- package/src/block/indexedBuilderState.ts +65 -0
- package/src/block/processBuilderDepositRequest.ts +6 -17
- package/src/block/processBuilderExitRequest.ts +5 -9
- package/src/block/processDeposit.ts +7 -2
- package/src/block/processEth1Data.ts +3 -3
- package/src/block/processOperations.ts +14 -11
- package/src/block/processParentExecutionPayload.ts +27 -23
- package/src/block/processProposerSlashing.ts +2 -28
- package/src/block/slashValidator.ts +13 -2
- package/src/cache/stateCache.ts +2 -0
- package/src/cache/types.ts +2 -1
- package/src/epoch/index.ts +4 -1
- package/src/epoch/processEth1DataReset.ts +2 -2
- package/src/epoch/processPendingDeposits.ts +14 -3
- package/src/index.ts +6 -1
- package/src/rewards/attestationsRewards.ts +8 -1
- package/src/signatureSets/index.ts +4 -2
- package/src/signatureSets/voluntaryExits.ts +3 -55
- package/src/slot/upgradeStateToHeze.ts +6 -4
- package/src/stateView/beaconStateView.ts +84 -77
- package/src/stateView/interface.ts +65 -21
- package/src/stateView/nativeBeaconStateView.ts +368 -375
- package/src/stateView/stateViewFactory.ts +29 -27
- package/src/types.ts +2 -0
- package/src/util/blindedBlock.ts +8 -3
- package/src/util/clock.ts +25 -16
- package/src/util/deposit.ts +2 -2
- package/src/util/genesis.ts +56 -30
- package/src/util/gloas.ts +2 -53
- package/src/util/index.ts +6 -0
- package/src/util/slot.ts +6 -1
- package/src/util/sszBytes.ts +129 -22
- package/src/util/weakSubjectivity.ts +43 -40
|
@@ -1,68 +1,70 @@
|
|
|
1
|
-
import
|
|
1
|
+
import bindings from "@chainsafe/lodestar-z";
|
|
2
|
+
import {pubkeyCache} from "@chainsafe/lodestar-z/pubkeys";
|
|
2
3
|
import {BeaconConfig} from "@lodestar/config";
|
|
3
4
|
import {createCachedBeaconState} from "../cache/stateCache.js";
|
|
4
|
-
import {BeaconStateAllForks} from "../cache/types.js";
|
|
5
5
|
import {getStateTypeFromBytes} from "../util/sszBytes.js";
|
|
6
6
|
import {BeaconStateView} from "./beaconStateView.js";
|
|
7
|
-
import {IBeaconStateView} from "./interface.js";
|
|
7
|
+
import {IBeaconStateView, IBeaconStateViewNative} from "./interface.js";
|
|
8
|
+
import {NativeBeaconStateView} from "./nativeBeaconStateView.js";
|
|
8
9
|
|
|
9
10
|
// ---- createBeaconStateView (startup path) ----
|
|
10
11
|
|
|
11
|
-
type
|
|
12
|
-
|
|
13
|
-
anchorState: BeaconStateAllForks;
|
|
12
|
+
type CreateBeaconStateViewOpts = {
|
|
13
|
+
nativeStateTransition: boolean;
|
|
14
14
|
config: BeaconConfig;
|
|
15
|
-
pubkeyCache: PubkeyCache;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type NativeOpts = {
|
|
19
|
-
useNative: true;
|
|
20
15
|
stateBytes: Uint8Array;
|
|
21
16
|
};
|
|
22
17
|
|
|
23
18
|
/**
|
|
24
|
-
* Create a BeaconStateView from
|
|
19
|
+
* Create a BeaconStateView from raw SSZ bytes. Used at node startup.
|
|
25
20
|
*
|
|
26
|
-
*
|
|
27
|
-
* passed separately to BeaconNode.init, so it must live outside this factory).
|
|
21
|
+
* Caller must reserve pubkey capacity before calling this function.
|
|
28
22
|
*
|
|
29
|
-
* Set `
|
|
23
|
+
* Set `nativeStateTransition: true` to use the native (Zig) implementation.
|
|
30
24
|
*/
|
|
31
|
-
export function createBeaconStateView(opts:
|
|
32
|
-
if (opts.
|
|
33
|
-
|
|
34
|
-
// TODO: return a new instance of NativeBeaconStateView
|
|
25
|
+
export function createBeaconStateView(opts: CreateBeaconStateViewOpts): IBeaconStateView {
|
|
26
|
+
if (opts.nativeStateTransition) {
|
|
27
|
+
return createNativeBeaconStateView(opts.config, opts.stateBytes);
|
|
35
28
|
}
|
|
36
|
-
const {
|
|
37
|
-
const
|
|
29
|
+
const {config, stateBytes} = opts;
|
|
30
|
+
const state = getStateTypeFromBytes(config, stateBytes).deserializeToViewDU(stateBytes);
|
|
31
|
+
const cachedState = createCachedBeaconState(state, {config, pubkeyCache}, {skipSyncPubkeys: false});
|
|
38
32
|
return new BeaconStateView(cachedState);
|
|
39
33
|
}
|
|
40
34
|
|
|
41
35
|
// ---- createBeaconStateViewForHistoricalRegen (regen path) ----
|
|
42
36
|
|
|
43
37
|
type RegenNodeJSOpts = {
|
|
44
|
-
|
|
38
|
+
nativeStateTransition: false;
|
|
45
39
|
config: BeaconConfig;
|
|
46
40
|
stateBytes: Uint8Array;
|
|
47
41
|
};
|
|
48
42
|
|
|
49
43
|
type RegenNativeOpts = {
|
|
50
|
-
|
|
44
|
+
nativeStateTransition: true;
|
|
45
|
+
config: BeaconConfig;
|
|
51
46
|
stateBytes: Uint8Array;
|
|
52
47
|
};
|
|
53
48
|
|
|
54
49
|
/**
|
|
55
50
|
* Create a BeaconStateView from raw SSZ bytes. Used in the historical state regen worker thread.
|
|
56
51
|
*
|
|
57
|
-
* Set `
|
|
52
|
+
* Set `nativeStateTransition: true` to use the native (Zig) implementation.
|
|
58
53
|
*/
|
|
59
54
|
export function createBeaconStateViewForHistoricalRegen(opts: RegenNodeJSOpts | RegenNativeOpts): IBeaconStateView {
|
|
60
|
-
if (opts.
|
|
61
|
-
|
|
62
|
-
// TODO: return a new instance of NativeBeaconStateView
|
|
55
|
+
if (opts.nativeStateTransition) {
|
|
56
|
+
return createNativeBeaconStateView(opts.config, opts.stateBytes);
|
|
63
57
|
}
|
|
64
58
|
const {config, stateBytes} = opts;
|
|
65
59
|
const state = getStateTypeFromBytes(config, stateBytes).deserializeToViewDU(stateBytes);
|
|
66
60
|
const cachedState = createCachedBeaconState(state, {config, pubkeyCache}, {skipSyncPubkeys: true});
|
|
67
61
|
return new BeaconStateView(cachedState);
|
|
68
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/types.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type {
|
|
|
12
12
|
CachedBeaconStateGloas,
|
|
13
13
|
CachedBeaconStateHeze,
|
|
14
14
|
CachedBeaconStatePhase0,
|
|
15
|
+
CachedBeaconStatePreHeze,
|
|
15
16
|
} from "./cache/stateCache.js";
|
|
16
17
|
export type {
|
|
17
18
|
BeaconStateAllForks,
|
|
@@ -25,5 +26,6 @@ export type {
|
|
|
25
26
|
BeaconStateGloas,
|
|
26
27
|
BeaconStateHeze,
|
|
27
28
|
BeaconStatePhase0,
|
|
29
|
+
BeaconStatePreHeze,
|
|
28
30
|
ShufflingGetter,
|
|
29
31
|
} from "./cache/types.js";
|
package/src/util/blindedBlock.ts
CHANGED
|
@@ -3,10 +3,12 @@ import {
|
|
|
3
3
|
ForkName,
|
|
4
4
|
ForkPostBellatrix,
|
|
5
5
|
ForkPostDeneb,
|
|
6
|
+
ForkPreDeneb,
|
|
6
7
|
ForkPreGloas,
|
|
7
8
|
ForkSeq,
|
|
8
9
|
isForkPostBellatrix,
|
|
9
10
|
isForkPostDeneb,
|
|
11
|
+
isForkPostGloas,
|
|
10
12
|
} from "@lodestar/params";
|
|
11
13
|
import {
|
|
12
14
|
BeaconBlock,
|
|
@@ -128,7 +130,10 @@ export function reconstructSignedBlockContents(
|
|
|
128
130
|
signedBlindedBlock: SignedBlindedBeaconBlock,
|
|
129
131
|
executionPayload: ExecutionPayload | null,
|
|
130
132
|
blobsBundle: BlobsBundle | null
|
|
131
|
-
): SignedBlockContents {
|
|
133
|
+
): SignedBlockContents<ForkPreGloas> {
|
|
134
|
+
if (isForkPostGloas(fork)) {
|
|
135
|
+
throw Error("Blinded block reconstruction is not supported after Gloas");
|
|
136
|
+
}
|
|
132
137
|
const signedBlock = signedBlindedBlockToFull(fork, signedBlindedBlock, executionPayload);
|
|
133
138
|
|
|
134
139
|
if (isForkPostDeneb(fork)) {
|
|
@@ -136,10 +141,10 @@ export function reconstructSignedBlockContents(
|
|
|
136
141
|
throw Error("Missing blobs bundle to reconstruct post-deneb block contents");
|
|
137
142
|
}
|
|
138
143
|
return {
|
|
139
|
-
signedBlock: signedBlock as SignedBeaconBlock<ForkPostDeneb>,
|
|
144
|
+
signedBlock: signedBlock as SignedBeaconBlock<ForkPostDeneb & ForkPreGloas>,
|
|
140
145
|
kzgProofs: blobsBundle.proofs,
|
|
141
146
|
blobs: blobsBundle.blobs,
|
|
142
147
|
};
|
|
143
148
|
}
|
|
144
|
-
return {signedBlock};
|
|
149
|
+
return {signedBlock: signedBlock as SignedBeaconBlock<ForkPreDeneb>};
|
|
145
150
|
}
|
package/src/util/clock.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {ChainForkConfig} from "@lodestar/config";
|
|
2
|
-
import {
|
|
2
|
+
import {SLOTS_PER_EPOCH} from "@lodestar/params";
|
|
3
3
|
import {Epoch, Slot, TimeSeconds} from "@lodestar/types";
|
|
4
4
|
import {ErrorAborted, Logger, isErrorAborted, sleep} from "@lodestar/utils";
|
|
5
5
|
import {computeEpochAtSlot} from "./epoch.js";
|
|
6
|
-
import {computeTimeAtSlot, getCurrentSlot} from "./slot.js";
|
|
6
|
+
import {computeTimeAtSlot, getCurrentSlot, getSlotDurationMs} from "./slot.js";
|
|
7
7
|
|
|
8
8
|
type RunEveryFn = (slot: Slot, signal: AbortSignal) => Promise<void>;
|
|
9
9
|
|
|
@@ -13,6 +13,7 @@ export type ClockOptions = {
|
|
|
13
13
|
|
|
14
14
|
export interface IClock {
|
|
15
15
|
readonly genesisTime: number;
|
|
16
|
+
/** @deprecated Use getSlotDurationMs(slot) instead */
|
|
16
17
|
readonly secondsPerSlot: number;
|
|
17
18
|
|
|
18
19
|
readonly currentEpoch: number;
|
|
@@ -25,6 +26,8 @@ export interface IClock {
|
|
|
25
26
|
secFromSlot(slot: Slot): number;
|
|
26
27
|
getCurrentSlot(): Slot;
|
|
27
28
|
getCurrentEpoch(): Epoch;
|
|
29
|
+
/** Slot duration in ms for a given slot */
|
|
30
|
+
getSlotDurationMs(slot: Slot): number;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
export enum TimeItem {
|
|
@@ -95,6 +98,11 @@ export class Clock implements IClock {
|
|
|
95
98
|
return Date.now() / 1000 - computeTimeAtSlot(this.config, slot, this.genesisTime);
|
|
96
99
|
}
|
|
97
100
|
|
|
101
|
+
/** Slot duration in ms for a given slot */
|
|
102
|
+
getSlotDurationMs(slot: Slot): number {
|
|
103
|
+
return getSlotDurationMs(this.config, slot);
|
|
104
|
+
}
|
|
105
|
+
|
|
98
106
|
/**
|
|
99
107
|
* If a task happens to take more than one slot to run, we might skip a slot. This is unfortunate,
|
|
100
108
|
* however the alternative is to *always* process every slot, which has the chance of creating a
|
|
@@ -145,20 +153,17 @@ export class Clock implements IClock {
|
|
|
145
153
|
}
|
|
146
154
|
|
|
147
155
|
private timeUntilNext(timeItem: TimeItem): number {
|
|
148
|
-
const
|
|
149
|
-
const msFromGenesis = Date.now() - this.genesisTime * 1000;
|
|
156
|
+
const currentSlot = getCurrentSlot(this.config, this.genesisTime);
|
|
150
157
|
|
|
151
158
|
if (timeItem === TimeItem.Slot) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
return Math.abs(msFromGenesis) % milliSecondsPerSlot;
|
|
159
|
+
const nextSlotTimeSec = computeTimeAtSlot(this.config, currentSlot + 1, this.genesisTime);
|
|
160
|
+
return Math.max(0, nextSlotTimeSec * 1000 - Date.now());
|
|
156
161
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return Math.
|
|
162
|
+
|
|
163
|
+
const currentEpoch = computeEpochAtSlot(currentSlot);
|
|
164
|
+
const nextEpochSlot = (currentEpoch + 1) * SLOTS_PER_EPOCH;
|
|
165
|
+
const nextEpochTimeSec = computeTimeAtSlot(this.config, nextEpochSlot, this.genesisTime);
|
|
166
|
+
return Math.max(0, nextEpochTimeSec * 1000 - Date.now());
|
|
162
167
|
}
|
|
163
168
|
}
|
|
164
169
|
|
|
@@ -166,9 +171,13 @@ export class Clock implements IClock {
|
|
|
166
171
|
* Same to the spec but we use Math.round instead of Math.floor.
|
|
167
172
|
*/
|
|
168
173
|
export function getCurrentSlotAround(config: ChainForkConfig, genesisTime: TimeSeconds): Slot {
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
|
|
174
|
+
const floorSlot = getCurrentSlot(config, genesisTime);
|
|
175
|
+
const slotStartSec = computeTimeAtSlot(config, floorSlot, genesisTime);
|
|
176
|
+
const slotDurationMs = getSlotDurationMs(config, floorSlot);
|
|
177
|
+
const slotDurationSec = slotDurationMs / 1000;
|
|
178
|
+
const elapsed = Date.now() / 1000 - slotStartSec;
|
|
179
|
+
|
|
180
|
+
return elapsed >= slotDurationSec / 2 ? floorSlot + 1 : floorSlot;
|
|
172
181
|
}
|
|
173
182
|
|
|
174
183
|
// function useEventStream() {
|
package/src/util/deposit.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {ForkSeq, MAX_DEPOSITS} from "@lodestar/params";
|
|
2
2
|
import {UintNum64, phase0} from "@lodestar/types";
|
|
3
|
-
import {
|
|
3
|
+
import {CachedBeaconStateElectra, CachedBeaconStatePreHeze} from "../types.js";
|
|
4
4
|
|
|
5
|
-
export function getEth1DepositCount(state:
|
|
5
|
+
export function getEth1DepositCount(state: CachedBeaconStatePreHeze, eth1Data?: phase0.Eth1Data): UintNum64 {
|
|
6
6
|
const eth1DataToUse = eth1Data ?? state.eth1Data;
|
|
7
7
|
// Proposer can set any value, use in bigint until the result is bounded by MAX_DEPOSITS
|
|
8
8
|
const depositCount = eth1DataToUse.depositCount;
|
package/src/util/genesis.ts
CHANGED
|
@@ -11,11 +11,18 @@ import {
|
|
|
11
11
|
UNSET_DEPOSIT_REQUESTS_START_INDEX,
|
|
12
12
|
} from "@lodestar/params";
|
|
13
13
|
import {Bytes32, Root, TimeSeconds, phase0, ssz} from "@lodestar/types";
|
|
14
|
-
import {processDeposit} from "../block/processDeposit.js";
|
|
14
|
+
import {applyDeposit, processDeposit} from "../block/processDeposit.js";
|
|
15
15
|
import {EpochCacheImmutableData} from "../cache/epochCache.js";
|
|
16
16
|
import {createCachedBeaconState} from "../cache/stateCache.js";
|
|
17
17
|
import {increaseBalance} from "../index.js";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
BeaconStateAllForks,
|
|
20
|
+
BeaconStatePreHeze,
|
|
21
|
+
CachedBeaconStateAllForks,
|
|
22
|
+
CachedBeaconStateElectra,
|
|
23
|
+
CachedBeaconStateGloas,
|
|
24
|
+
CachedBeaconStatePreHeze,
|
|
25
|
+
} from "../types.js";
|
|
19
26
|
import {newFilledArray} from "./array.js";
|
|
20
27
|
import {getTemporaryBlockHeader} from "./blockRoot.js";
|
|
21
28
|
import {computeEpochAtSlot} from "./epoch.js";
|
|
@@ -87,7 +94,9 @@ export function getGenesisBeaconState(
|
|
|
87
94
|
state.latestBlockHeader = ssz.phase0.BeaconBlockHeader.toViewDU(latestBlockHeader);
|
|
88
95
|
|
|
89
96
|
// Ethereum 1.0 chain data
|
|
90
|
-
|
|
97
|
+
if (config.getForkSeq(GENESIS_SLOT) < ForkSeq.heze) {
|
|
98
|
+
(state as BeaconStatePreHeze).eth1Data = ssz.phase0.Eth1Data.toViewDU(genesisEth1Data);
|
|
99
|
+
}
|
|
91
100
|
state.randaoMixes = ssz.phase0.RandaoMixes.toViewDU(randaoMixes);
|
|
92
101
|
|
|
93
102
|
return state;
|
|
@@ -100,7 +109,9 @@ export function getGenesisBeaconState(
|
|
|
100
109
|
* @param eth1BlockHash eth1 block hash
|
|
101
110
|
*/
|
|
102
111
|
export function applyEth1BlockHash(state: CachedBeaconStateAllForks, eth1BlockHash: Bytes32): void {
|
|
103
|
-
state.
|
|
112
|
+
if (state.config.getForkSeq(state.slot) < ForkSeq.heze) {
|
|
113
|
+
(state as CachedBeaconStatePreHeze).eth1Data.blockHash = eth1BlockHash;
|
|
114
|
+
}
|
|
104
115
|
state.randaoMixes = ssz.phase0.RandaoMixes.toViewDU(newFilledArray(EPOCHS_PER_HISTORICAL_VECTOR, eth1BlockHash));
|
|
105
116
|
}
|
|
106
117
|
|
|
@@ -134,36 +145,41 @@ export function applyDeposits(
|
|
|
134
145
|
fullDepositDataRootList?: DepositDataRootViewDU
|
|
135
146
|
): {activatedValidatorCount: number} {
|
|
136
147
|
const fork = config.getForkSeq(state.slot);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (fullDepositDataRootArr) {
|
|
142
|
-
const depositCount = Number(state.eth1Data.depositCount);
|
|
143
|
-
for (let index = 0; index < depositCount; index++) {
|
|
144
|
-
depositDataRootList.push(fullDepositDataRootArr[index]);
|
|
148
|
+
if (fork >= ForkSeq.heze) {
|
|
149
|
+
// Genesis deposits do not use the removed legacy deposit tree.
|
|
150
|
+
for (const deposit of newDeposits) {
|
|
151
|
+
applyDeposit(fork, state, deposit.data);
|
|
145
152
|
}
|
|
146
|
-
}
|
|
153
|
+
} else {
|
|
154
|
+
const statePreHeze = state as CachedBeaconStatePreHeze;
|
|
155
|
+
const depositDataRootList: Root[] = [];
|
|
156
|
+
const fullDepositDataRootArr = fullDepositDataRootList ? fullDepositDataRootList.getAllReadonlyValues() : null;
|
|
147
157
|
|
|
148
|
-
const initDepositCount = depositDataRootList.length;
|
|
149
|
-
const depositDatas = fullDepositDataRootList ? null : newDeposits.map((deposit) => deposit.data);
|
|
150
|
-
const {DepositData, DepositDataRootList} = ssz.phase0;
|
|
151
|
-
|
|
152
|
-
for (const [index, deposit] of newDeposits.entries()) {
|
|
153
158
|
if (fullDepositDataRootArr) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
state.eth1Data.depositRoot = DepositDataRootList.hashTreeRoot(
|
|
159
|
-
depositDataList.map((d) => DepositData.hashTreeRoot(d))
|
|
160
|
-
);
|
|
159
|
+
const depositCount = Number(statePreHeze.eth1Data.depositCount);
|
|
160
|
+
for (let index = 0; index < depositCount; index++) {
|
|
161
|
+
depositDataRootList.push(fullDepositDataRootArr[index]);
|
|
162
|
+
}
|
|
161
163
|
}
|
|
162
164
|
|
|
163
|
-
|
|
165
|
+
const initDepositCount = depositDataRootList.length;
|
|
166
|
+
const depositDatas = fullDepositDataRootList ? null : newDeposits.map((deposit) => deposit.data);
|
|
167
|
+
const {DepositData, DepositDataRootList} = ssz.phase0;
|
|
168
|
+
|
|
169
|
+
for (const [index, deposit] of newDeposits.entries()) {
|
|
170
|
+
if (fullDepositDataRootArr) {
|
|
171
|
+
depositDataRootList.push(fullDepositDataRootArr[index + initDepositCount]);
|
|
172
|
+
statePreHeze.eth1Data.depositRoot = DepositDataRootList.hashTreeRoot(depositDataRootList);
|
|
173
|
+
} else if (depositDatas) {
|
|
174
|
+
const depositDataList = depositDatas.slice(0, index + 1);
|
|
175
|
+
statePreHeze.eth1Data.depositRoot = DepositDataRootList.hashTreeRoot(
|
|
176
|
+
depositDataList.map((d) => DepositData.hashTreeRoot(d))
|
|
177
|
+
);
|
|
178
|
+
}
|
|
164
179
|
|
|
165
|
-
|
|
166
|
-
|
|
180
|
+
statePreHeze.eth1Data.depositCount += 1n;
|
|
181
|
+
processDeposit(fork, statePreHeze, deposit);
|
|
182
|
+
}
|
|
167
183
|
}
|
|
168
184
|
|
|
169
185
|
// Process deposit balance updates
|
|
@@ -178,7 +194,11 @@ export function applyDeposits(
|
|
|
178
194
|
}
|
|
179
195
|
increaseBalance(state, validatorIndex, amount);
|
|
180
196
|
}
|
|
181
|
-
|
|
197
|
+
if (fork >= ForkSeq.gloas) {
|
|
198
|
+
(state as CachedBeaconStateGloas).pendingDeposits = ssz.gloas.PendingDeposits.defaultViewDU();
|
|
199
|
+
} else {
|
|
200
|
+
stateElectra.pendingDeposits = ssz.electra.PendingDeposits.defaultViewDU();
|
|
201
|
+
}
|
|
182
202
|
}
|
|
183
203
|
|
|
184
204
|
// Process activations
|
|
@@ -316,7 +336,9 @@ export function initializeBeaconStateFromEth1(
|
|
|
316
336
|
stateElectra.latestExecutionPayloadHeader =
|
|
317
337
|
(executionPayloadHeader as CompositeViewDU<typeof ssz.electra.ExecutionPayloadHeader>) ??
|
|
318
338
|
ssz.electra.ExecutionPayloadHeader.defaultViewDU();
|
|
319
|
-
|
|
339
|
+
if (fork < ForkSeq.heze) {
|
|
340
|
+
stateElectra.depositRequestsStartIndex = UNSET_DEPOSIT_REQUESTS_START_INDEX;
|
|
341
|
+
}
|
|
320
342
|
}
|
|
321
343
|
|
|
322
344
|
if (fork >= ForkSeq.fulu) {
|
|
@@ -326,6 +348,10 @@ export function initializeBeaconStateFromEth1(
|
|
|
326
348
|
stateFulu.latestExecutionPayloadHeader =
|
|
327
349
|
(executionPayloadHeader as CompositeViewDU<typeof ssz.fulu.ExecutionPayloadHeader>) ??
|
|
328
350
|
ssz.fulu.ExecutionPayloadHeader.defaultViewDU();
|
|
351
|
+
if (fork < ForkSeq.heze) {
|
|
352
|
+
// Fulu retires the legacy bridge after the genesis deposits.
|
|
353
|
+
stateFulu.depositRequestsStartIndex = BigInt(stateFulu.eth1DepositIndex);
|
|
354
|
+
}
|
|
329
355
|
}
|
|
330
356
|
|
|
331
357
|
if (fork >= ForkSeq.gloas) {
|
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
|
@@ -28,6 +28,12 @@ export * from "./signatureSets.js";
|
|
|
28
28
|
export * from "./signingRoot.js";
|
|
29
29
|
export * from "./slot.js";
|
|
30
30
|
export * from "./ssz.js";
|
|
31
|
+
export {
|
|
32
|
+
type StateBytesMetadata,
|
|
33
|
+
getValidatorCountFromStateBytes,
|
|
34
|
+
getValidatorPubkeyFromStateBytes,
|
|
35
|
+
readBeaconStateBytesMetadata,
|
|
36
|
+
} from "./sszBytes.js";
|
|
31
37
|
export * from "./syncCommittee.js";
|
|
32
38
|
export * from "./validator.js";
|
|
33
39
|
export * from "./weakSubjectivity.js";
|
package/src/util/slot.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {ChainConfig} from "@lodestar/config";
|
|
1
|
+
import {ChainConfig, ChainForkConfig} from "@lodestar/config";
|
|
2
2
|
import {GENESIS_SLOT} from "@lodestar/params";
|
|
3
3
|
import {Epoch, Slot, TimeSeconds} from "@lodestar/types";
|
|
4
4
|
import {computeEpochAtSlot, computeStartSlotAtEpoch} from "./epoch.js";
|
|
5
5
|
|
|
6
|
+
/** Slot duration in ms for a given slot */
|
|
7
|
+
export function getSlotDurationMs(config: ChainForkConfig, slot: Slot): number {
|
|
8
|
+
return config.getSlotDurationMs(config.getForkName(slot));
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
export function getSlotsSinceGenesis(config: ChainConfig, genesisTime: TimeSeconds): Slot {
|
|
7
12
|
const diffInSeconds = Date.now() / 1000 - genesisTime;
|
|
8
13
|
return Math.floor(diffInSeconds / (config.SLOT_DURATION_MS / 1000));
|