2626from eth .beacon .enums .validator_status_codes import (
2727 ValidatorStatusCode ,
2828)
29- from eth .beacon .types .shard_and_committees import (
30- ShardAndCommittee ,
29+ from eth .beacon .types .shard_committees import (
30+ ShardCommittee ,
3131)
3232from eth .beacon .utils .random import (
3333 shuffle ,
@@ -77,20 +77,20 @@ def get_block_hash(
7777 recent_block_hashes : Sequence [Hash32 ],
7878 current_block_slot_number : int ,
7979 slot : int ,
80- cycle_length : int ) -> Hash32 :
80+ epoch_length : int ) -> Hash32 :
8181 """
8282 Return the blockhash from ``ActiveState.recent_block_hashes`` by
8383 ``current_block_slot_number``.
8484 """
85- if len (recent_block_hashes ) != cycle_length * 2 :
85+ if len (recent_block_hashes ) != epoch_length * 2 :
8686 raise ValueError (
87- "Length of recent_block_hashes != cycle_length * 2"
87+ "Length of recent_block_hashes != epoch_length * 2"
8888 "\t expected: %s, found: %s" % (
89- cycle_length * 2 , len (recent_block_hashes )
89+ epoch_length * 2 , len (recent_block_hashes )
9090 )
9191 )
9292
93- slot_relative_position = current_block_slot_number - cycle_length * 2
93+ slot_relative_position = current_block_slot_number - epoch_length * 2
9494 return _get_element_from_recent_list (
9595 recent_block_hashes ,
9696 slot ,
@@ -104,7 +104,7 @@ def get_hashes_from_recent_block_hashes(
104104 current_block_slot_number : int ,
105105 from_slot : int ,
106106 to_slot : int ,
107- cycle_length : int ) -> Iterable [Hash32 ]:
107+ epoch_length : int ) -> Iterable [Hash32 ]:
108108 """
109109 Returns the block hashes between ``from_slot`` and ``to_slot``.
110110 """
@@ -113,24 +113,24 @@ def get_hashes_from_recent_block_hashes(
113113 recent_block_hashes ,
114114 current_block_slot_number ,
115115 slot ,
116- cycle_length ,
116+ epoch_length ,
117117 )
118118
119119
120120@to_tuple
121121def get_hashes_to_sign (recent_block_hashes : Sequence [Hash32 ],
122122 block : 'BaseBeaconBlock' ,
123- cycle_length : int ) -> Iterable [Hash32 ]:
123+ epoch_length : int ) -> Iterable [Hash32 ]:
124124 """
125125 Given the head block to attest to, collect the list of hashes to be
126126 signed in the attestation.
127127 """
128128 yield from get_hashes_from_recent_block_hashes (
129129 recent_block_hashes ,
130130 block .slot_number ,
131- from_slot = block .slot_number - cycle_length + 1 ,
131+ from_slot = block .slot_number - epoch_length + 1 ,
132132 to_slot = block .slot_number - 1 ,
133- cycle_length = cycle_length ,
133+ epoch_length = epoch_length ,
134134 )
135135 yield block .hash
136136
@@ -139,17 +139,17 @@ def get_hashes_to_sign(recent_block_hashes: Sequence[Hash32],
139139def get_signed_parent_hashes (recent_block_hashes : Sequence [Hash32 ],
140140 block : 'BaseBeaconBlock' ,
141141 attestation : 'AttestationRecord' ,
142- cycle_length : int ) -> Iterable [Hash32 ]:
142+ epoch_length : int ) -> Iterable [Hash32 ]:
143143 """
144144 Given an attestation and the block they were included in,
145145 the list of hashes that were included in the signature.
146146 """
147147 yield from get_hashes_from_recent_block_hashes (
148148 recent_block_hashes ,
149149 block .slot_number ,
150- from_slot = attestation .slot - cycle_length + 1 ,
150+ from_slot = attestation .slot - epoch_length + 1 ,
151151 to_slot = attestation .slot - len (attestation .oblique_parent_hashes ),
152- cycle_length = cycle_length ,
152+ epoch_length = epoch_length ,
153153 )
154154 yield from attestation .oblique_parent_hashes
155155
@@ -167,28 +167,28 @@ def get_new_recent_block_hashes(old_block_hashes: Sequence[Hash32],
167167
168168
169169#
170- # Get shards_and_committees or indices
170+ # Get shards_committees or indices
171171#
172172@to_tuple
173- def get_shards_and_committees_for_slot (
173+ def get_shards_committees_for_slot (
174174 crystallized_state : 'CrystallizedState' ,
175175 slot : int ,
176- cycle_length : int ) -> Iterable [ShardAndCommittee ]:
176+ epoch_length : int ) -> Iterable [ShardCommittee ]:
177177 """
178178 FIXME
179179 """
180- if len (crystallized_state .shard_and_committee_for_slots ) != cycle_length * 2 :
180+ if len (crystallized_state .shard_committee_for_slots ) != epoch_length * 2 :
181181 raise ValueError (
182- "Length of shard_and_committee_for_slots != cycle_length * 2"
182+ "Length of shard_committee_for_slots != epoch_length * 2"
183183 "\t expected: %s, found: %s" % (
184- cycle_length * 2 , len (crystallized_state .shard_and_committee_for_slots )
184+ epoch_length * 2 , len (crystallized_state .shard_committee_for_slots )
185185 )
186186 )
187187
188- slot_relative_position = crystallized_state .last_state_recalc - cycle_length
188+ slot_relative_position = crystallized_state .last_state_recalc - epoch_length
189189
190190 yield from _get_element_from_recent_list (
191- crystallized_state .shard_and_committee_for_slots ,
191+ crystallized_state .shard_committee_for_slots ,
192192 slot ,
193193 slot_relative_position ,
194194 )
@@ -197,22 +197,22 @@ def get_shards_and_committees_for_slot(
197197@to_tuple
198198def get_attestation_indices (crystallized_state : 'CrystallizedState' ,
199199 attestation : 'AttestationRecord' ,
200- cycle_length : int ) -> Iterable [int ]:
200+ epoch_length : int ) -> Iterable [int ]:
201201 """
202202 FIXME
203203 Return committee of the given attestation.
204204 """
205205 shard_id = attestation .shard_id
206206
207- shards_and_committees_for_slot = get_shards_and_committees_for_slot (
207+ shards_committees_for_slot = get_shards_committees_for_slot (
208208 crystallized_state ,
209209 attestation .slot ,
210- cycle_length ,
210+ epoch_length ,
211211 )
212212
213- for shard_and_committee in shards_and_committees_for_slot :
214- if shard_and_committee .shard_id == shard_id :
215- yield from shard_and_committee .committee
213+ for shard_committee in shards_committees_for_slot :
214+ if shard_committee .shard_id == shard_id :
215+ yield from shard_committee .committee
216216
217217
218218def get_active_validator_indices (validators : Sequence ['ValidatorRecord' ]) -> Tuple [int , ...]:
@@ -229,17 +229,19 @@ def get_active_validator_indices(validators: Sequence['ValidatorRecord']) -> Tup
229229# Shuffling
230230#
231231@to_tuple
232- def _get_shards_and_committees_for_shard_indices (
232+ def _get_shards_committees_for_shard_indices (
233233 shard_indices : Sequence [Sequence [int ]],
234234 start_shard : int ,
235- shard_count : int ) -> Iterable [ShardAndCommittee ]:
235+ total_validator_count : int ,
236+ shard_count : int ) -> Iterable [ShardCommittee ]:
236237 """
237- Returns filled [ShardAndCommittee ] tuple.
238+ Returns filled [ShardCommittee ] tuple.
238239 """
239240 for index , indices in enumerate (shard_indices ):
240- yield ShardAndCommittee (
241+ yield ShardCommittee (
241242 shard = (start_shard + index ) % shard_count ,
242- committee = indices
243+ committee = indices ,
244+ total_validator_count = total_validator_count ,
243245 )
244246
245247
@@ -248,18 +250,18 @@ def get_new_shuffling(*,
248250 seed : Hash32 ,
249251 validators : Sequence ['ValidatorRecord' ],
250252 crosslinking_start_shard : int ,
251- cycle_length : int ,
253+ epoch_length : int ,
252254 target_committee_size : int ,
253- shard_count : int ) -> Iterable [Iterable [ShardAndCommittee ]]:
255+ shard_count : int ) -> Iterable [Iterable [ShardCommittee ]]:
254256 """
255- Return shuffled ``shard_and_committee_for_slots `` (``[[ShardAndCommittee ]]``) of
257+ Return shuffled ``shard_committee_for_slots `` (``[[ShardCommittee ]]``) of
256258 the given active ``validators`` using ``seed`` as entropy.
257259
258260 Two-dimensional:
259261 The first layer is ``slot`` number
260- ``shard_and_committee_for_slots [slot] -> [ShardAndCommittee ]``
262+ ``shard_committee_for_slots [slot] -> [ShardCommittee ]``
261263 The second layer is ``shard_indices`` number
262- ``shard_and_committee_for_slots [slot][shard_indices] -> ShardAndCommittee ``
264+ ``shard_committee_for_slots [slot][shard_indices] -> ShardCommittee ``
263265
264266 Example:
265267 validators:
@@ -278,40 +280,41 @@ def get_new_shuffling(*,
278280 [
279281 # slot 0
280282 [
281- ShardAndCommittee (shard_id=0, committee=[6, 0]),
282- ShardAndCommittee (shard_id=1, committee=[2, 12, 14]),
283+ ShardCommittee (shard_id=0, committee=[6, 0]),
284+ ShardCommittee (shard_id=1, committee=[2, 12, 14]),
283285 ],
284286 # slot 1
285287 [
286- ShardAndCommittee (shard_id=2, committee=[8, 10]),
287- ShardAndCommittee (shard_id=3, committee=[4, 9, 1]),
288+ ShardCommittee (shard_id=2, committee=[8, 10]),
289+ ShardCommittee (shard_id=3, committee=[4, 9, 1]),
288290 ],
289291 # slot 2
290292 [
291- ShardAndCommittee (shard_id=4, committee=[5, 13, 15]),
292- ShardAndCommittee (shard_id=5, committee=[7, 3, 11]),
293+ ShardCommittee (shard_id=4, committee=[5, 13, 15]),
294+ ShardCommittee (shard_id=5, committee=[7, 3, 11]),
293295 ],
294296 ]
295297 """
296298 active_validators = get_active_validator_indices (validators )
297299 active_validators_size = len (active_validators )
298300 committees_per_slot = clamp (
299301 1 ,
300- shard_count // cycle_length ,
301- active_validators_size // cycle_length // target_committee_size ,
302+ shard_count // epoch_length ,
303+ active_validators_size // epoch_length // target_committee_size ,
302304 )
303305 # Shuffle with seed
304306 shuffled_active_validator_indices = shuffle (active_validators , seed )
305307
306308 # Split the shuffled list into epoch_length pieces
307- validators_per_slot = split (shuffled_active_validator_indices , cycle_length )
309+ validators_per_slot = split (shuffled_active_validator_indices , epoch_length )
308310 for index , slot_indices in enumerate (validators_per_slot ):
309311 # Split the shuffled list into committees_per_slot pieces
310312 shard_indices = split (slot_indices , committees_per_slot )
311313 start_shard = crosslinking_start_shard + index * committees_per_slot
312- yield _get_shards_and_committees_for_shard_indices (
314+ yield _get_shards_committees_for_shard_indices (
313315 shard_indices ,
314316 start_shard ,
317+ active_validators_size ,
315318 shard_count ,
316319 )
317320
@@ -321,24 +324,24 @@ def get_new_shuffling(*,
321324#
322325def get_block_committees_info (parent_block : 'BaseBeaconBlock' ,
323326 crystallized_state : 'CrystallizedState' ,
324- cycle_length : int ) -> BlockCommitteesInfo :
325- shards_and_committees = get_shards_and_committees_for_slot (
327+ epoch_length : int ) -> BlockCommitteesInfo :
328+ shards_committees = get_shards_committees_for_slot (
326329 crystallized_state ,
327330 parent_block .slot_number ,
328- cycle_length ,
331+ epoch_length ,
329332 )
330333 """
331334 FIXME
332335 Return the block committees and proposer info with BlockCommitteesInfo pack.
333336 """
334- # `proposer_index_in_committee` th attester in `shard_and_committee `
337+ # `proposer_index_in_committee` th attester in `shard_committee `
335338 # is the proposer of the parent block.
336339 try :
337- shard_and_committee = shards_and_committees [0 ]
340+ shard_committee = shards_committees [0 ]
338341 except IndexError :
339- raise ValueError ("shards_and_committees should not be empty." )
342+ raise ValueError ("shards_committees should not be empty." )
340343
341- proposer_committee_size = len (shard_and_committee .committee )
344+ proposer_committee_size = len (shard_committee .committee )
342345 if proposer_committee_size <= 0 :
343346 raise ValueError (
344347 "The first committee should not be empty"
@@ -350,12 +353,12 @@ def get_block_committees_info(parent_block: 'BaseBeaconBlock',
350353 )
351354
352355 # The index in CrystallizedState.validators
353- proposer_index = shard_and_committee .committee [proposer_index_in_committee ]
356+ proposer_index = shard_committee .committee [proposer_index_in_committee ]
354357
355358 return BlockCommitteesInfo (
356359 proposer_index = proposer_index ,
357360 proposer_index_in_committee = proposer_index_in_committee ,
358- proposer_shard_id = shard_and_committee .shard_id ,
361+ proposer_shard_id = shard_committee .shard_id ,
359362 proposer_committee_size = proposer_committee_size ,
360- shards_and_committees = shards_and_committees ,
363+ shards_committees = shards_committees ,
361364 )
0 commit comments