@@ -221,17 +221,19 @@ impl<P: Preset> Storage<P> {
221221
222222 info_with_peers ! ( "loaded state at slot {anchor_slot}" ) ;
223223
224+ let anchor_validators = anchor_state. validators ( ) ;
225+
224226 let mut batch = vec ! [
225227 serialize( FinalizedBlockByRoot ( anchor_block_root) , & anchor_block) ?,
226228 serialize( BlockRootBySlot ( anchor_slot) , anchor_block_root) ?,
227229 serialize( SlotByStateRoot ( anchor_state_root) , anchor_slot) ?,
228230 serialize(
229231 StateByBlockRoot ( anchor_block_root) ,
230- prepare_state( anchor_state. clone_arc( ) ) ,
232+ prepare_state( anchor_state. clone_arc( ) , anchor_validators . len_usize ( ) ) ,
231233 ) ?,
232234 ] ;
233235
234- self . append_finalized_validator_pubkeys_to_batch ( & mut batch, anchor_state . validators ( ) ) ?;
236+ self . append_finalized_validator_pubkeys_to_batch ( & mut batch, anchor_validators ) ?;
235237
236238 self . database . put_batch ( batch) ?;
237239
@@ -270,6 +272,8 @@ impl<P: Preset> Storage<P> {
270272 let mut archival_state_appended = false ;
271273 let mut batch = vec ! [ ] ;
272274
275+ let finalized_validators = store. finalized_validators ( ) ;
276+
273277 let unfinalized = unfinalized. zip ( core:: iter:: repeat ( false ) ) ;
274278 let finalized = finalized. rev ( ) . zip ( core:: iter:: repeat ( true ) ) ;
275279
@@ -279,7 +283,7 @@ impl<P: Preset> Storage<P> {
279283 . peekable ( ) ;
280284
281285 if let Some ( StateCheckpoint { head_slot, .. } ) =
282- self . load_state_checkpoint ( Some ( & store . finalized_validators ( ) ) ) ?
286+ self . load_state_checkpoint ( Some ( & finalized_validators) ) ?
283287 {
284288 store_head_slot = head_slot;
285289 }
@@ -342,6 +346,7 @@ impl<P: Preset> Storage<P> {
342346 head_slot : store_head_slot,
343347 state : prepare_state (
344348 state. get_or_init ( || chain_link. state ( store) ) . clone_arc ( ) ,
349+ finalized_validators. len_usize ( ) ,
345350 ) ,
346351 } ,
347352 ) ?) ;
@@ -358,7 +363,10 @@ impl<P: Preset> Storage<P> {
358363
359364 batch. push ( serialize (
360365 StateByBlockRoot ( block_root) ,
361- prepare_state ( state. get_or_init ( || chain_link. state ( store) ) . clone_arc ( ) ) ,
366+ prepare_state (
367+ state. get_or_init ( || chain_link. state ( store) ) . clone_arc ( ) ,
368+ finalized_validators. len_usize ( ) ,
369+ ) ,
362370 ) ?) ;
363371
364372 archival_state_appended = true ;
@@ -368,10 +376,7 @@ impl<P: Preset> Storage<P> {
368376 }
369377
370378 if update_finalized_validators {
371- self . append_finalized_validator_pubkeys_to_batch (
372- & mut batch,
373- & store. finalized_validators ( ) ,
374- ) ?;
379+ self . append_finalized_validator_pubkeys_to_batch ( & mut batch, & finalized_validators) ?;
375380 }
376381
377382 self . database . put_batch ( batch) ?;
@@ -427,7 +432,7 @@ impl<P: Preset> Storage<P> {
427432 slots. push ( state. slot ( ) ) ;
428433 batch. push ( serialize (
429434 StateByBlockRoot ( block_root) ,
430- prepare_state ( archival_state) ,
435+ prepare_state ( archival_state, finalized_validators . len_usize ( ) ) ,
431436 ) ?) ;
432437
433438 update_finalized_validators = true ;
@@ -1430,8 +1435,16 @@ pub fn print_beacon_database_info(database: &Database) -> Result<()> {
14301435 Ok ( ( ) )
14311436}
14321437
1433- fn prepare_state < P : Preset > ( mut state : Arc < BeaconState < P > > ) -> Arc < BeaconState < P > > {
1434- for validator in & mut * state. make_mut ( ) . validators_mut ( ) {
1438+ fn prepare_state < P : Preset > (
1439+ mut state : Arc < BeaconState < P > > ,
1440+ finalized_validator_list_len : usize ,
1441+ ) -> Arc < BeaconState < P > > {
1442+ for validator in state
1443+ . make_mut ( )
1444+ . validators_mut ( )
1445+ . into_iter ( )
1446+ . take ( finalized_validator_list_len)
1447+ {
14351448 // pubkey never changes, so we can restore it later from finalized validator list
14361449 validator. pubkey = PublicKeyBytes :: zero ( ) ;
14371450 }
0 commit comments