66 Any ,
77 Iterable ,
88 Sequence ,
9- Tuple ,
109 TYPE_CHECKING ,
1110)
1211
2322)
2423
2524from eth .beacon .block_committees_info import BlockCommitteesInfo
25+ from eth .beacon .enums .validator_status_codes import (
26+ ValidatorStatusCode ,
27+ )
2628from eth .beacon .types .shard_and_committees import (
2729 ShardAndCommittee ,
2830)
3739 from eth .beacon .types .attestation_records import AttestationRecord # noqa: F401
3840 from eth .beacon .types .blocks import BaseBeaconBlock # noqa: F401
3941 from eth .beacon .types .crystallized_states import CrystallizedState # noqa: F401
42+ from eth .beacon .types .states import BeaconState # noqa: F401
4043 from eth .beacon .types .validator_records import ValidatorRecord # noqa: F401
4144
4245
@@ -170,6 +173,9 @@ def get_shards_and_committees_for_slot(
170173 crystallized_state : 'CrystallizedState' ,
171174 slot : int ,
172175 cycle_length : int ) -> Iterable [ShardAndCommittee ]:
176+ """
177+ FIXME
178+ """
173179 if len (crystallized_state .shard_and_committee_for_slots ) != cycle_length * 2 :
174180 raise ValueError (
175181 "Length of shard_and_committee_for_slots != cycle_length * 2"
@@ -192,6 +198,7 @@ def get_attestation_indices(crystallized_state: 'CrystallizedState',
192198 attestation : 'AttestationRecord' ,
193199 cycle_length : int ) -> Iterable [int ]:
194200 """
201+ FIXME
195202 Return committee of the given attestation.
196203 """
197204 shard_id = attestation .shard_id
@@ -208,63 +215,32 @@ def get_attestation_indices(crystallized_state: 'CrystallizedState',
208215
209216
210217@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 ]:
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+ Return the active validators.
217221 """
218222 o = []
219223 for index , validator in enumerate (validators ):
220- if (validator .start_dynasty <= dynasty and dynasty < validator . end_dynasty ):
224+ if (validator .status == ValidatorStatusCode . ACTIVE ):
221225 o .append (index )
222226 return o
223227
224228
225229#
226230# Shuffling
227231#
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-
257232@to_tuple
258233def _get_shards_and_committees_for_shard_indices (
259234 shard_indices : Sequence [Sequence [int ]],
260- shard_start : int ,
235+ start_shard : int ,
261236 shard_count : int ) -> Iterable [ShardAndCommittee ]:
262237 """
238+ FIXME
263239 Returns filled [ShardAndCommittee] tuple.
264240 """
265241 for index , indices in enumerate (shard_indices ):
266242 yield ShardAndCommittee (
267- shard = (shard_start + index ) % shard_count ,
243+ shard = (start_shard + index ) % shard_count ,
268244 committee = indices
269245 )
270246
@@ -273,10 +249,9 @@ def _get_shards_and_committees_for_shard_indices(
273249def get_new_shuffling (* ,
274250 seed : Hash32 ,
275251 validators : Sequence ['ValidatorRecord' ],
276- dynasty : int ,
277252 crosslinking_start_shard : int ,
278253 cycle_length : int ,
279- min_committee_size : int ,
254+ target_committee_size : int ,
280255 shard_count : int ) -> Iterable [Iterable [ShardAndCommittee ]]:
281256 """
282257 Return shuffled ``shard_and_committee_for_slots`` (``[[ShardAndCommittee]]``) of
@@ -319,15 +294,13 @@ def get_new_shuffling(*,
319294 ShardAndCommittee(shard_id=5, committee=[7, 3, 11]),
320295 ],
321296 ]
322-
323- NOTE: The spec might be updated to output an array rather than an array of arrays.
324297 """
325- active_validators = get_active_validator_indices (dynasty , validators )
298+ active_validators = get_active_validator_indices (validators )
326299 active_validators_size = len (active_validators )
327300 committees_per_slot = clamp (
328301 1 ,
329302 shard_count // cycle_length ,
330- active_validators_size // cycle_length // ( min_committee_size * 2 ) + 1 ,
303+ active_validators_size // cycle_length // target_committee_size ,
331304 )
332305 shuffled_active_validator_indices = shuffle (active_validators , seed )
333306
@@ -336,10 +309,10 @@ def get_new_shuffling(*,
336309 for index , slot_indices in enumerate (validators_per_slot ):
337310 # Split the shuffled list into committees_per_slot pieces
338311 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
340313 yield _get_shards_and_committees_for_shard_indices (
341314 shard_indices ,
342- shard_id_start ,
315+ start_shard ,
343316 shard_count ,
344317 )
345318
@@ -356,6 +329,7 @@ def get_block_committees_info(parent_block: 'BaseBeaconBlock',
356329 cycle_length ,
357330 )
358331 """
332+ FIXME
359333 Return the block committees and proposer info with BlockCommitteesInfo pack.
360334 """
361335 # `proposer_index_in_committee` th attester in `shard_and_committee`
0 commit comments