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
use consensus_types::{common::Round, safety_data::SafetyData};
use diem_types::waypoint::Waypoint;
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct ConsensusState {
safety_data: SafetyData,
waypoint: Waypoint,
in_validator_set: bool,
}
impl Display for ConsensusState {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(
f,
"ConsensusState: [\n\
\tepoch = {},
\tlast_voted_round = {},\n\
\tpreferred_round = {}\n\
\twaypoint = {}\n\
\tin_validator_set = {}\n\
]",
self.epoch(),
self.last_voted_round(),
self.preferred_round(),
self.waypoint,
self.in_validator_set,
)
}
}
impl ConsensusState {
pub fn new(safety_data: SafetyData, waypoint: Waypoint, in_validator_set: bool) -> Self {
Self {
safety_data,
waypoint,
in_validator_set,
}
}
pub fn epoch(&self) -> u64 {
self.safety_data.epoch
}
pub fn last_voted_round(&self) -> Round {
self.safety_data.last_voted_round
}
pub fn preferred_round(&self) -> Round {
self.safety_data.preferred_round
}
pub fn one_chain_round(&self) -> Round {
self.safety_data.one_chain_round
}
pub fn waypoint(&self) -> Waypoint {
self.waypoint
}
pub fn in_validator_set(&self) -> bool {
self.in_validator_set
}
pub fn safety_data(&mut self) -> SafetyData {
self.safety_data.clone()
}
}