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
124
125
126
127
128
129
use super::Timestamp;
/// Protocol parameters for Highway.
#[derive(Debug, Clone)]
pub(crate) struct Params {
seed: u64,
block_reward: u64,
reduced_block_reward: u64,
min_round_exp: u8,
max_round_exp: u8,
init_round_exp: u8,
end_height: u64,
start_timestamp: Timestamp,
end_timestamp: Timestamp,
endorsement_evidence_limit: u64,
}
impl Params {
/// Creates a new set of Highway protocol parameters.
///
/// Arguments:
///
/// * `seed`: The random seed.
/// * `block_reward`: The total reward that is paid out for a finalized block. Validator rewards
/// for finalization must add up to this number or less. This should be large enough to allow
/// very precise fractions of a block reward while still leaving space for millions of full
/// rewards in a `u64`.
/// * `reduced_block_reward`: The reduced block reward that is paid out even if the heaviest
/// summit does not exceed half the total weight.
/// * `min_round_exp`: The minimum round exponent. `1 << min_round_exp` milliseconds is the
/// minimum round length.
/// * `max_round_exp`: The maximum round exponent. `1 << max_round_exp` milliseconds is the
/// maximum round length.
/// * `end_height`, `end_timestamp`: The last block will be the first one that has at least the
/// specified height _and_ is no earlier than the specified timestamp. No children of this
/// block can be proposed.
#[allow(clippy::too_many_arguments)] // FIXME
pub(crate) fn new(
seed: u64,
block_reward: u64,
reduced_block_reward: u64,
min_round_exp: u8,
max_round_exp: u8,
init_round_exp: u8,
end_height: u64,
start_timestamp: Timestamp,
end_timestamp: Timestamp,
endorsement_evidence_limit: u64,
) -> Params {
assert!(
reduced_block_reward <= block_reward,
"reduced block reward must not be greater than the reward for a finalized block"
);
Params {
seed,
block_reward,
reduced_block_reward,
min_round_exp,
max_round_exp,
init_round_exp,
end_height,
start_timestamp,
end_timestamp,
endorsement_evidence_limit,
}
}
/// Returns the random seed.
pub(crate) fn seed(&self) -> u64 {
self.seed
}
/// Returns the total reward for a finalized block.
pub(crate) fn block_reward(&self) -> u64 {
self.block_reward
}
/// Returns the reduced block reward that is paid out even if the heaviest summit does not
/// exceed half the total weight. This is at most `block_reward`.
pub(crate) fn reduced_block_reward(&self) -> u64 {
self.reduced_block_reward
}
/// Returns the minimum round exponent. `1 << self.min_round_exp()` milliseconds is the minimum
/// round length.
pub(crate) fn min_round_exp(&self) -> u8 {
self.min_round_exp
}
/// Returns the maximum round exponent. `1 << self.max_round_exp()` milliseconds is the maximum
/// round length.
pub(crate) fn max_round_exp(&self) -> u8 {
self.max_round_exp
}
/// Returns the initial round exponent.
pub(crate) fn init_round_exp(&self) -> u8 {
self.init_round_exp
}
/// Returns the minimum height of the last block.
pub(crate) fn end_height(&self) -> u64 {
self.end_height
}
/// Returns the start timestamp of the era.
pub(crate) fn start_timestamp(&self) -> Timestamp {
self.start_timestamp
}
/// Returns the minimum timestamp of the last block.
pub(crate) fn end_timestamp(&self) -> Timestamp {
self.end_timestamp
}
/// Returns the maximum number of additional units included in evidence for conflicting
/// endorsements. If you endorse two conflicting forks at sequence numbers that differ by more
/// than this, you get away with it and are not marked faulty.
pub(crate) fn endorsement_evidence_limit(&self) -> u64 {
self.endorsement_evidence_limit
}
/// Returns new `Params` with the update endorsement evidence limit.
#[cfg(test)]
pub(crate) fn with_endorsement_evidence_limit(mut self, new_limit: u64) -> Params {
self.endorsement_evidence_limit = new_limit;
self
}
}