Add surround/dbl vote fns to SlashableAttestation
Copied from `SlashableVoteData`
This commit is contained in:
parent
c885e36a93
commit
f3a3cfcc45
@ -1,4 +1,4 @@
|
|||||||
use crate::{test_utils::TestRandom, SlashableAttestation};
|
use crate::{test_utils::TestRandom, ChainSpec, SlashableAttestation};
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
use serde_derive::Serialize;
|
use serde_derive::Serialize;
|
||||||
use ssz_derive::{Decode, Encode, TreeHash};
|
use ssz_derive::{Decode, Encode, TreeHash};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::{test_utils::TestRandom, AggregateSignature, AttestationData, Bitfield};
|
use crate::{test_utils::TestRandom, AggregateSignature, AttestationData, Bitfield, ChainSpec};
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
use serde_derive::Serialize;
|
use serde_derive::Serialize;
|
||||||
use ssz_derive::{Decode, Encode, TreeHash};
|
use ssz_derive::{Decode, Encode, TreeHash};
|
||||||
@ -12,6 +12,27 @@ pub struct SlashableAttestation {
|
|||||||
pub aggregate_signature: AggregateSignature,
|
pub aggregate_signature: AggregateSignature,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SlashableAttestation {
|
||||||
|
/// Check if ``attestation_data_1`` and ``attestation_data_2`` have the same target.
|
||||||
|
///
|
||||||
|
/// Spec v0.3.0
|
||||||
|
pub fn is_double_vote(&self, other: &SlashableAttestation, spec: &ChainSpec) -> bool {
|
||||||
|
self.data.slot.epoch(spec.epoch_length) == other.data.slot.epoch(spec.epoch_length)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if ``attestation_data_1`` surrounds ``attestation_data_2``.
|
||||||
|
///
|
||||||
|
/// Spec v0.3.0
|
||||||
|
pub fn is_surround_vote(&self, other: &SlashableAttestation, spec: &ChainSpec) -> bool {
|
||||||
|
let source_epoch_1 = self.data.justified_epoch;
|
||||||
|
let source_epoch_2 = other.data.justified_epoch;
|
||||||
|
let target_epoch_1 = self.data.slot.epoch(spec.epoch_length);
|
||||||
|
let target_epoch_2 = other.data.slot.epoch(spec.epoch_length);
|
||||||
|
|
||||||
|
(source_epoch_1 < source_epoch_2) && (target_epoch_2 < target_epoch_1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
Loading…
Reference in New Issue
Block a user