@@ -347,6 +347,11 @@ impl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block> {
347
347
genesis_hash : storage. genesis_hash ,
348
348
finalized_hash : storage. finalized_hash ,
349
349
finalized_number : storage. finalized_number ,
350
+ finalized_state : if storage. finalized_hash != Default :: default ( ) {
351
+ Some ( ( storage. finalized_hash . clone ( ) , storage. finalized_number ) )
352
+ } else {
353
+ None
354
+ } ,
350
355
number_leaves : storage. leaves . count ( )
351
356
}
352
357
}
@@ -528,6 +533,32 @@ pub struct BlockImportOperation<Block: BlockT> {
528
533
set_head : Option < BlockId < Block > > ,
529
534
}
530
535
536
+ impl < Block : BlockT > BlockImportOperation < Block > where
537
+ Block :: Hash : Ord ,
538
+ {
539
+ fn apply_storage ( & mut self , storage : Storage , commit : bool ) -> sp_blockchain:: Result < Block :: Hash > {
540
+ check_genesis_storage ( & storage) ?;
541
+
542
+ let child_delta = storage. children_default . iter ( )
543
+ . map ( |( _storage_key, child_content) |
544
+ (
545
+ & child_content. child_info ,
546
+ child_content. data . iter ( ) . map ( |( k, v) | ( k. as_ref ( ) , Some ( v. as_ref ( ) ) ) )
547
+ )
548
+ ) ;
549
+
550
+ let ( root, transaction) = self . old_state . full_storage_root (
551
+ storage. top . iter ( ) . map ( |( k, v) | ( k. as_ref ( ) , Some ( v. as_ref ( ) ) ) ) ,
552
+ child_delta,
553
+ ) ;
554
+
555
+ if commit {
556
+ self . new_state = Some ( transaction) ;
557
+ }
558
+ Ok ( root)
559
+ }
560
+ }
561
+
531
562
impl < Block : BlockT > backend:: BlockImportOperation < Block > for BlockImportOperation < Block > where
532
563
Block :: Hash : Ord ,
533
564
{
@@ -569,24 +600,12 @@ impl<Block: BlockT> backend::BlockImportOperation<Block> for BlockImportOperatio
569
600
Ok ( ( ) )
570
601
}
571
602
572
- fn reset_storage ( & mut self , storage : Storage ) -> sp_blockchain:: Result < Block :: Hash > {
573
- check_genesis_storage ( & storage) ?;
574
-
575
- let child_delta = storage. children_default . iter ( )
576
- . map ( |( _storage_key, child_content) |
577
- (
578
- & child_content. child_info ,
579
- child_content. data . iter ( ) . map ( |( k, v) | ( k. as_ref ( ) , Some ( v. as_ref ( ) ) ) )
580
- )
581
- ) ;
582
-
583
- let ( root, transaction) = self . old_state . full_storage_root (
584
- storage. top . iter ( ) . map ( |( k, v) | ( k. as_ref ( ) , Some ( v. as_ref ( ) ) ) ) ,
585
- child_delta,
586
- ) ;
603
+ fn set_genesis_state ( & mut self , storage : Storage , commit : bool ) -> sp_blockchain:: Result < Block :: Hash > {
604
+ self . apply_storage ( storage, commit)
605
+ }
587
606
588
- self . new_state = Some ( transaction ) ;
589
- Ok ( root )
607
+ fn reset_storage ( & mut self , storage : Storage ) -> sp_blockchain :: Result < Block :: Hash > {
608
+ self . apply_storage ( storage , true )
590
609
}
591
610
592
611
fn insert_aux < I > ( & mut self , ops : I ) -> sp_blockchain:: Result < ( ) >
@@ -806,12 +825,12 @@ impl<Block: BlockT> backend::RemoteBackend<Block> for Backend<Block> where Block
806
825
/// Check that genesis storage is valid.
807
826
pub fn check_genesis_storage ( storage : & Storage ) -> sp_blockchain:: Result < ( ) > {
808
827
if storage. top . iter ( ) . any ( |( k, _) | well_known_keys:: is_child_storage_key ( k) ) {
809
- return Err ( sp_blockchain:: Error :: GenesisInvalid . into ( ) ) ;
828
+ return Err ( sp_blockchain:: Error :: InvalidState . into ( ) ) ;
810
829
}
811
830
812
831
if storage. children_default . keys ( )
813
832
. any ( |child_key| !well_known_keys:: is_child_storage_key ( & child_key) ) {
814
- return Err ( sp_blockchain:: Error :: GenesisInvalid . into ( ) ) ;
833
+ return Err ( sp_blockchain:: Error :: InvalidState . into ( ) ) ;
815
834
}
816
835
817
836
Ok ( ( ) )
0 commit comments