2323)
2424
2525from eth .beacon .block_committees_info import BlockCommitteesInfo
26+ from eth .beacon .enums .validator_status_codes import (
27+ ValidatorStatusCode ,
28+ )
2629from eth .beacon .types .shard_and_committees import (
2730 ShardAndCommittee ,
2831)
3740 from eth .beacon .types .attestation_records import AttestationRecord # noqa: F401
3841 from eth .beacon .types .blocks import BaseBeaconBlock # noqa: F401
3942 from eth .beacon .types .crystallized_states import CrystallizedState # noqa: F401
43+ from eth .beacon .types .states import BeaconState # noqa: F401
4044 from eth .beacon .types .validator_records import ValidatorRecord # noqa: F401
4145
4246
@@ -170,6 +174,9 @@ def get_shards_and_committees_for_slot(
170174 crystallized_state : 'CrystallizedState' ,
171175 slot : int ,
172176 cycle_length : int ) -> Iterable [ShardAndCommittee ]:
177+ """
178+ FIXME
179+ """
173180 if len (crystallized_state .shard_and_committee_for_slots ) != cycle_length * 2 :
174181 raise ValueError (
175182 "Length of shard_and_committee_for_slots != cycle_length * 2"
@@ -192,6 +199,7 @@ def get_attestation_indices(crystallized_state: 'CrystallizedState',
192199 attestation : 'AttestationRecord' ,
193200 cycle_length : int ) -> Iterable [int ]:
194201 """
202+ FIXME
195203 Return committee of the given attestation.
196204 """
197205 shard_id = attestation .shard_id
@@ -207,64 +215,30 @@ def get_attestation_indices(crystallized_state: 'CrystallizedState',
207215 yield from shard_and_committee .committee
208216
209217
210- @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' ]) -> Tuple [int , ...]:
213219 """
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+ Gets indices of active validators from ``validators``.
217221 """
218- o = []
219- for index , validator in enumerate (validators ):
220- if (validator .start_dynasty <= dynasty and dynasty < validator .end_dynasty ):
221- o .append (index )
222- return o
222+ return tuple (
223+ i for i , v in enumerate (validators )
224+ if v .status in [ValidatorStatusCode .ACTIVE , ValidatorStatusCode .PENDING_EXIT ]
225+ )
223226
224227
225228#
226229# Shuffling
227230#
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-
257231@to_tuple
258232def _get_shards_and_committees_for_shard_indices (
259233 shard_indices : Sequence [Sequence [int ]],
260- shard_start : int ,
234+ start_shard : int ,
261235 shard_count : int ) -> Iterable [ShardAndCommittee ]:
262236 """
263237 Returns filled [ShardAndCommittee] tuple.
264238 """
265239 for index , indices in enumerate (shard_indices ):
266240 yield ShardAndCommittee (
267- shard = (shard_start + index ) % shard_count ,
241+ shard = (start_shard + index ) % shard_count ,
268242 committee = indices
269243 )
270244
@@ -273,14 +247,13 @@ def _get_shards_and_committees_for_shard_indices(
273247def get_new_shuffling (* ,
274248 seed : Hash32 ,
275249 validators : Sequence ['ValidatorRecord' ],
276- dynasty : int ,
277250 crosslinking_start_shard : int ,
278251 cycle_length : int ,
279- min_committee_size : int ,
252+ target_committee_size : int ,
280253 shard_count : int ) -> Iterable [Iterable [ShardAndCommittee ]]:
281254 """
282255 Return shuffled ``shard_and_committee_for_slots`` (``[[ShardAndCommittee]]``) of
283- the given active ``validators``.
256+ the given active ``validators`` using ``seed`` as entropy .
284257
285258 Two-dimensional:
286259 The first layer is ``slot`` number
@@ -319,27 +292,26 @@ def get_new_shuffling(*,
319292 ShardAndCommittee(shard_id=5, committee=[7, 3, 11]),
320293 ],
321294 ]
322-
323- NOTE: The spec might be updated to output an array rather than an array of arrays.
324295 """
325- active_validators = get_active_validator_indices (dynasty , validators )
296+ active_validators = get_active_validator_indices (validators )
326297 active_validators_size = len (active_validators )
327298 committees_per_slot = clamp (
328299 1 ,
329300 shard_count // cycle_length ,
330- active_validators_size // cycle_length // ( min_committee_size * 2 ) + 1 ,
301+ active_validators_size // cycle_length // target_committee_size ,
331302 )
303+ # Shuffle with seed
332304 shuffled_active_validator_indices = shuffle (active_validators , seed )
333305
334- # Split the shuffled list into cycle_length pieces
306+ # Split the shuffled list into epoch_length pieces
335307 validators_per_slot = split (shuffled_active_validator_indices , cycle_length )
336308 for index , slot_indices in enumerate (validators_per_slot ):
337309 # Split the shuffled list into committees_per_slot pieces
338310 shard_indices = split (slot_indices , committees_per_slot )
339- shard_id_start = crosslinking_start_shard + index * committees_per_slot
311+ start_shard = crosslinking_start_shard + index * committees_per_slot
340312 yield _get_shards_and_committees_for_shard_indices (
341313 shard_indices ,
342- shard_id_start ,
314+ start_shard ,
343315 shard_count ,
344316 )
345317
@@ -356,6 +328,7 @@ def get_block_committees_info(parent_block: 'BaseBeaconBlock',
356328 cycle_length ,
357329 )
358330 """
331+ FIXME
359332 Return the block committees and proposer info with BlockCommitteesInfo pack.
360333 """
361334 # `proposer_index_in_committee` th attester in `shard_and_committee`
0 commit comments