@lodestar/state-transition 1.41.0-dev.bb273175f2 → 1.41.0-dev.be5acbb8f7
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 +3 -3
- package/lib/block/processExecutionPayloadBid.d.ts +1 -1
- package/lib/block/processExecutionPayloadEnvelope.d.ts +5 -2
- package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadEnvelope.js +20 -14
- package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
- package/lib/block/processPayloadAttestation.d.ts +1 -1
- package/lib/epoch/index.d.ts +1 -1
- package/lib/epoch/processBuilderPendingPayments.d.ts +1 -1
- package/lib/testUtils/cache.d.ts +2 -0
- package/lib/testUtils/cache.d.ts.map +1 -0
- package/lib/testUtils/cache.js +7 -0
- package/lib/testUtils/cache.js.map +1 -0
- package/lib/testUtils/index.d.ts +6 -0
- package/lib/testUtils/index.d.ts.map +1 -0
- package/lib/testUtils/index.js +6 -0
- package/lib/testUtils/index.js.map +1 -0
- package/lib/testUtils/infura.d.ts +3 -0
- package/lib/testUtils/infura.d.ts.map +1 -0
- package/lib/testUtils/infura.js +8 -0
- package/lib/testUtils/infura.js.map +1 -0
- package/lib/testUtils/interop.d.ts +2 -0
- package/lib/testUtils/interop.d.ts.map +1 -0
- package/lib/testUtils/interop.js +24 -0
- package/lib/testUtils/interop.js.map +1 -0
- package/lib/testUtils/params.d.ts +18 -0
- package/lib/testUtils/params.d.ts.map +1 -0
- package/lib/testUtils/params.js +20 -0
- package/lib/testUtils/params.js.map +1 -0
- package/lib/testUtils/state.d.ts +20 -0
- package/lib/testUtils/state.d.ts.map +1 -0
- package/lib/testUtils/state.js +78 -0
- package/lib/testUtils/state.js.map +1 -0
- package/lib/testUtils/testFileCache.d.ts +17 -0
- package/lib/testUtils/testFileCache.d.ts.map +1 -0
- package/lib/testUtils/testFileCache.js +96 -0
- package/lib/testUtils/testFileCache.js.map +1 -0
- package/lib/testUtils/util.d.ts +50 -0
- package/lib/testUtils/util.d.ts.map +1 -0
- package/lib/testUtils/util.js +329 -0
- package/lib/testUtils/util.js.map +1 -0
- package/package.json +12 -7
- package/src/block/index.ts +3 -3
- package/src/block/isValidIndexedPayloadAttestation.ts +2 -2
- package/src/block/processAttestationsAltair.ts +1 -1
- package/src/block/processExecutionPayloadBid.ts +4 -4
- package/src/block/processExecutionPayloadEnvelope.ts +35 -21
- package/src/block/processOperations.ts +1 -1
- package/src/block/processPayloadAttestation.ts +2 -2
- package/src/block/processWithdrawals.ts +1 -1
- package/src/epoch/index.ts +1 -1
- package/src/epoch/processBuilderPendingPayments.ts +2 -2
- package/src/testUtils/cache.ts +8 -0
- package/src/testUtils/index.ts +5 -0
- package/src/testUtils/infura.ts +10 -0
- package/src/testUtils/interop.ts +29 -0
- package/src/testUtils/params.ts +23 -0
- package/src/testUtils/state.ts +110 -0
- package/src/testUtils/testFileCache.ts +127 -0
- package/src/testUtils/util.ts +429 -0
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import {PublicKey, SecretKey} from "@chainsafe/blst";
|
|
2
|
+
import {BitArray, fromHexString} from "@chainsafe/ssz";
|
|
3
|
+
import {createBeaconConfig, createChainForkConfig} from "@lodestar/config";
|
|
4
|
+
import {config} from "@lodestar/config/default";
|
|
5
|
+
import {
|
|
6
|
+
EPOCHS_PER_ETH1_VOTING_PERIOD,
|
|
7
|
+
EPOCHS_PER_HISTORICAL_VECTOR,
|
|
8
|
+
ForkName,
|
|
9
|
+
ForkSeq,
|
|
10
|
+
MAX_ATTESTATIONS,
|
|
11
|
+
MAX_EFFECTIVE_BALANCE,
|
|
12
|
+
SLOTS_PER_EPOCH,
|
|
13
|
+
SLOTS_PER_HISTORICAL_ROOT,
|
|
14
|
+
} from "@lodestar/params";
|
|
15
|
+
import {BeaconState, Slot, phase0, ssz} from "@lodestar/types";
|
|
16
|
+
import {getEffectiveBalanceIncrements} from "../cache/effectiveBalanceIncrements.js";
|
|
17
|
+
import {
|
|
18
|
+
computeCommitteeCount,
|
|
19
|
+
computeEpochAtSlot,
|
|
20
|
+
createCachedBeaconState,
|
|
21
|
+
createPubkeyCache,
|
|
22
|
+
interopSecretKey,
|
|
23
|
+
newFilledArray,
|
|
24
|
+
processSlots,
|
|
25
|
+
} from "../index.js";
|
|
26
|
+
import {
|
|
27
|
+
BeaconStateAltair,
|
|
28
|
+
BeaconStatePhase0,
|
|
29
|
+
CachedBeaconStateAllForks,
|
|
30
|
+
CachedBeaconStateAltair,
|
|
31
|
+
CachedBeaconStatePhase0,
|
|
32
|
+
} from "../types.js";
|
|
33
|
+
import {getNextSyncCommittee} from "../util/syncCommittee.js";
|
|
34
|
+
import {getActiveValidatorIndices} from "../util/validator.js";
|
|
35
|
+
import {interopPubkeysCached} from "./interop.js";
|
|
36
|
+
|
|
37
|
+
let phase0State: BeaconStatePhase0 | null = null;
|
|
38
|
+
let phase0CachedState23637: CachedBeaconStatePhase0 | null = null;
|
|
39
|
+
let phase0CachedState23638: CachedBeaconStatePhase0 | null = null;
|
|
40
|
+
let phase0SignedBlock: phase0.SignedBeaconBlock | null = null;
|
|
41
|
+
let altairState: BeaconStateAltair | null = null;
|
|
42
|
+
let altairCachedState23637: CachedBeaconStateAltair | null = null;
|
|
43
|
+
let altairCachedState23638: CachedBeaconStateAltair | null = null;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Number of validators in prater is 210000 as of May 2021
|
|
47
|
+
*/
|
|
48
|
+
export const numValidators = 250000;
|
|
49
|
+
export const keypairsMod = 100;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* As of Jul 07 2021, the performance state has
|
|
53
|
+
* out.prevEpochUnslashedStake.targetStake 7750000000000000n
|
|
54
|
+
* out.currEpochUnslashedTargetStake 7750000000000000n
|
|
55
|
+
* This prefix represent the total stake in Peta Wei
|
|
56
|
+
*/
|
|
57
|
+
export const perfStateId = `${numValidators} vs - 7PWei`;
|
|
58
|
+
|
|
59
|
+
/** Cache interop secret keys */
|
|
60
|
+
const secretKeyByModIndex = new Map<number, SecretKey>();
|
|
61
|
+
const epoch = 23638;
|
|
62
|
+
export const perfStateEpoch = epoch;
|
|
63
|
+
|
|
64
|
+
export function getPubkeys(vc = numValidators) {
|
|
65
|
+
const pubkeysMod = interopPubkeysCached(keypairsMod);
|
|
66
|
+
const pubkeysModObj = pubkeysMod.map((pk) => PublicKey.fromBytes(pk));
|
|
67
|
+
const pubkeys = Array.from({length: vc}, (_, i) => pubkeysMod[i % keypairsMod]);
|
|
68
|
+
return {pubkeysMod, pubkeysModObj, pubkeys};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Get secret key of a validatorIndex, if the pubkeys are generated with `getPubkeys()` */
|
|
72
|
+
export function getSecretKeyFromIndex(validatorIndex: number): SecretKey {
|
|
73
|
+
return interopSecretKey(validatorIndex % keypairsMod);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Get secret key of a validatorIndex, if the pubkeys are generated with `getPubkeys()` */
|
|
77
|
+
export function getSecretKeyFromIndexCached(validatorIndex: number): SecretKey {
|
|
78
|
+
const keyIndex = validatorIndex % keypairsMod;
|
|
79
|
+
let sk = secretKeyByModIndex.get(keyIndex);
|
|
80
|
+
if (!sk) {
|
|
81
|
+
sk = interopSecretKey(keyIndex);
|
|
82
|
+
secretKeyByModIndex.set(keyIndex, sk);
|
|
83
|
+
}
|
|
84
|
+
return sk;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function getPubkeyCaches({pubkeysMod}: ReturnType<typeof getPubkeys>) {
|
|
88
|
+
// Manually sync pubkeys to prevent doing BLS opts 110_000 times
|
|
89
|
+
const pubkeyCache = createPubkeyCache();
|
|
90
|
+
for (let i = 0; i < numValidators; i++) {
|
|
91
|
+
const pubkey = pubkeysMod[i % keypairsMod];
|
|
92
|
+
pubkeyCache.set(i, pubkey);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {pubkeyCache};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function generatePerfTestCachedStatePhase0(opts?: {goBackOneSlot: boolean}): CachedBeaconStatePhase0 {
|
|
99
|
+
// Generate only some publicKeys
|
|
100
|
+
const {pubkeys, pubkeysMod, pubkeysModObj} = getPubkeys();
|
|
101
|
+
const {pubkeyCache} = getPubkeyCaches({pubkeys, pubkeysMod, pubkeysModObj});
|
|
102
|
+
|
|
103
|
+
if (!phase0State) {
|
|
104
|
+
const state = buildPerformanceStatePhase0();
|
|
105
|
+
|
|
106
|
+
// no justificationBits
|
|
107
|
+
phase0State = ssz.phase0.BeaconState.toViewDU(state);
|
|
108
|
+
|
|
109
|
+
// cache roots
|
|
110
|
+
phase0State.hashTreeRoot();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (!phase0CachedState23637) {
|
|
114
|
+
const state = phase0State.clone();
|
|
115
|
+
state.slot -= 1;
|
|
116
|
+
phase0CachedState23637 = createCachedBeaconState(state, {
|
|
117
|
+
config: createBeaconConfig(config, state.genesisValidatorsRoot),
|
|
118
|
+
pubkeyCache,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const currentEpoch = computeEpochAtSlot(state.slot - 1);
|
|
122
|
+
const previousEpoch = currentEpoch - 1;
|
|
123
|
+
|
|
124
|
+
// previous epoch attestations
|
|
125
|
+
const numPrevAttestations = SLOTS_PER_EPOCH * MAX_ATTESTATIONS;
|
|
126
|
+
const activeValidatorCount = pubkeys.length;
|
|
127
|
+
const committeesPerSlot = computeCommitteeCount(activeValidatorCount);
|
|
128
|
+
for (let i = 0; i < numPrevAttestations; i++) {
|
|
129
|
+
const slotInEpoch = i % SLOTS_PER_EPOCH;
|
|
130
|
+
const slot = previousEpoch * SLOTS_PER_EPOCH + slotInEpoch;
|
|
131
|
+
const index = i % committeesPerSlot;
|
|
132
|
+
const shuffling = phase0CachedState23637.epochCtx.getShufflingAtEpoch(previousEpoch);
|
|
133
|
+
const committee = shuffling.committees[slotInEpoch][index];
|
|
134
|
+
phase0CachedState23637.previousEpochAttestations.push(
|
|
135
|
+
ssz.phase0.PendingAttestation.toViewDU({
|
|
136
|
+
aggregationBits: BitArray.fromBoolArray(Array.from({length: committee.length}, () => true)),
|
|
137
|
+
data: {
|
|
138
|
+
beaconBlockRoot: phase0CachedState23637.blockRoots.get(slotInEpoch % SLOTS_PER_HISTORICAL_ROOT),
|
|
139
|
+
index,
|
|
140
|
+
slot,
|
|
141
|
+
source: state.previousJustifiedCheckpoint,
|
|
142
|
+
target: state.currentJustifiedCheckpoint,
|
|
143
|
+
},
|
|
144
|
+
inclusionDelay: 1,
|
|
145
|
+
proposerIndex: i,
|
|
146
|
+
})
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// current epoch attestations
|
|
151
|
+
const numCurAttestations = (SLOTS_PER_EPOCH - 1) * MAX_ATTESTATIONS;
|
|
152
|
+
for (let i = 0; i < numCurAttestations; i++) {
|
|
153
|
+
const slotInEpoch = i % SLOTS_PER_EPOCH;
|
|
154
|
+
const slot = currentEpoch * SLOTS_PER_EPOCH + slotInEpoch;
|
|
155
|
+
const index = i % committeesPerSlot;
|
|
156
|
+
const shuffling = phase0CachedState23637.epochCtx.getShufflingAtEpoch(previousEpoch);
|
|
157
|
+
const committee = shuffling.committees[slotInEpoch][index];
|
|
158
|
+
|
|
159
|
+
phase0CachedState23637.currentEpochAttestations.push(
|
|
160
|
+
ssz.phase0.PendingAttestation.toViewDU({
|
|
161
|
+
aggregationBits: BitArray.fromBoolArray(Array.from({length: committee.length}, () => true)),
|
|
162
|
+
data: {
|
|
163
|
+
beaconBlockRoot: phase0CachedState23637.blockRoots.get(slotInEpoch % SLOTS_PER_HISTORICAL_ROOT),
|
|
164
|
+
index,
|
|
165
|
+
slot,
|
|
166
|
+
source: state.currentJustifiedCheckpoint,
|
|
167
|
+
target: {
|
|
168
|
+
epoch: currentEpoch,
|
|
169
|
+
root: phase0CachedState23637.blockRoots.get((currentEpoch * SLOTS_PER_EPOCH) % SLOTS_PER_HISTORICAL_ROOT),
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
inclusionDelay: 1,
|
|
173
|
+
proposerIndex: i,
|
|
174
|
+
})
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (!phase0CachedState23638) {
|
|
179
|
+
phase0CachedState23638 = processSlots(
|
|
180
|
+
phase0CachedState23637,
|
|
181
|
+
phase0CachedState23637.slot + 1
|
|
182
|
+
) as CachedBeaconStatePhase0;
|
|
183
|
+
phase0CachedState23638.slot += 1;
|
|
184
|
+
}
|
|
185
|
+
const resultingState = opts?.goBackOneSlot ? phase0CachedState23637 : phase0CachedState23638;
|
|
186
|
+
|
|
187
|
+
return resultingState.clone();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function cachedStateAltairPopulateCaches(state: CachedBeaconStateAltair): void {
|
|
191
|
+
// Populate caches
|
|
192
|
+
state.blockRoots.getAllReadonly();
|
|
193
|
+
state.eth1DataVotes.getAllReadonly();
|
|
194
|
+
state.validators.getAllReadonly();
|
|
195
|
+
state.balances.getAll();
|
|
196
|
+
state.previousEpochParticipation.getAll();
|
|
197
|
+
state.currentEpochParticipation.getAll();
|
|
198
|
+
state.inactivityScores.getAll();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Warning: This function has side effects on the cached state
|
|
203
|
+
* The order in which the caches are populated is important and can cause stable tests to fail.
|
|
204
|
+
*/
|
|
205
|
+
export function generatePerfTestCachedStateAltair(opts?: {
|
|
206
|
+
goBackOneSlot: boolean;
|
|
207
|
+
vc?: number;
|
|
208
|
+
}): CachedBeaconStateAltair {
|
|
209
|
+
const {pubkeys, pubkeysMod, pubkeysModObj} = getPubkeys(opts?.vc);
|
|
210
|
+
const {pubkeyCache} = getPubkeyCaches({pubkeys, pubkeysMod, pubkeysModObj});
|
|
211
|
+
|
|
212
|
+
const altairConfig = createChainForkConfig({ALTAIR_FORK_EPOCH: 0});
|
|
213
|
+
|
|
214
|
+
const origState = generatePerformanceStateAltair(pubkeys);
|
|
215
|
+
|
|
216
|
+
if (!altairCachedState23637) {
|
|
217
|
+
const state = origState.clone();
|
|
218
|
+
state.slot -= 1;
|
|
219
|
+
altairCachedState23637 = createCachedBeaconState(state, {
|
|
220
|
+
config: createBeaconConfig(altairConfig, state.genesisValidatorsRoot),
|
|
221
|
+
pubkeyCache,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
if (!altairCachedState23638) {
|
|
225
|
+
altairCachedState23638 = processSlots(
|
|
226
|
+
altairCachedState23637,
|
|
227
|
+
altairCachedState23637.slot + 1
|
|
228
|
+
) as CachedBeaconStateAltair;
|
|
229
|
+
altairCachedState23638.slot += 1;
|
|
230
|
+
}
|
|
231
|
+
const resultingState = opts?.goBackOneSlot ? altairCachedState23637 : altairCachedState23638;
|
|
232
|
+
|
|
233
|
+
return resultingState.clone();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* This is generated from Medalla state 756416
|
|
238
|
+
*/
|
|
239
|
+
export function generatePerformanceStateAltair(pubkeysArg?: Uint8Array[]): BeaconStateAltair {
|
|
240
|
+
if (!altairState) {
|
|
241
|
+
const pubkeys = pubkeysArg || getPubkeys().pubkeys;
|
|
242
|
+
const statePhase0 = buildPerformanceStatePhase0(pubkeys);
|
|
243
|
+
const state = statePhase0 as BeaconState as BeaconState<ForkName.altair>;
|
|
244
|
+
|
|
245
|
+
state.previousEpochParticipation = newFilledArray(pubkeys.length, 0b111);
|
|
246
|
+
state.currentEpochParticipation = state.previousEpochParticipation;
|
|
247
|
+
state.inactivityScores = Array.from({length: pubkeys.length}, (_, i) => i % 2);
|
|
248
|
+
|
|
249
|
+
// Placeholder syncCommittees
|
|
250
|
+
state.currentSyncCommittee = ssz.altair.SyncCommittee.defaultValue();
|
|
251
|
+
state.nextSyncCommittee = state.currentSyncCommittee;
|
|
252
|
+
|
|
253
|
+
// Now the state is fully populated to convert to ViewDU
|
|
254
|
+
altairState = ssz.altair.BeaconState.toViewDU(state);
|
|
255
|
+
|
|
256
|
+
// Now set correct syncCommittees
|
|
257
|
+
const epoch = computeEpochAtSlot(state.slot);
|
|
258
|
+
const activeValidatorIndices = getActiveValidatorIndices(altairState, epoch);
|
|
259
|
+
|
|
260
|
+
const effectiveBalanceIncrements = getEffectiveBalanceIncrements(altairState);
|
|
261
|
+
const {syncCommittee} = getNextSyncCommittee(
|
|
262
|
+
ForkSeq.altair,
|
|
263
|
+
altairState,
|
|
264
|
+
activeValidatorIndices,
|
|
265
|
+
effectiveBalanceIncrements
|
|
266
|
+
);
|
|
267
|
+
state.currentSyncCommittee = syncCommittee;
|
|
268
|
+
state.nextSyncCommittee = syncCommittee;
|
|
269
|
+
|
|
270
|
+
altairState = ssz.altair.BeaconState.toViewDU(state);
|
|
271
|
+
// cache roots
|
|
272
|
+
altairState.hashTreeRoot();
|
|
273
|
+
}
|
|
274
|
+
return altairState.clone();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* This is generated from Medalla block 756417
|
|
279
|
+
*/
|
|
280
|
+
export function generatePerformanceBlockPhase0(): phase0.SignedBeaconBlock {
|
|
281
|
+
if (!phase0SignedBlock) {
|
|
282
|
+
const block = ssz.phase0.SignedBeaconBlock.defaultValue();
|
|
283
|
+
const parentState = generatePerfTestCachedStatePhase0();
|
|
284
|
+
block.message.slot = parentState.slot;
|
|
285
|
+
block.message.proposerIndex = parentState.epochCtx.getBeaconProposer(parentState.slot);
|
|
286
|
+
block.message.parentRoot = ssz.phase0.BeaconBlockHeader.hashTreeRoot(parentState.latestBlockHeader);
|
|
287
|
+
block.message.stateRoot = fromHexString("0x6c86ca3c4c6688cf189421b8a68bf2dbc91521609965e6f4e207d44347061fee");
|
|
288
|
+
block.message.body.randaoReveal = fromHexString(
|
|
289
|
+
"0x8a5d2673c48f22f6ed19462efec35645db490df29eed2f56321dbe4a89b2463b0c902095a7ab74a2dc5b7f67edb1a19507ea3d4361d5af9cb0a524945c91638dfd6568841486813a2c45142659d6d9403f5081febb123a7931edbc248b9d0025"
|
|
290
|
+
);
|
|
291
|
+
// eth1Data, graffiti, attestations
|
|
292
|
+
phase0SignedBlock = block;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return phase0SignedBlock;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function buildPerformanceStatePhase0(pubkeysArg?: Uint8Array[]): phase0.BeaconState {
|
|
299
|
+
const slot = epoch * SLOTS_PER_EPOCH;
|
|
300
|
+
const pubkeys = pubkeysArg || getPubkeys().pubkeys;
|
|
301
|
+
const currentEpoch = computeEpochAtSlot(slot - 1);
|
|
302
|
+
|
|
303
|
+
return {
|
|
304
|
+
// Misc
|
|
305
|
+
genesisTime: 1596546008,
|
|
306
|
+
genesisValidatorsRoot: fromHexString("0x04700007fabc8282644aed6d1c7c9e21d38a03a0c4ba193f3afe428824b3a673"),
|
|
307
|
+
slot: epoch * SLOTS_PER_EPOCH,
|
|
308
|
+
fork: {
|
|
309
|
+
currentVersion: fromHexString("0x00000001"),
|
|
310
|
+
previousVersion: fromHexString("0x00000001"),
|
|
311
|
+
epoch: 0,
|
|
312
|
+
},
|
|
313
|
+
// History
|
|
314
|
+
latestBlockHeader: {
|
|
315
|
+
slot: slot - 1,
|
|
316
|
+
proposerIndex: 80882,
|
|
317
|
+
parentRoot: fromHexString("0x5b83c3078e474b86af60043eda82a34c3c2e5ebf83146b14d9d909aea4163ef2"),
|
|
318
|
+
stateRoot: fromHexString("0x2761ae355e8a53c11e0e37d5e417f8984db0c53fa83f1bc65f89c6af35a196a7"),
|
|
319
|
+
bodyRoot: fromHexString("0x249a1962eef90e122fa2447040bfac102798b1dba9c73e5593bc5aa32eb92bfd"),
|
|
320
|
+
},
|
|
321
|
+
blockRoots: Array.from({length: SLOTS_PER_HISTORICAL_ROOT}, (_, i) => Buffer.alloc(32, i)),
|
|
322
|
+
stateRoots: Array.from({length: SLOTS_PER_HISTORICAL_ROOT}, (_, i) => Buffer.alloc(32, i)),
|
|
323
|
+
historicalRoots: [],
|
|
324
|
+
// Eth1
|
|
325
|
+
eth1Data: {
|
|
326
|
+
depositCount: pubkeys.length,
|
|
327
|
+
depositRoot: fromHexString("0xcb1f89a924cfd31224823db5a41b1643f10faa7aedf231f1e28887f6ee98c047"),
|
|
328
|
+
blockHash: fromHexString("0x701fb2869ce16d0f1d14f6705725adb0dec6799da29006dfc6fff83960298f21"),
|
|
329
|
+
},
|
|
330
|
+
// minus one so that inserting 1 from block works
|
|
331
|
+
eth1DataVotes: newFilledArray(EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH - 1, {
|
|
332
|
+
depositCount: 1,
|
|
333
|
+
depositRoot: Buffer.alloc(32, 1),
|
|
334
|
+
blockHash: Buffer.alloc(32, 1),
|
|
335
|
+
}),
|
|
336
|
+
eth1DepositIndex: pubkeys.length,
|
|
337
|
+
// Registry
|
|
338
|
+
validators: pubkeys.map((_, i) => ({
|
|
339
|
+
pubkey: pubkeys[i],
|
|
340
|
+
withdrawalCredentials: Buffer.alloc(32, i),
|
|
341
|
+
effectiveBalance: 31000000000,
|
|
342
|
+
slashed: false,
|
|
343
|
+
activationEligibilityEpoch: 0,
|
|
344
|
+
activationEpoch: 0,
|
|
345
|
+
exitEpoch: Infinity,
|
|
346
|
+
withdrawableEpoch: Infinity,
|
|
347
|
+
})),
|
|
348
|
+
balances: Array.from({length: pubkeys.length}, () => 31217089836),
|
|
349
|
+
randaoMixes: Array.from({length: EPOCHS_PER_HISTORICAL_VECTOR}, (_, i) => Buffer.alloc(32, i)),
|
|
350
|
+
// Slashings
|
|
351
|
+
slashings: ssz.phase0.Slashings.defaultValue(),
|
|
352
|
+
previousEpochAttestations: [],
|
|
353
|
+
currentEpochAttestations: [],
|
|
354
|
+
// Finality
|
|
355
|
+
justificationBits: BitArray.fromBitLen(4),
|
|
356
|
+
previousJustifiedCheckpoint: {
|
|
357
|
+
epoch: currentEpoch - 2,
|
|
358
|
+
root: fromHexString("0x3fe60bf06a57b0956cd1f8181d26649cf8bf79e48bf82f55562e04b33d4785d4"),
|
|
359
|
+
},
|
|
360
|
+
currentJustifiedCheckpoint: {
|
|
361
|
+
epoch: currentEpoch - 1,
|
|
362
|
+
root: fromHexString("0x3ba0913d2fb5e4cbcfb0d39eb15803157c1e769d63b8619285d8fdabbd8181c7"),
|
|
363
|
+
},
|
|
364
|
+
finalizedCheckpoint: {
|
|
365
|
+
epoch: currentEpoch - 3,
|
|
366
|
+
root: fromHexString("0x122b8ff579d0c8f8a8b66326bdfec3f685007d2842f01615a0768870961ccc17"),
|
|
367
|
+
},
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export function generateTestCachedBeaconStateOnlyValidators({
|
|
372
|
+
vc,
|
|
373
|
+
slot,
|
|
374
|
+
}: {
|
|
375
|
+
vc: number;
|
|
376
|
+
slot: Slot;
|
|
377
|
+
}): CachedBeaconStateAllForks {
|
|
378
|
+
// Generate only some publicKeys
|
|
379
|
+
const {pubkeys, pubkeysMod} = getPubkeys(vc);
|
|
380
|
+
|
|
381
|
+
// Manually sync pubkeys to prevent doing BLS opts 110_000 times
|
|
382
|
+
const pubkeyCache = createPubkeyCache();
|
|
383
|
+
for (let i = 0; i < vc; i++) {
|
|
384
|
+
const pubkey = pubkeysMod[i % keypairsMod];
|
|
385
|
+
pubkeyCache.set(i, pubkey);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const state = ssz.phase0.BeaconState.defaultViewDU();
|
|
389
|
+
state.slot = slot;
|
|
390
|
+
|
|
391
|
+
const activeValidator = ssz.phase0.Validator.toViewDU({
|
|
392
|
+
pubkey: Buffer.alloc(48, 0),
|
|
393
|
+
withdrawalCredentials: Buffer.alloc(32, 0),
|
|
394
|
+
effectiveBalance: MAX_EFFECTIVE_BALANCE,
|
|
395
|
+
slashed: false,
|
|
396
|
+
activationEligibilityEpoch: 0,
|
|
397
|
+
activationEpoch: 0,
|
|
398
|
+
exitEpoch: Infinity,
|
|
399
|
+
withdrawableEpoch: Infinity,
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
for (let i = 0; i < vc; i++) {
|
|
403
|
+
const validator = activeValidator.clone();
|
|
404
|
+
validator.pubkey = pubkeys[i];
|
|
405
|
+
state.validators.push(validator);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
state.balances = ssz.phase0.Balances.toViewDU(newFilledArray(pubkeys.length, MAX_EFFECTIVE_BALANCE));
|
|
409
|
+
state.randaoMixes = ssz.phase0.RandaoMixes.toViewDU(
|
|
410
|
+
newFilledArray(EPOCHS_PER_HISTORICAL_VECTOR, Buffer.alloc(32, 0xdd))
|
|
411
|
+
);
|
|
412
|
+
|
|
413
|
+
// Commit ViewDU changes
|
|
414
|
+
state.commit();
|
|
415
|
+
|
|
416
|
+
// Sanity check for .commit() above
|
|
417
|
+
if (state.validators.length !== vc) {
|
|
418
|
+
throw Error(`Wrong number of validators in the state: ${state.validators.length} !== ${vc}`);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
return createCachedBeaconState(
|
|
422
|
+
state,
|
|
423
|
+
{
|
|
424
|
+
config: createBeaconConfig(config, state.genesisValidatorsRoot),
|
|
425
|
+
pubkeyCache,
|
|
426
|
+
},
|
|
427
|
+
{skipSyncPubkeys: true}
|
|
428
|
+
);
|
|
429
|
+
}
|