Update 0_beacon-chain.md
This commit is contained in:
parent
dc4b652f72
commit
2b454d57f1
|
@ -59,6 +59,7 @@
|
||||||
- [`get_current_epoch`](#get_current_epoch)
|
- [`get_current_epoch`](#get_current_epoch)
|
||||||
- [`get_epoch_start_slot`](#get_epoch_start_slot)
|
- [`get_epoch_start_slot`](#get_epoch_start_slot)
|
||||||
- [`is_active_validator`](#is_active_validator)
|
- [`is_active_validator`](#is_active_validator)
|
||||||
|
- [`is_slashable_validator`](#is_slashable_validator)
|
||||||
- [`get_active_validator_indices`](#get_active_validator_indices)
|
- [`get_active_validator_indices`](#get_active_validator_indices)
|
||||||
- [`get_permuted_index`](#get_permuted_index)
|
- [`get_permuted_index`](#get_permuted_index)
|
||||||
- [`split`](#split)
|
- [`split`](#split)
|
||||||
|
@ -737,6 +738,18 @@ def is_active_validator(validator: Validator, epoch: Epoch) -> bool:
|
||||||
return validator.activation_epoch <= epoch < validator.exit_epoch
|
return validator.activation_epoch <= epoch < validator.exit_epoch
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `is_slashable_validator`
|
||||||
|
```python
|
||||||
|
def is_slashable_validator(validator: Validator, epoch: Epoch) -> bool:
|
||||||
|
"""
|
||||||
|
Check if ``validator`` is slashable.
|
||||||
|
"""
|
||||||
|
return (
|
||||||
|
validator.activation_epoch <= epoch < validator.withdrawable_epoch and
|
||||||
|
validator.slashed is False
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
### `get_active_validator_indices`
|
### `get_active_validator_indices`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
@ -2315,8 +2328,8 @@ def process_proposer_slashing(state: BeaconState,
|
||||||
assert slot_to_epoch(proposer_slashing.header_1.slot) == slot_to_epoch(proposer_slashing.header_2.slot)
|
assert slot_to_epoch(proposer_slashing.header_1.slot) == slot_to_epoch(proposer_slashing.header_2.slot)
|
||||||
# But the headers are different
|
# But the headers are different
|
||||||
assert proposer_slashing.header_1 != proposer_slashing.header_2
|
assert proposer_slashing.header_1 != proposer_slashing.header_2
|
||||||
# Proposer is active and not already slashed
|
# Check proposer is slashable
|
||||||
assert is_active_validator(proposer) and proposer.slashed is False
|
assert is_slashable_validator(proposer)
|
||||||
# Signatures are valid
|
# Signatures are valid
|
||||||
for header in (proposer_slashing.header_1, proposer_slashing.header_2):
|
for header in (proposer_slashing.header_1, proposer_slashing.header_2):
|
||||||
assert bls_verify(
|
assert bls_verify(
|
||||||
|
@ -2355,8 +2368,7 @@ def process_attester_slashing(state: BeaconState,
|
||||||
index for index in attestation1.validator_indices
|
index for index in attestation1.validator_indices
|
||||||
if (
|
if (
|
||||||
index in attestation2.validator_indices and
|
index in attestation2.validator_indices and
|
||||||
is_active_validator(state.validator_registry[index]) and
|
is_slashable_validator(state.validator_registry[index])
|
||||||
state.validator_registry[index].slashed is False
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
assert len(slashable_indices) >= 1
|
assert len(slashable_indices) >= 1
|
||||||
|
|
Loading…
Reference in New Issue