1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use ssz_derive::Ssz;
#[cfg(feature = "serde")]
use serde_derive::{Serialize, Deserialize};
#[cfg(feature = "parity-codec")]
use codec::{Encode, Decode};
use crate::primitives::{BitField, H256, Signature};
use crate::Config;
#[derive(Ssz, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(deny_unknown_fields))]
#[cfg_attr(feature = "parity-codec", derive(Encode, Decode))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Crosslink {
pub epoch: u64,
pub crosslink_data_root: H256,
}
#[derive(Ssz, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(deny_unknown_fields))]
#[cfg_attr(feature = "parity-codec", derive(Encode, Decode))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Attestation {
pub aggregation_bitfield: BitField,
pub data: AttestationData,
pub custody_bitfield: BitField,
pub aggregate_signature: Signature,
}
#[derive(Ssz, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(deny_unknown_fields))]
#[cfg_attr(feature = "parity-codec", derive(Encode, Decode))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct PendingAttestation {
pub aggregation_bitfield: BitField,
pub data: AttestationData,
pub custody_bitfield: BitField,
pub inclusion_slot: u64,
}
#[derive(Ssz, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(deny_unknown_fields))]
#[cfg_attr(feature = "parity-codec", derive(Encode, Decode))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct AttestationData {
pub slot: u64,
pub beacon_block_root: H256,
pub source_epoch: u64,
pub source_root: H256,
pub target_root: H256,
pub shard: u64,
pub previous_crosslink: Crosslink,
pub crosslink_data_root: H256,
}
impl AttestationData {
pub fn is_double_vote<C: Config>(&self, other: &AttestationData, config: &C) -> bool {
config.slot_to_epoch(self.slot) == config.slot_to_epoch(other.slot)
}
pub fn is_surround_vote<C: Config>(&self, other: &AttestationData, config: &C) -> bool {
self.source_epoch < other.source_epoch &&
config.slot_to_epoch(other.slot) < config.slot_to_epoch(self.slot)
}
}
#[derive(Ssz, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(deny_unknown_fields))]
#[cfg_attr(feature = "parity-codec", derive(Encode, Decode))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct AttestationDataAndCustodyBit {
pub data: AttestationData,
pub custody_bit: bool,
}