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