17
17
Hash32 ,
18
18
)
19
19
20
- from eth .utils .blake import (
21
- blake ,
22
- )
20
+ from eth .beacon .block_committees_info import BlockCommitteesInfo
23
21
from eth .beacon .types .shard_and_committees import (
24
22
ShardAndCommittee ,
25
23
)
@@ -125,7 +123,7 @@ def get_hashes_to_sign(recent_block_hashes: Sequence[Hash32],
125
123
to_slot = block .slot_number - 1 ,
126
124
cycle_length = cycle_length ,
127
125
)
128
- yield blake ( block .hash )
126
+ yield block .hash
129
127
130
128
131
129
@to_tuple
@@ -222,6 +220,18 @@ def get_active_validator_indices(dynasty: int,
222
220
#
223
221
# Shuffling
224
222
#
223
+ def clamp (minval : int , x : int , maxval : int ) -> int :
224
+ """
225
+ Bound the given ``x`` between ``minval`` and ``maxval``
226
+ """
227
+ if x <= minval :
228
+ return minval
229
+ elif x >= maxval :
230
+ return maxval
231
+ else :
232
+ return x
233
+
234
+
225
235
def _get_shuffling_committee_slot_portions (
226
236
active_validators_size : int ,
227
237
cycle_length : int ,
@@ -321,24 +331,19 @@ def get_new_shuffling(*,
321
331
"""
322
332
active_validators = get_active_validator_indices (dynasty , validators )
323
333
active_validators_size = len (active_validators )
324
-
325
- committees_per_slot , slots_per_committee = _get_shuffling_committee_slot_portions (
326
- active_validators_size ,
327
- cycle_length ,
328
- min_committee_size ,
329
- shard_count ,
334
+ committees_per_slot = clamp (
335
+ 1 ,
336
+ active_validators_size // cycle_length // (min_committee_size * 2 ) + 1 ,
337
+ shard_count // cycle_length
330
338
)
331
-
332
339
shuffled_active_validator_indices = shuffle (active_validators , seed )
333
340
334
341
# Split the shuffled list into cycle_length pieces
335
342
validators_per_slot = split (shuffled_active_validator_indices , cycle_length )
336
- for slot , slot_indices in enumerate (validators_per_slot ):
343
+ for index , slot_indices in enumerate (validators_per_slot ):
337
344
# Split the shuffled list into committees_per_slot pieces
338
345
shard_indices = split (slot_indices , committees_per_slot )
339
- shard_id_start = crosslinking_start_shard + (
340
- slot * committees_per_slot // slots_per_committee
341
- )
346
+ shard_id_start = crosslinking_start_shard + index * committees_per_slot
342
347
yield _get_shards_and_committees_for_shard_indices (
343
348
shard_indices ,
344
349
shard_id_start ,
@@ -349,9 +354,9 @@ def get_new_shuffling(*,
349
354
#
350
355
# Get proposer postition
351
356
#
352
- def get_proposer_position (parent_block : 'BaseBeaconBlock' ,
353
- crystallized_state : 'CrystallizedState' ,
354
- cycle_length : int ) -> Tuple [ int , int ] :
357
+ def get_block_committees_info (parent_block : 'BaseBeaconBlock' ,
358
+ crystallized_state : 'CrystallizedState' ,
359
+ cycle_length : int ) -> BlockCommitteesInfo :
355
360
shards_and_committees = get_shards_and_committees_for_slot (
356
361
crystallized_state ,
357
362
parent_block .slot_number ,
@@ -366,14 +371,24 @@ def get_proposer_position(parent_block: 'BaseBeaconBlock',
366
371
# `proposer_index_in_committee` th attester in `shard_and_committee`
367
372
# is the proposer of the parent block.
368
373
shard_and_committee = shards_and_committees [0 ]
369
- if len (shard_and_committee .committee ) <= 0 :
374
+ proposer_committee_size = len (shard_and_committee .committee )
375
+ if proposer_committee_size <= 0 :
370
376
raise ValueError (
371
377
"The first committee should not be empty"
372
378
)
373
379
374
380
proposer_index_in_committee = (
375
381
parent_block .slot_number %
376
- len ( shard_and_committee . committee )
382
+ proposer_committee_size
377
383
)
378
384
379
- return proposer_index_in_committee , shard_and_committee .shard_id
385
+ # The index in CrystallizedState.validators
386
+ proposer_index = shard_and_committee .committee [proposer_index_in_committee ]
387
+
388
+ return BlockCommitteesInfo (
389
+ proposer_index = proposer_index ,
390
+ proposer_index_in_committee = proposer_index_in_committee ,
391
+ proposer_shard_id = shard_and_committee .shard_id ,
392
+ proposer_committee_size = proposer_committee_size ,
393
+ shards_and_committees = shards_and_committees ,
394
+ )
0 commit comments