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
use ethjson;
use util::{U256, Uint};
use time::Duration;
use super::super::transition::Timeouts;
use super::Step;
#[derive(Debug)]
pub struct TendermintParams {
pub gas_limit_bound_divisor: U256,
pub validators: ethjson::spec::ValidatorSet,
pub timeouts: TendermintTimeouts,
pub block_reward: U256,
}
#[derive(Debug, Clone)]
pub struct TendermintTimeouts {
pub propose: Duration,
pub prevote: Duration,
pub precommit: Duration,
pub commit: Duration,
}
impl Default for TendermintTimeouts {
fn default() -> Self {
TendermintTimeouts {
propose: Duration::milliseconds(1000),
prevote: Duration::milliseconds(1000),
precommit: Duration::milliseconds(1000),
commit: Duration::milliseconds(1000),
}
}
}
impl Timeouts<Step> for TendermintTimeouts {
fn initial(&self) -> Duration {
self.propose
}
fn timeout(&self, step: &Step) -> Duration {
match *step {
Step::Propose => self.propose,
Step::Prevote => self.prevote,
Step::Precommit => self.precommit,
Step::Commit => self.commit,
}
}
}
fn to_duration(ms: ethjson::uint::Uint) -> Duration {
let ms: usize = ms.into();
Duration::milliseconds(ms as i64)
}
impl From<ethjson::spec::TendermintParams> for TendermintParams {
fn from(p: ethjson::spec::TendermintParams) -> Self {
let dt = TendermintTimeouts::default();
TendermintParams {
gas_limit_bound_divisor: p.gas_limit_bound_divisor.into(),
validators: p.validators,
timeouts: TendermintTimeouts {
propose: p.timeout_propose.map_or(dt.propose, to_duration),
prevote: p.timeout_prevote.map_or(dt.prevote, to_duration),
precommit: p.timeout_precommit.map_or(dt.precommit, to_duration),
commit: p.timeout_commit.map_or(dt.commit, to_duration),
},
block_reward: p.block_reward.map_or_else(U256::zero, Into::into),
}
}
}