6
6
Any ,
7
7
Iterable ,
8
8
Sequence ,
9
- Tuple ,
10
9
TYPE_CHECKING ,
11
10
)
12
11
23
22
)
24
23
25
24
from eth .beacon .block_committees_info import BlockCommitteesInfo
25
+ from eth .beacon .enums .validator_status_codes import (
26
+ ValidatorStatusCode ,
27
+ )
26
28
from eth .beacon .types .shard_and_committees import (
27
29
ShardAndCommittee ,
28
30
)
37
39
from eth .beacon .types .attestation_records import AttestationRecord # noqa: F401
38
40
from eth .beacon .types .blocks import BaseBeaconBlock # noqa: F401
39
41
from eth .beacon .types .crystallized_states import CrystallizedState # noqa: F401
42
+ from eth .beacon .types .states import BeaconState # noqa: F401
40
43
from eth .beacon .types .validator_records import ValidatorRecord # noqa: F401
41
44
42
45
@@ -170,6 +173,9 @@ def get_shards_and_committees_for_slot(
170
173
crystallized_state : 'CrystallizedState' ,
171
174
slot : int ,
172
175
cycle_length : int ) -> Iterable [ShardAndCommittee ]:
176
+ """
177
+ FIXME
178
+ """
173
179
if len (crystallized_state .shard_and_committee_for_slots ) != cycle_length * 2 :
174
180
raise ValueError (
175
181
"Length of shard_and_committee_for_slots != cycle_length * 2"
@@ -192,6 +198,7 @@ def get_attestation_indices(crystallized_state: 'CrystallizedState',
192
198
attestation : 'AttestationRecord' ,
193
199
cycle_length : int ) -> Iterable [int ]:
194
200
"""
201
+ FIXME
195
202
Return committee of the given attestation.
196
203
"""
197
204
shard_id = attestation .shard_id
@@ -208,63 +215,32 @@ def get_attestation_indices(crystallized_state: 'CrystallizedState',
208
215
209
216
210
217
@to_tuple
211
- def get_active_validator_indices (dynasty : int ,
212
- validators : Iterable ['ValidatorRecord' ]) -> Iterable [int ]:
218
+ def get_active_validator_indices (validators : Sequence ['ValidatorRecord' ]) -> Iterable [int ]:
213
219
"""
214
- TODO: Logic changed in the latest spec, will have to update when we add validator
215
- rotation logic.
216
- https://github.com/ethereum/eth2.0-specs/commit/52cf7f943dc99cfd27db9fb2c03c692858e2a789#diff-a08ecec277db4a6ed0b3635cfadc9af1 # noqa: E501
220
+ Return the active validators.
217
221
"""
218
222
o = []
219
223
for index , validator in enumerate (validators ):
220
- if (validator .start_dynasty <= dynasty and dynasty < validator . end_dynasty ):
224
+ if (validator .status == ValidatorStatusCode . ACTIVE ):
221
225
o .append (index )
222
226
return o
223
227
224
228
225
229
#
226
230
# Shuffling
227
231
#
228
- def _get_shuffling_committee_slot_portions (
229
- active_validators_size : int ,
230
- cycle_length : int ,
231
- min_committee_size : int ,
232
- shard_count : int ) -> Tuple [int , int ]:
233
- """
234
- Return committees number per slot and slots number per committee.
235
- """
236
- # If there are enough active validators to form committees for every slot
237
- if active_validators_size >= cycle_length * min_committee_size :
238
- # One slot can be attested by many committees, but not more than shard_count // cycle_length
239
- committees_per_slot = min (
240
- active_validators_size // cycle_length // (min_committee_size * 2 ) + 1 ,
241
- shard_count // cycle_length
242
- )
243
- # One committee only has to attest one slot
244
- slots_per_committee = 1
245
- else :
246
- # One slot can only be asttested by one committee
247
- committees_per_slot = 1
248
- # One committee has to asttest more than one slot
249
- slots_per_committee = 1
250
- bound = cycle_length * min (min_committee_size , active_validators_size )
251
- while (active_validators_size * slots_per_committee < bound ):
252
- slots_per_committee *= 2
253
-
254
- return committees_per_slot , slots_per_committee
255
-
256
-
257
232
@to_tuple
258
233
def _get_shards_and_committees_for_shard_indices (
259
234
shard_indices : Sequence [Sequence [int ]],
260
- shard_start : int ,
235
+ start_shard : int ,
261
236
shard_count : int ) -> Iterable [ShardAndCommittee ]:
262
237
"""
238
+ FIXME
263
239
Returns filled [ShardAndCommittee] tuple.
264
240
"""
265
241
for index , indices in enumerate (shard_indices ):
266
242
yield ShardAndCommittee (
267
- shard = (shard_start + index ) % shard_count ,
243
+ shard = (start_shard + index ) % shard_count ,
268
244
committee = indices
269
245
)
270
246
@@ -273,10 +249,9 @@ def _get_shards_and_committees_for_shard_indices(
273
249
def get_new_shuffling (* ,
274
250
seed : Hash32 ,
275
251
validators : Sequence ['ValidatorRecord' ],
276
- dynasty : int ,
277
252
crosslinking_start_shard : int ,
278
253
cycle_length : int ,
279
- min_committee_size : int ,
254
+ target_committee_size : int ,
280
255
shard_count : int ) -> Iterable [Iterable [ShardAndCommittee ]]:
281
256
"""
282
257
Return shuffled ``shard_and_committee_for_slots`` (``[[ShardAndCommittee]]``) of
@@ -319,15 +294,13 @@ def get_new_shuffling(*,
319
294
ShardAndCommittee(shard_id=5, committee=[7, 3, 11]),
320
295
],
321
296
]
322
-
323
- NOTE: The spec might be updated to output an array rather than an array of arrays.
324
297
"""
325
- active_validators = get_active_validator_indices (dynasty , validators )
298
+ active_validators = get_active_validator_indices (validators )
326
299
active_validators_size = len (active_validators )
327
300
committees_per_slot = clamp (
328
301
1 ,
329
302
shard_count // cycle_length ,
330
- active_validators_size // cycle_length // ( min_committee_size * 2 ) + 1 ,
303
+ active_validators_size // cycle_length // target_committee_size ,
331
304
)
332
305
shuffled_active_validator_indices = shuffle (active_validators , seed )
333
306
@@ -336,10 +309,10 @@ def get_new_shuffling(*,
336
309
for index , slot_indices in enumerate (validators_per_slot ):
337
310
# Split the shuffled list into committees_per_slot pieces
338
311
shard_indices = split (slot_indices , committees_per_slot )
339
- shard_id_start = crosslinking_start_shard + index * committees_per_slot
312
+ start_shard = crosslinking_start_shard + index * committees_per_slot
340
313
yield _get_shards_and_committees_for_shard_indices (
341
314
shard_indices ,
342
- shard_id_start ,
315
+ start_shard ,
343
316
shard_count ,
344
317
)
345
318
@@ -356,6 +329,7 @@ def get_block_committees_info(parent_block: 'BaseBeaconBlock',
356
329
cycle_length ,
357
330
)
358
331
"""
332
+ FIXME
359
333
Return the block committees and proposer info with BlockCommitteesInfo pack.
360
334
"""
361
335
# `proposer_index_in_committee` th attester in `shard_and_committee`
0 commit comments