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
use crate::{sync_info::SyncInfo, vote::Vote};
use anyhow::ensure;
use diem_crypto::HashValue;
use diem_types::validator_verifier::ValidatorVerifier;
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
pub struct VoteMsg {
vote: Vote,
sync_info: SyncInfo,
}
impl Display for VoteMsg {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "VoteMsg: [{}]", self.vote,)
}
}
impl VoteMsg {
pub fn new(vote: Vote, sync_info: SyncInfo) -> Self {
Self { vote, sync_info }
}
pub fn vote(&self) -> &Vote {
&self.vote
}
pub fn sync_info(&self) -> &SyncInfo {
&self.sync_info
}
pub fn epoch(&self) -> u64 {
self.vote.epoch()
}
pub fn proposed_block_id(&self) -> HashValue {
self.vote.vote_data().proposed().id()
}
pub fn verify(&self, validator: &ValidatorVerifier) -> anyhow::Result<()> {
ensure!(
self.vote().epoch() == self.sync_info.epoch(),
"VoteMsg has different epoch"
);
if let Some((timeout, _)) = self.vote().two_chain_timeout() {
ensure!(
timeout.hqc_round() <= self.sync_info.highest_certified_round(),
"2-chain Timeout hqc should be less or equal than the sync info hqc"
);
}
self.vote().verify(validator)
}
}