@@ -927,22 +927,39 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
927927 BlockOrigin :: Genesis | BlockOrigin :: NetworkInitialSync | BlockOrigin :: File => false ,
928928 } ;
929929
930- self . backend . begin_state_operation ( & mut operation. op , BlockId :: Hash ( parent_hash) ) ?;
930+ let storage_changes = match & body {
931+ Some ( body) => {
932+ self . backend . begin_state_operation ( & mut operation. op , BlockId :: Hash ( parent_hash) ) ?;
933+
934+ // ensure parent block is finalized to maintain invariant that
935+ // finality is called sequentially.
936+ if finalized {
937+ self . apply_finality_with_block_hash ( operation, parent_hash, None , info. best_hash , make_notifications) ?;
938+ }
931939
932- // ensure parent block is finalized to maintain invariant that
933- // finality is called sequentially.
934- if finalized {
935- self . apply_finality_with_block_hash ( operation, parent_hash, None , info. best_hash , make_notifications) ?;
936- }
940+ // FIXME #1232: correct path logic for when to execute this function
941+ let ( storage_update, changes_update, storage_changes) = self . block_execution (
942+ & operation. op ,
943+ & import_headers,
944+ origin,
945+ hash,
946+ & body,
947+ ) ?;
937948
938- // FIXME #1232: correct path logic for when to execute this function
939- let ( storage_update, changes_update, storage_changes) = self . block_execution (
940- & operation. op ,
941- & import_headers,
942- origin,
943- hash,
944- body. clone ( ) ,
945- ) ?;
949+ operation. op . update_cache ( new_cache) ;
950+ if let Some ( storage_update) = storage_update {
951+ operation. op . update_db_storage ( storage_update) ?;
952+ }
953+ if let Some ( storage_changes) = storage_changes. clone ( ) {
954+ operation. op . update_storage ( storage_changes. 0 , storage_changes. 1 ) ?;
955+ }
956+ if let Some ( Some ( changes_update) ) = changes_update {
957+ operation. op . update_changes_trie ( changes_update) ?;
958+ }
959+ storage_changes
960+ } ,
961+ None => Default :: default ( )
962+ } ;
946963
947964 let is_new_best = finalized || match fork_choice {
948965 ForkChoiceStrategy :: LongestChain => import_headers. post ( ) . number ( ) > & info. best_number ,
@@ -977,17 +994,6 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
977994 leaf_state,
978995 ) ?;
979996
980- operation. op . update_cache ( new_cache) ;
981- if let Some ( storage_update) = storage_update {
982- operation. op . update_db_storage ( storage_update) ?;
983- }
984- if let Some ( storage_changes) = storage_changes. clone ( ) {
985- operation. op . update_storage ( storage_changes. 0 , storage_changes. 1 ) ?;
986- }
987- if let Some ( Some ( changes_update) ) = changes_update {
988- operation. op . update_changes_trie ( changes_update) ?;
989- }
990-
991997 operation. op . insert_aux ( aux) ?;
992998
993999 if make_notifications {
@@ -1014,7 +1020,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
10141020 import_headers : & PrePostHeader < Block :: Header > ,
10151021 origin : BlockOrigin ,
10161022 hash : Block :: Hash ,
1017- body : Option < Vec < Block :: Extrinsic > > ,
1023+ body : & [ Block :: Extrinsic ] ,
10181024 ) -> error:: Result < (
10191025 Option < StorageUpdate < B , Block > > ,
10201026 Option < Option < ChangesUpdate < Block > > > ,
@@ -1052,7 +1058,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
10521058
10531059 let encoded_block = <Block as BlockT >:: encode_from (
10541060 import_headers. pre ( ) ,
1055- & body. unwrap_or_default ( )
1061+ body,
10561062 ) ;
10571063
10581064 let ( _, storage_update, changes_update) = self . executor
@@ -1523,7 +1529,7 @@ impl<'a, B, E, Block, RA> consensus::BlockImport<Block> for &'a Client<B, E, Blo
15231529 & mut self ,
15241530 block : BlockCheckParams < Block > ,
15251531 ) -> Result < ImportResult , Self :: Error > {
1526- let BlockCheckParams { hash, number, parent_hash } = block;
1532+ let BlockCheckParams { hash, number, parent_hash, header_only } = block;
15271533
15281534 if let Some ( h) = self . fork_blocks . as_ref ( ) . and_then ( |x| x. get ( & number) ) {
15291535 if & hash != h {
@@ -1541,7 +1547,9 @@ impl<'a, B, E, Block, RA> consensus::BlockImport<Block> for &'a Client<B, E, Blo
15411547 . map_err ( |e| ConsensusError :: ClientImport ( e. to_string ( ) ) ) ?
15421548 {
15431549 BlockStatus :: InChainWithState | BlockStatus :: Queued => { } ,
1544- BlockStatus :: Unknown | BlockStatus :: InChainPruned => return Ok ( ImportResult :: UnknownParent ) ,
1550+ BlockStatus :: Unknown => return Ok ( ImportResult :: UnknownParent ) ,
1551+ BlockStatus :: InChainPruned if header_only => { } ,
1552+ BlockStatus :: InChainPruned => return Ok ( ImportResult :: MissingState ) ,
15451553 BlockStatus :: KnownBad => return Ok ( ImportResult :: KnownBad ) ,
15461554 }
15471555
@@ -1553,7 +1561,6 @@ impl<'a, B, E, Block, RA> consensus::BlockImport<Block> for &'a Client<B, E, Blo
15531561 BlockStatus :: KnownBad => return Ok ( ImportResult :: KnownBad ) ,
15541562 }
15551563
1556-
15571564 Ok ( ImportResult :: imported ( false ) )
15581565 }
15591566}
0 commit comments