1
- from itertools import (
2
- repeat ,
3
- )
4
-
5
1
from typing import (
6
2
Any ,
7
3
Iterable ,
12
8
13
9
from eth_utils import (
14
10
to_tuple ,
11
+ ValidationError ,
15
12
)
16
13
17
14
from eth_typing import (
@@ -80,21 +77,12 @@ def _get_element_from_recent_list(
80
77
#
81
78
def get_block_hash (
82
79
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 :
86
82
"""
87
83
Returns the block hash at a recent ``slot``.
88
84
"""
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 )
98
86
return _get_element_from_recent_list (
99
87
latest_block_hashes ,
100
88
slot ,
@@ -105,52 +93,20 @@ def get_block_hash(
105
93
@to_tuple
106
94
def get_hashes_from_latest_block_hashes (
107
95
latest_block_hashes : Sequence [Hash32 ],
108
- current_block_slot : int ,
96
+ current_slot : int ,
109
97
from_slot : int ,
110
- to_slot : int ,
111
- epoch_length : int ) -> Iterable [Hash32 ]:
98
+ to_slot : int ) -> Iterable [Hash32 ]:
112
99
"""
113
100
Returns the block hashes between ``from_slot`` and ``to_slot``.
114
101
"""
115
102
for slot in range (from_slot , to_slot + 1 ):
116
103
yield get_block_hash (
117
104
latest_block_hashes ,
118
- current_block_slot ,
105
+ current_slot ,
119
106
slot ,
120
- epoch_length ,
121
107
)
122
108
123
109
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
-
154
110
#
155
111
# Get shards_committees or indices
156
112
#
@@ -314,11 +270,11 @@ def get_block_committees_info(parent_block: 'BaseBeaconBlock',
314
270
try :
315
271
shard_committee = shards_committees [0 ]
316
272
except IndexError :
317
- raise ValueError ("shards_committees should not be empty." )
273
+ raise ValidationError ("shards_committees should not be empty." )
318
274
319
275
proposer_committee_size = len (shard_committee .committee )
320
276
if proposer_committee_size <= 0 :
321
- raise ValueError (
277
+ raise ValidationError (
322
278
"The first committee should not be empty"
323
279
)
324
280
@@ -351,12 +307,12 @@ def get_beacon_proposer_index(state: 'BeaconState',
351
307
try :
352
308
first_shard_committee = shard_committees [0 ]
353
309
except IndexError :
354
- raise ValueError ("shard_committees should not be empty." )
310
+ raise ValidationError ("shard_committees should not be empty." )
355
311
356
312
proposer_committee_size = len (first_shard_committee .committee )
357
313
358
314
if proposer_committee_size <= 0 :
359
- raise ValueError (
315
+ raise ValidationError (
360
316
"The first committee should not be empty"
361
317
)
362
318
@@ -395,10 +351,10 @@ def get_attestation_participants(state: 'BeaconState',
395
351
try :
396
352
shard_committee = shard_committees [0 ]
397
353
except IndexError :
398
- raise ValueError ("shard_committees should not be empty." )
354
+ raise ValidationError ("shard_committees should not be empty." )
399
355
400
356
if len (participation_bitfield ) != get_bitfield_length (len (shard_committee .committee )):
401
- raise ValueError (
357
+ raise ValidationError (
402
358
'Invalid bitfield length,'
403
359
"\t expected: %s, found: %s" % (
404
360
get_bitfield_length (len (shard_committee .committee )),
0 commit comments