consensus_types/
timeout.rs1use crate::common::Round;
9use diem_crypto_derive::{BCSCryptoHash, CryptoHasher};
10use diem_types::{
11 validator_config::ConsensusSignature, validator_signer::ValidatorSigner,
12};
13use serde::{Deserialize, Serialize};
14use std::fmt::{Display, Formatter};
15
16#[derive(
19 Clone,
20 Debug,
21 Deserialize,
22 Eq,
23 PartialEq,
24 Serialize,
25 CryptoHasher,
26 BCSCryptoHash,
27)]
28pub struct Timeout {
29 epoch: u64,
32 round: Round,
35}
36
37impl Timeout {
38 pub fn new(epoch: u64, round: Round) -> Self { Self { epoch, round } }
39
40 pub fn epoch(&self) -> u64 { self.epoch }
41
42 pub fn round(&self) -> Round { self.round }
43
44 pub fn sign(&self, signer: &ValidatorSigner) -> ConsensusSignature {
45 signer.sign(self)
46 }
47}
48
49impl Display for Timeout {
50 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
51 write!(f, "Timeout: [epoch: {}, round: {}]", self.epoch, self.round,)
52 }
53}