11use crate :: hdiff:: HierarchyConfig ;
2- use crate :: { DBColumn , Error , StoreItem } ;
2+ use crate :: { AnchorInfo , DBColumn , Error , Split , StoreItem } ;
33use serde:: { Deserialize , Serialize } ;
44use ssz:: { Decode , Encode } ;
55use ssz_derive:: { Decode , Encode } ;
@@ -117,15 +117,22 @@ impl StoreConfig {
117117 pub fn check_compatibility (
118118 & self ,
119119 on_disk_config : & OnDiskStoreConfig ,
120+ split : & Split ,
121+ anchor : Option < & AnchorInfo > ,
120122 ) -> Result < ( ) , StoreConfigError > {
121123 let db_config = self . as_disk_config ( ) ;
122- if db_config. ne ( on_disk_config) {
123- return Err ( StoreConfigError :: IncompatibleStoreConfig {
124+ // Allow changing the hierarchy exponents if no historic states are stored.
125+ if db_config. linear_blocks == on_disk_config. linear_blocks
126+ && ( db_config. hierarchy_config == on_disk_config. hierarchy_config
127+ || anchor. map_or ( false , |anchor| anchor. no_historic_states_stored ( split. slot ) ) )
128+ {
129+ Ok ( ( ) )
130+ } else {
131+ Err ( StoreConfigError :: IncompatibleStoreConfig {
124132 config : db_config,
125133 on_disk : on_disk_config. clone ( ) ,
126- } ) ;
134+ } )
127135 }
128- Ok ( ( ) )
129136 }
130137
131138 /// Check that the configuration is valid.
@@ -218,6 +225,8 @@ impl StoreItem for OnDiskStoreConfig {
218225#[ cfg( test) ]
219226mod test {
220227 use super :: * ;
228+ use crate :: { metadata:: STATE_UPPER_LIMIT_NO_RETAIN , AnchorInfo , Split } ;
229+ use types:: { Hash256 , Slot } ;
221230
222231 #[ test]
223232 fn check_compatibility_ok ( ) {
@@ -229,7 +238,10 @@ mod test {
229238 linear_blocks : true ,
230239 hierarchy_config : store_config. hierarchy_config . clone ( ) ,
231240 } ;
232- assert ! ( store_config. check_compatibility( & on_disk_config) . is_ok( ) ) ;
241+ let split = Split :: default ( ) ;
242+ assert ! ( store_config
243+ . check_compatibility( & on_disk_config, & split, None )
244+ . is_ok( ) ) ;
233245 }
234246
235247 #[ test]
@@ -242,7 +254,10 @@ mod test {
242254 linear_blocks : false ,
243255 hierarchy_config : store_config. hierarchy_config . clone ( ) ,
244256 } ;
245- assert ! ( store_config. check_compatibility( & on_disk_config) . is_err( ) ) ;
257+ let split = Split :: default ( ) ;
258+ assert ! ( store_config
259+ . check_compatibility( & on_disk_config, & split, None )
260+ . is_err( ) ) ;
246261 }
247262
248263 #[ test]
@@ -257,6 +272,34 @@ mod test {
257272 exponents : vec ! [ 5 , 8 , 11 , 13 , 16 , 18 , 21 ] ,
258273 } ,
259274 } ;
260- assert ! ( store_config. check_compatibility( & on_disk_config) . is_err( ) ) ;
275+ let split = Split :: default ( ) ;
276+ assert ! ( store_config
277+ . check_compatibility( & on_disk_config, & split, None )
278+ . is_err( ) ) ;
279+ }
280+
281+ #[ test]
282+ fn check_compatibility_hierarchy_config_update ( ) {
283+ let store_config = StoreConfig {
284+ linear_blocks : true ,
285+ ..Default :: default ( )
286+ } ;
287+ let on_disk_config = OnDiskStoreConfig {
288+ linear_blocks : true ,
289+ hierarchy_config : HierarchyConfig {
290+ exponents : vec ! [ 5 , 8 , 11 , 13 , 16 , 18 , 21 ] ,
291+ } ,
292+ } ;
293+ let split = Split :: default ( ) ;
294+ let anchor = AnchorInfo {
295+ anchor_slot : Slot :: new ( 0 ) ,
296+ oldest_block_slot : Slot :: new ( 0 ) ,
297+ oldest_block_parent : Hash256 :: zero ( ) ,
298+ state_upper_limit : STATE_UPPER_LIMIT_NO_RETAIN ,
299+ state_lower_limit : Slot :: new ( 0 ) ,
300+ } ;
301+ assert ! ( store_config
302+ . check_compatibility( & on_disk_config, & split, Some ( & anchor) )
303+ . is_ok( ) ) ;
261304 }
262305}
0 commit comments