@@ -347,6 +347,11 @@ impl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block> {
347347 genesis_hash : storage. genesis_hash ,
348348 finalized_hash : storage. finalized_hash ,
349349 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+ } ,
350355 number_leaves : storage. leaves . count ( )
351356 }
352357 }
@@ -528,6 +533,32 @@ pub struct BlockImportOperation<Block: BlockT> {
528533 set_head : Option < BlockId < Block > > ,
529534}
530535
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+
531562impl < Block : BlockT > backend:: BlockImportOperation < Block > for BlockImportOperation < Block > where
532563 Block :: Hash : Ord ,
533564{
@@ -569,24 +600,12 @@ impl<Block: BlockT> backend::BlockImportOperation<Block> for BlockImportOperatio
569600 Ok ( ( ) )
570601 }
571602
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+ }
587606
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 )
590609 }
591610
592611 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
806825/// Check that genesis storage is valid.
807826pub fn check_genesis_storage ( storage : & Storage ) -> sp_blockchain:: Result < ( ) > {
808827 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 ( ) ) ;
810829 }
811830
812831 if storage. children_default . keys ( )
813832 . 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 ( ) ) ;
815834 }
816835
817836 Ok ( ( ) )
0 commit comments