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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
use network::constants::Network;
use util::uint::Uint256;
const MAX_BITS_BITCOIN: Uint256 = Uint256([
0x0000000000000000u64,
0x0000000000000000u64,
0x0000000000000000u64,
0x00000000ffff0000u64,
]);
const MAX_BITS_TESTNET: Uint256 = Uint256([
0x0000000000000000u64,
0x0000000000000000u64,
0x0000000000000000u64,
0x00000000ffff0000u64,
]);
const MAX_BITS_SIGNET: Uint256 = Uint256([
0x0000000000000000u64,
0x0000000000000000u64,
0x0000000000000000u64,
0x00000377ae000000u64,
]);
const MAX_BITS_REGTEST: Uint256 = Uint256([
0x0000000000000000u64,
0x0000000000000000u64,
0x0000000000000000u64,
0x7fffff0000000000u64,
]);
#[derive(Debug, Clone)]
pub struct Params {
pub network: Network,
pub bip16_time: u32,
pub bip34_height: u32,
pub bip65_height: u32,
pub bip66_height: u32,
pub rule_change_activation_threshold: u32,
pub miner_confirmation_window: u32,
pub pow_limit: Uint256,
pub pow_target_spacing: u64,
pub pow_target_timespan: u64,
pub allow_min_difficulty_blocks: bool,
pub no_pow_retargeting: bool,
}
impl Params {
pub fn new(network: Network) -> Self {
match network {
Network::Bitcoin => Params {
network: Network::Bitcoin,
bip16_time: 1333238400,
bip34_height: 227931,
bip65_height: 388381,
bip66_height: 363725,
rule_change_activation_threshold: 1916,
miner_confirmation_window: 2016,
pow_limit: MAX_BITS_BITCOIN,
pow_target_spacing: 10 * 60,
pow_target_timespan: 14 * 24 * 60 * 60,
allow_min_difficulty_blocks: false,
no_pow_retargeting: false,
},
Network::Testnet => Params {
network: Network::Testnet,
bip16_time: 1333238400,
bip34_height: 21111,
bip65_height: 581885,
bip66_height: 330776,
rule_change_activation_threshold: 1512,
miner_confirmation_window: 2016,
pow_limit: MAX_BITS_TESTNET,
pow_target_spacing: 10 * 60,
pow_target_timespan: 14 * 24 * 60 * 60,
allow_min_difficulty_blocks: true,
no_pow_retargeting: false,
},
Network::Signet => Params {
network: Network::Signet,
bip16_time: 1333238400,
bip34_height: 1,
bip65_height: 1,
bip66_height: 1,
rule_change_activation_threshold: 1916,
miner_confirmation_window: 2016,
pow_limit: MAX_BITS_SIGNET,
pow_target_spacing: 10 * 60,
pow_target_timespan: 14 * 24 * 60 * 60,
allow_min_difficulty_blocks: false,
no_pow_retargeting: false,
},
Network::Regtest => Params {
network: Network::Regtest,
bip16_time: 1333238400,
bip34_height: 100000000,
bip65_height: 1351,
bip66_height: 1251,
rule_change_activation_threshold: 108,
miner_confirmation_window: 144,
pow_limit: MAX_BITS_REGTEST,
pow_target_spacing: 10 * 60,
pow_target_timespan: 14 * 24 * 60 * 60,
allow_min_difficulty_blocks: true,
no_pow_retargeting: true,
},
}
}
pub fn difficulty_adjustment_interval(&self) -> u64 {
self.pow_target_timespan / self.pow_target_spacing
}
}