Slice notation for justification_bitfield shift

This commit is contained in:
Dankrad Feist 2019-06-28 00:18:54 +01:00
parent 7adf07ea5f
commit 237b41df5b
No known key found for this signature in database
GPG Key ID: 6815E6A20BEBBABA
2 changed files with 15 additions and 8 deletions

View File

@ -1292,8 +1292,9 @@ def process_justification_and_finalization(state: BeaconState) -> None:
# Process justifications
state.previous_justified_epoch = state.current_justified_epoch
state.previous_justified_root = state.current_justified_root
state.justification_bitfield = Bitvector[JUSTIFICATION_BITVECTOR_LENGTH](
*([0b0] + state.justification_bitfield[0:JUSTIFICATION_BITVECTOR_LENGTH - 1]))
state.justification_bitfield[1:JUSTIFICATION_BITVECTOR_LENGTH] = \
state.justification_bitfield[0:JUSTIFICATION_BITVECTOR_LENGTH - 1]
state.justification_bitfield[0] = 0b0
previous_epoch_matching_target_balance = get_attesting_balance(
state, get_matching_target_attestations(state, previous_epoch)
)

View File

@ -324,6 +324,12 @@ class BaseList(list, Elements):
return super().__getitem__(k)
def __setitem__(self, k, v):
if type(k) == slice:
if k.start < 0 or k.stop > len(self):
raise IndexError(f"cannot set item in type {self.__class__}"
f" at out of bounds slice {k} (to {v}, bound: {len(self)})")
super().__setitem__(k, [coerce_type_maybe(x, self.__class__.elem_type) for x in v])
else:
if k < 0:
raise IndexError(f"cannot set item in type {self.__class__} at negative index {k} (to {v})")
if k > len(self):