26
26
from eth .beacon .enums .validator_status_codes import (
27
27
ValidatorStatusCode ,
28
28
)
29
- from eth .beacon .types .shard_and_committees import (
30
- ShardAndCommittee ,
29
+ from eth .beacon .types .shard_committees import (
30
+ ShardCommittee ,
31
31
)
32
32
from eth .beacon .utils .random import (
33
33
shuffle ,
@@ -77,20 +77,20 @@ def get_block_hash(
77
77
recent_block_hashes : Sequence [Hash32 ],
78
78
current_block_slot_number : int ,
79
79
slot : int ,
80
- cycle_length : int ) -> Hash32 :
80
+ epoch_length : int ) -> Hash32 :
81
81
"""
82
82
Return the blockhash from ``ActiveState.recent_block_hashes`` by
83
83
``current_block_slot_number``.
84
84
"""
85
- if len (recent_block_hashes ) != cycle_length * 2 :
85
+ if len (recent_block_hashes ) != epoch_length * 2 :
86
86
raise ValueError (
87
- "Length of recent_block_hashes != cycle_length * 2"
87
+ "Length of recent_block_hashes != epoch_length * 2"
88
88
"\t expected: %s, found: %s" % (
89
- cycle_length * 2 , len (recent_block_hashes )
89
+ epoch_length * 2 , len (recent_block_hashes )
90
90
)
91
91
)
92
92
93
- slot_relative_position = current_block_slot_number - cycle_length * 2
93
+ slot_relative_position = current_block_slot_number - epoch_length * 2
94
94
return _get_element_from_recent_list (
95
95
recent_block_hashes ,
96
96
slot ,
@@ -104,7 +104,7 @@ def get_hashes_from_recent_block_hashes(
104
104
current_block_slot_number : int ,
105
105
from_slot : int ,
106
106
to_slot : int ,
107
- cycle_length : int ) -> Iterable [Hash32 ]:
107
+ epoch_length : int ) -> Iterable [Hash32 ]:
108
108
"""
109
109
Returns the block hashes between ``from_slot`` and ``to_slot``.
110
110
"""
@@ -113,24 +113,24 @@ def get_hashes_from_recent_block_hashes(
113
113
recent_block_hashes ,
114
114
current_block_slot_number ,
115
115
slot ,
116
- cycle_length ,
116
+ epoch_length ,
117
117
)
118
118
119
119
120
120
@to_tuple
121
121
def get_hashes_to_sign (recent_block_hashes : Sequence [Hash32 ],
122
122
block : 'BaseBeaconBlock' ,
123
- cycle_length : int ) -> Iterable [Hash32 ]:
123
+ epoch_length : int ) -> Iterable [Hash32 ]:
124
124
"""
125
125
Given the head block to attest to, collect the list of hashes to be
126
126
signed in the attestation.
127
127
"""
128
128
yield from get_hashes_from_recent_block_hashes (
129
129
recent_block_hashes ,
130
130
block .slot_number ,
131
- from_slot = block .slot_number - cycle_length + 1 ,
131
+ from_slot = block .slot_number - epoch_length + 1 ,
132
132
to_slot = block .slot_number - 1 ,
133
- cycle_length = cycle_length ,
133
+ epoch_length = epoch_length ,
134
134
)
135
135
yield block .hash
136
136
@@ -139,17 +139,17 @@ def get_hashes_to_sign(recent_block_hashes: Sequence[Hash32],
139
139
def get_signed_parent_hashes (recent_block_hashes : Sequence [Hash32 ],
140
140
block : 'BaseBeaconBlock' ,
141
141
attestation : 'AttestationRecord' ,
142
- cycle_length : int ) -> Iterable [Hash32 ]:
142
+ epoch_length : int ) -> Iterable [Hash32 ]:
143
143
"""
144
144
Given an attestation and the block they were included in,
145
145
the list of hashes that were included in the signature.
146
146
"""
147
147
yield from get_hashes_from_recent_block_hashes (
148
148
recent_block_hashes ,
149
149
block .slot_number ,
150
- from_slot = attestation .slot - cycle_length + 1 ,
150
+ from_slot = attestation .slot - epoch_length + 1 ,
151
151
to_slot = attestation .slot - len (attestation .oblique_parent_hashes ),
152
- cycle_length = cycle_length ,
152
+ epoch_length = epoch_length ,
153
153
)
154
154
yield from attestation .oblique_parent_hashes
155
155
@@ -167,28 +167,28 @@ def get_new_recent_block_hashes(old_block_hashes: Sequence[Hash32],
167
167
168
168
169
169
#
170
- # Get shards_and_committees or indices
170
+ # Get shards_committees or indices
171
171
#
172
172
@to_tuple
173
- def get_shards_and_committees_for_slot (
173
+ def get_shards_committees_for_slot (
174
174
crystallized_state : 'CrystallizedState' ,
175
175
slot : int ,
176
- cycle_length : int ) -> Iterable [ShardAndCommittee ]:
176
+ epoch_length : int ) -> Iterable [ShardCommittee ]:
177
177
"""
178
178
FIXME
179
179
"""
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 :
181
181
raise ValueError (
182
- "Length of shard_and_committee_for_slots != cycle_length * 2"
182
+ "Length of shard_committee_for_slots != epoch_length * 2"
183
183
"\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 )
185
185
)
186
186
)
187
187
188
- slot_relative_position = crystallized_state .last_state_recalc - cycle_length
188
+ slot_relative_position = crystallized_state .last_state_recalc - epoch_length
189
189
190
190
yield from _get_element_from_recent_list (
191
- crystallized_state .shard_and_committee_for_slots ,
191
+ crystallized_state .shard_committee_for_slots ,
192
192
slot ,
193
193
slot_relative_position ,
194
194
)
@@ -197,22 +197,22 @@ def get_shards_and_committees_for_slot(
197
197
@to_tuple
198
198
def get_attestation_indices (crystallized_state : 'CrystallizedState' ,
199
199
attestation : 'AttestationRecord' ,
200
- cycle_length : int ) -> Iterable [int ]:
200
+ epoch_length : int ) -> Iterable [int ]:
201
201
"""
202
202
FIXME
203
203
Return committee of the given attestation.
204
204
"""
205
205
shard_id = attestation .shard_id
206
206
207
- shards_and_committees_for_slot = get_shards_and_committees_for_slot (
207
+ shards_committees_for_slot = get_shards_committees_for_slot (
208
208
crystallized_state ,
209
209
attestation .slot ,
210
- cycle_length ,
210
+ epoch_length ,
211
211
)
212
212
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
216
216
217
217
218
218
def get_active_validator_indices (validators : Sequence ['ValidatorRecord' ]) -> Tuple [int , ...]:
@@ -229,17 +229,19 @@ def get_active_validator_indices(validators: Sequence['ValidatorRecord']) -> Tup
229
229
# Shuffling
230
230
#
231
231
@to_tuple
232
- def _get_shards_and_committees_for_shard_indices (
232
+ def _get_shards_committees_for_shard_indices (
233
233
shard_indices : Sequence [Sequence [int ]],
234
234
start_shard : int ,
235
- shard_count : int ) -> Iterable [ShardAndCommittee ]:
235
+ total_validator_count : int ,
236
+ shard_count : int ) -> Iterable [ShardCommittee ]:
236
237
"""
237
- Returns filled [ShardAndCommittee ] tuple.
238
+ Returns filled [ShardCommittee ] tuple.
238
239
"""
239
240
for index , indices in enumerate (shard_indices ):
240
- yield ShardAndCommittee (
241
+ yield ShardCommittee (
241
242
shard = (start_shard + index ) % shard_count ,
242
- committee = indices
243
+ committee = indices ,
244
+ total_validator_count = total_validator_count ,
243
245
)
244
246
245
247
@@ -248,18 +250,18 @@ def get_new_shuffling(*,
248
250
seed : Hash32 ,
249
251
validators : Sequence ['ValidatorRecord' ],
250
252
crosslinking_start_shard : int ,
251
- cycle_length : int ,
253
+ epoch_length : int ,
252
254
target_committee_size : int ,
253
- shard_count : int ) -> Iterable [Iterable [ShardAndCommittee ]]:
255
+ shard_count : int ) -> Iterable [Iterable [ShardCommittee ]]:
254
256
"""
255
- Return shuffled ``shard_and_committee_for_slots `` (``[[ShardAndCommittee ]]``) of
257
+ Return shuffled ``shard_committee_for_slots `` (``[[ShardCommittee ]]``) of
256
258
the given active ``validators`` using ``seed`` as entropy.
257
259
258
260
Two-dimensional:
259
261
The first layer is ``slot`` number
260
- ``shard_and_committee_for_slots [slot] -> [ShardAndCommittee ]``
262
+ ``shard_committee_for_slots [slot] -> [ShardCommittee ]``
261
263
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 ``
263
265
264
266
Example:
265
267
validators:
@@ -278,40 +280,41 @@ def get_new_shuffling(*,
278
280
[
279
281
# slot 0
280
282
[
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]),
283
285
],
284
286
# slot 1
285
287
[
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]),
288
290
],
289
291
# slot 2
290
292
[
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]),
293
295
],
294
296
]
295
297
"""
296
298
active_validators = get_active_validator_indices (validators )
297
299
active_validators_size = len (active_validators )
298
300
committees_per_slot = clamp (
299
301
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 ,
302
304
)
303
305
# Shuffle with seed
304
306
shuffled_active_validator_indices = shuffle (active_validators , seed )
305
307
306
308
# 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 )
308
310
for index , slot_indices in enumerate (validators_per_slot ):
309
311
# Split the shuffled list into committees_per_slot pieces
310
312
shard_indices = split (slot_indices , committees_per_slot )
311
313
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 (
313
315
shard_indices ,
314
316
start_shard ,
317
+ active_validators_size ,
315
318
shard_count ,
316
319
)
317
320
@@ -321,24 +324,24 @@ def get_new_shuffling(*,
321
324
#
322
325
def get_block_committees_info (parent_block : 'BaseBeaconBlock' ,
323
326
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 (
326
329
crystallized_state ,
327
330
parent_block .slot_number ,
328
- cycle_length ,
331
+ epoch_length ,
329
332
)
330
333
"""
331
334
FIXME
332
335
Return the block committees and proposer info with BlockCommitteesInfo pack.
333
336
"""
334
- # `proposer_index_in_committee` th attester in `shard_and_committee `
337
+ # `proposer_index_in_committee` th attester in `shard_committee `
335
338
# is the proposer of the parent block.
336
339
try :
337
- shard_and_committee = shards_and_committees [0 ]
340
+ shard_committee = shards_committees [0 ]
338
341
except IndexError :
339
- raise ValueError ("shards_and_committees should not be empty." )
342
+ raise ValueError ("shards_committees should not be empty." )
340
343
341
- proposer_committee_size = len (shard_and_committee .committee )
344
+ proposer_committee_size = len (shard_committee .committee )
342
345
if proposer_committee_size <= 0 :
343
346
raise ValueError (
344
347
"The first committee should not be empty"
@@ -350,12 +353,12 @@ def get_block_committees_info(parent_block: 'BaseBeaconBlock',
350
353
)
351
354
352
355
# 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 ]
354
357
355
358
return BlockCommitteesInfo (
356
359
proposer_index = proposer_index ,
357
360
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 ,
359
362
proposer_committee_size = proposer_committee_size ,
360
- shards_and_committees = shards_and_committees ,
363
+ shards_committees = shards_committees ,
361
364
)
0 commit comments