@@ -18,75 +18,8 @@ mod mainnet;
18
18
/// Newest network version for all networks
19
19
pub const NEWEST_NETWORK_VERSION : NetworkVersion = NetworkVersion :: V16 ;
20
20
21
- const UPGRADE_INFOS : [ UpgradeInfo ; 16 ] = [
22
- UpgradeInfo {
23
- height : Height :: Breeze ,
24
- version : NetworkVersion :: V1 ,
25
- } ,
26
- UpgradeInfo {
27
- height : Height :: Smoke ,
28
- version : NetworkVersion :: V2 ,
29
- } ,
30
- UpgradeInfo {
31
- height : Height :: Ignition ,
32
- version : NetworkVersion :: V3 ,
33
- } ,
34
- UpgradeInfo {
35
- height : Height :: ActorsV2 ,
36
- version : NetworkVersion :: V4 ,
37
- } ,
38
- UpgradeInfo {
39
- height : Height :: Tape ,
40
- version : NetworkVersion :: V5 ,
41
- } ,
42
- UpgradeInfo {
43
- height : Height :: Kumquat ,
44
- version : NetworkVersion :: V6 ,
45
- } ,
46
- UpgradeInfo {
47
- height : Height :: Calico ,
48
- version : NetworkVersion :: V7 ,
49
- } ,
50
- UpgradeInfo {
51
- height : Height :: Persian ,
52
- version : NetworkVersion :: V8 ,
53
- } ,
54
- UpgradeInfo {
55
- height : Height :: Orange ,
56
- version : NetworkVersion :: V9 ,
57
- } ,
58
- UpgradeInfo {
59
- height : Height :: Trust ,
60
- version : NetworkVersion :: V10 ,
61
- } ,
62
- UpgradeInfo {
63
- height : Height :: Norwegian ,
64
- version : NetworkVersion :: V11 ,
65
- } ,
66
- UpgradeInfo {
67
- height : Height :: Turbo ,
68
- version : NetworkVersion :: V12 ,
69
- } ,
70
- UpgradeInfo {
71
- height : Height :: Hyperdrive ,
72
- version : NetworkVersion :: V13 ,
73
- } ,
74
- UpgradeInfo {
75
- height : Height :: Chocolate ,
76
- version : NetworkVersion :: V14 ,
77
- } ,
78
- UpgradeInfo {
79
- height : Height :: OhSnap ,
80
- version : NetworkVersion :: V15 ,
81
- } ,
82
- UpgradeInfo {
83
- height : Height :: Skyr ,
84
- version : NetworkVersion :: V16 ,
85
- } ,
86
- ] ;
87
-
88
21
/// Defines the meaningful heights of the protocol.
89
- #[ derive( Debug , Clone , Copy , Serialize , Deserialize , PartialEq , Eq ) ]
22
+ #[ derive( Debug , Clone , Copy , Serialize , Deserialize , PartialEq , Eq , Hash ) ]
90
23
pub enum Height {
91
24
Breeze ,
92
25
Smoke ,
@@ -98,7 +31,6 @@ pub enum Height {
98
31
Calico ,
99
32
Persian ,
100
33
Orange ,
101
- Claus ,
102
34
Trust ,
103
35
Norwegian ,
104
36
Turbo ,
@@ -114,6 +46,30 @@ impl Default for Height {
114
46
}
115
47
}
116
48
49
+ impl From < Height > for NetworkVersion {
50
+ fn from ( height : Height ) -> NetworkVersion {
51
+ match height {
52
+ Height :: Breeze => NetworkVersion :: V1 ,
53
+ Height :: Smoke => NetworkVersion :: V2 ,
54
+ Height :: Ignition => NetworkVersion :: V3 ,
55
+ Height :: ActorsV2 => NetworkVersion :: V4 ,
56
+ Height :: Tape => NetworkVersion :: V5 ,
57
+ Height :: Liftoff => NetworkVersion :: V5 ,
58
+ Height :: Kumquat => NetworkVersion :: V6 ,
59
+ Height :: Calico => NetworkVersion :: V7 ,
60
+ Height :: Persian => NetworkVersion :: V8 ,
61
+ Height :: Orange => NetworkVersion :: V9 ,
62
+ Height :: Trust => NetworkVersion :: V10 ,
63
+ Height :: Norwegian => NetworkVersion :: V11 ,
64
+ Height :: Turbo => NetworkVersion :: V12 ,
65
+ Height :: Hyperdrive => NetworkVersion :: V13 ,
66
+ Height :: Chocolate => NetworkVersion :: V14 ,
67
+ Height :: OhSnap => NetworkVersion :: V15 ,
68
+ Height :: Skyr => NetworkVersion :: V16 ,
69
+ }
70
+ }
71
+ }
72
+
117
73
#[ derive( Debug , Serialize , Deserialize , Clone , PartialEq , Eq ) ]
118
74
pub struct UpgradeInfo {
119
75
pub height : Height ,
@@ -128,6 +84,12 @@ pub struct HeightInfo {
128
84
pub epoch : ChainEpoch ,
129
85
}
130
86
87
+ pub fn sort_by_epoch ( height_info_slice : & [ HeightInfo ] ) -> Vec < HeightInfo > {
88
+ let mut height_info_vec = height_info_slice. to_vec ( ) ;
89
+ height_info_vec. sort_by ( |a, b| a. epoch . cmp ( & b. epoch ) ) ;
90
+ height_info_vec
91
+ }
92
+
131
93
#[ derive( Clone ) ]
132
94
struct DrandPoint < ' a > {
133
95
pub height : ChainEpoch ,
@@ -141,7 +103,6 @@ pub struct ChainConfig {
141
103
pub name : String ,
142
104
pub bootstrap_peers : Vec < String > ,
143
105
pub block_delay_secs : u64 ,
144
- pub version_schedule : Vec < UpgradeInfo > ,
145
106
pub height_infos : Vec < HeightInfo > ,
146
107
#[ serde( default = "default_policy" ) ]
147
108
#[ serde( with = "serde_policy" ) ]
@@ -155,8 +116,7 @@ impl PartialEq for ChainConfig {
155
116
self . name == other. name
156
117
&& self . bootstrap_peers == other. bootstrap_peers
157
118
&& self . block_delay_secs == other. block_delay_secs
158
- && self . version_schedule == other. version_schedule
159
- && self . height_infos == other. height_infos
119
+ && sort_by_epoch ( & self . height_infos ) == sort_by_epoch ( & other. height_infos )
160
120
&& ( self . policy . max_aggregated_sectors == other. policy . max_aggregated_sectors
161
121
&& self . policy . min_aggregated_sectors == other. policy . min_aggregated_sectors
162
122
&& self . policy . max_aggregated_proof_size == other. policy . max_aggregated_proof_size
@@ -221,7 +181,6 @@ impl ChainConfig {
221
181
name : "calibnet" . to_string ( ) ,
222
182
bootstrap_peers : DEFAULT_BOOTSTRAP . iter ( ) . map ( |x| x. to_string ( ) ) . collect ( ) ,
223
183
block_delay_secs : EPOCH_DURATION_SECONDS as u64 ,
224
- version_schedule : UPGRADE_INFOS . to_vec ( ) ,
225
184
height_infos : HEIGHT_INFOS . to_vec ( ) ,
226
185
policy : Policy {
227
186
valid_post_proof_type : HashSet :: < RegisteredPoStProof > :: from ( [
@@ -239,19 +198,14 @@ impl ChainConfig {
239
198
}
240
199
241
200
pub fn network_version ( & self , epoch : ChainEpoch ) -> NetworkVersion {
242
- let height = self
243
- . height_infos
201
+ let height = sort_by_epoch ( & self . height_infos )
244
202
. iter ( )
245
203
. rev ( )
246
204
. find ( |info| epoch > info. epoch )
247
205
. map ( |info| info. height )
248
206
. unwrap_or ( Height :: Breeze ) ;
249
207
250
- self . version_schedule
251
- . iter ( )
252
- . find ( |info| height == info. height )
253
- . map ( |info| info. version )
254
- . expect ( "A network version should exist even if not specified in the config (a default exists)." )
208
+ From :: from ( height)
255
209
}
256
210
257
211
pub async fn get_beacon_schedule (
@@ -276,11 +230,11 @@ impl ChainConfig {
276
230
}
277
231
278
232
pub fn epoch ( & self , height : Height ) -> ChainEpoch {
279
- self . height_infos
233
+ sort_by_epoch ( & self . height_infos )
280
234
. iter ( )
281
235
. find ( |info| height == info. height )
282
236
. map ( |info| info. epoch )
283
- . expect ( "Internal error: Protocol height not found in map. Please report to https://github.com/ChainSafe/forest/issues" )
237
+ . unwrap_or ( 0 )
284
238
}
285
239
286
240
pub fn genesis_bytes ( & self ) -> Option < & [ u8 ] > {
@@ -305,7 +259,6 @@ impl Default for ChainConfig {
305
259
name : "mainnet" . to_string ( ) ,
306
260
bootstrap_peers : DEFAULT_BOOTSTRAP . iter ( ) . map ( |x| x. to_string ( ) ) . collect ( ) ,
307
261
block_delay_secs : EPOCH_DURATION_SECONDS as u64 ,
308
- version_schedule : UPGRADE_INFOS . to_vec ( ) ,
309
262
height_infos : HEIGHT_INFOS . to_vec ( ) ,
310
263
policy : Policy {
311
264
valid_post_proof_type : HashSet :: < RegisteredPoStProof > :: from ( [
0 commit comments