Update replace_empty_or_append

Requires adding definitions of `empty` and `typeof` to the function puller.
This commit is contained in:
vbuterin 2019-04-09 05:59:00 -05:00 committed by GitHub
parent 3fc24f3d41
commit 9dde3a2661
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 12 deletions

View File

@ -233,9 +233,9 @@ def epoch_to_custody_period(epoch: Epoch) -> int:
### `replace_empty_or_append`
```python
def replace_empty_or_append(list: List[Any], empty_element: Any, new_element: Any) -> int:
def replace_empty_or_append(list: List[Any], new_element: Any) -> int:
for i in range(len(list)):
if list[i] == empty_element:
if list[i] == empty(typeof(new_element)):
list[i] = new_element
return i
list.append(new_element)
@ -343,11 +343,7 @@ def process_chunk_challenge(state: BeaconState,
depth=depth,
chunk_index=challenge.chunk_index,
)
replace_empty_or_append(
list=state.custody_chunk_challenge_records,
empty_element=CustodyChunkChallengeRecord(),
new_element=new_record
)
replace_empty_or_append(state.custody_chunk_challenge_records, new_record)
state.custody_challenge_index += 1
# Postpone responder withdrawability
@ -413,11 +409,7 @@ def process_bit_challenge(state: BeaconState,
chunk_bits=challenge.chunk_bits,
responder_key=challenge.responder_key,
)
replace_empty_or_append(
list=state.custody_bit_challenge_records,
empty_element=CustodyBitChallengeRecord(),
new_element=new_record
)
replace_empty_or_append(state.custody_bit_challenge_records, new_record)
state.custody_challenge_index += 1
# Postpone responder withdrawability
responder.withdrawable_epoch = FAR_FUTURE_EPOCH