1- from itertools import (
2- repeat ,
3- )
4-
51from typing import (
62 Any ,
73 Iterable ,
128
139from eth_utils import (
1410 to_tuple ,
11+ ValidationError ,
1512)
1613
1714from eth_typing import (
@@ -80,21 +77,12 @@ def _get_element_from_recent_list(
8077#
8178def get_block_hash (
8279 latest_block_hashes : Sequence [Hash32 ],
83- current_block_slot : int ,
84- slot : int ,
85- epoch_length : int ) -> Hash32 :
80+ current_slot : int ,
81+ slot : int ) -> Hash32 :
8682 """
8783 Returns the block hash at a recent ``slot``.
8884 """
89- if len (latest_block_hashes ) != epoch_length * 2 :
90- raise ValueError (
91- "Length of latest_block_hashes != epoch_length * 2"
92- "\t expected: %s, found: %s" % (
93- epoch_length * 2 , len (latest_block_hashes )
94- )
95- )
96-
97- slot_relative_position = current_block_slot - epoch_length * 2
85+ slot_relative_position = current_slot - len (latest_block_hashes )
9886 return _get_element_from_recent_list (
9987 latest_block_hashes ,
10088 slot ,
@@ -105,52 +93,20 @@ def get_block_hash(
10593@to_tuple
10694def get_hashes_from_latest_block_hashes (
10795 latest_block_hashes : Sequence [Hash32 ],
108- current_block_slot : int ,
96+ current_slot : int ,
10997 from_slot : int ,
110- to_slot : int ,
111- epoch_length : int ) -> Iterable [Hash32 ]:
98+ to_slot : int ) -> Iterable [Hash32 ]:
11299 """
113100 Returns the block hashes between ``from_slot`` and ``to_slot``.
114101 """
115102 for slot in range (from_slot , to_slot + 1 ):
116103 yield get_block_hash (
117104 latest_block_hashes ,
118- current_block_slot ,
105+ current_slot ,
119106 slot ,
120- epoch_length ,
121107 )
122108
123109
124- @to_tuple
125- def get_hashes_to_sign (latest_block_hashes : Sequence [Hash32 ],
126- block : 'BaseBeaconBlock' ,
127- epoch_length : int ) -> Iterable [Hash32 ]:
128- """
129- Given the head block to attest to, collect the list of hashes to be
130- signed in the attestation.
131- """
132- yield from get_hashes_from_latest_block_hashes (
133- latest_block_hashes ,
134- block .slot ,
135- from_slot = block .slot - epoch_length + 1 ,
136- to_slot = block .slot - 1 ,
137- epoch_length = epoch_length ,
138- )
139- yield block .hash
140-
141-
142- @to_tuple
143- def get_new_latest_block_hashes (old_block_hashes : Sequence [Hash32 ],
144- parent_slot : int ,
145- current_slot : int ,
146- parent_hash : Hash32 ) -> Iterable [Hash32 ]:
147-
148- shift_size = current_slot - parent_slot
149- parent_hash_repeat = min (shift_size , len (old_block_hashes ))
150- yield from old_block_hashes [shift_size :]
151- yield from repeat (parent_hash , parent_hash_repeat )
152-
153-
154110#
155111# Get shards_committees or indices
156112#
@@ -314,11 +270,11 @@ def get_block_committees_info(parent_block: 'BaseBeaconBlock',
314270 try :
315271 shard_committee = shards_committees [0 ]
316272 except IndexError :
317- raise ValueError ("shards_committees should not be empty." )
273+ raise ValidationError ("shards_committees should not be empty." )
318274
319275 proposer_committee_size = len (shard_committee .committee )
320276 if proposer_committee_size <= 0 :
321- raise ValueError (
277+ raise ValidationError (
322278 "The first committee should not be empty"
323279 )
324280
@@ -351,12 +307,12 @@ def get_beacon_proposer_index(state: 'BeaconState',
351307 try :
352308 first_shard_committee = shard_committees [0 ]
353309 except IndexError :
354- raise ValueError ("shard_committees should not be empty." )
310+ raise ValidationError ("shard_committees should not be empty." )
355311
356312 proposer_committee_size = len (first_shard_committee .committee )
357313
358314 if proposer_committee_size <= 0 :
359- raise ValueError (
315+ raise ValidationError (
360316 "The first committee should not be empty"
361317 )
362318
@@ -395,10 +351,10 @@ def get_attestation_participants(state: 'BeaconState',
395351 try :
396352 shard_committee = shard_committees [0 ]
397353 except IndexError :
398- raise ValueError ("shard_committees should not be empty." )
354+ raise ValidationError ("shard_committees should not be empty." )
399355
400356 if len (participation_bitfield ) != get_bitfield_length (len (shard_committee .committee )):
401- raise ValueError (
357+ raise ValidationError (
402358 'Invalid bitfield length,'
403359 "\t expected: %s, found: %s" % (
404360 get_bitfield_length (len (shard_committee .committee )),
0 commit comments