fix slashing conditons to be based upon epochs rather than slots

This commit is contained in:
Danny Ryan 2018-12-28 11:10:12 -06:00
parent 6b84dae09e
commit aa9bda271f
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
1 changed files with 10 additions and 4 deletions

View File

@ -1080,7 +1080,9 @@ def is_double_vote(attestation_data_1: AttestationData,
Returns True if the provided ``AttestationData`` are slashable
due to a 'double vote'.
"""
return attestation_data_1.slot == attestation_data_2.slot
target_epoch_1 = attestation_data_1.slot // EPOCH_LENGTH
target_epoch_2 = attestation_data_2.slot // EPOCH_LENGTH
return target_epoch_1 == target_epoch_2
```
#### `is_surround_vote`
@ -1095,10 +1097,14 @@ def is_surround_vote(attestation_data_1: AttestationData,
Note: parameter order matters as this function only checks
that ``attestation_data_1`` surrounds ``attestation_data_2``.
"""
source_epoch_1 = attestation_data_1.justified_slot // EPOCH_LENGTH
source_epoch_2 = attestation_data_2.justified_slot // EPOCH_LENGTH
target_epoch_1 = attestation_data_1.slot // EPOCH_LENGTH
target_epoch_2 = attestation_data_2.slot // EPOCH_LENGTH
return (
(attestation_data_1.justified_slot < attestation_data_2.justified_slot) and
(attestation_data_2.justified_slot + 1 == attestation_data_2.slot) and
(attestation_data_2.slot < attestation_data_1.slot)
(source_epoch_1 < source_epoch_2) and
(source_epoch_2 + 1 == target_epoch_2) and
(target_epoch_2 < target_epoch_1)
)
```