@@ -807,28 +807,27 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
807807 sp_consensus:: StorageChanges :: Import ( changes) => {
808808 let mut storage = sp_storage:: Storage :: default ( ) ;
809809 for state in changes. state . 0 . into_iter ( ) {
810- if state. parent_storages . len ( ) == 0 {
810+ if state. parent_storage_keys . len ( ) == 0 && state . state_root . len ( ) == 0 {
811811 for ( key, value) in state. key_values . into_iter ( ) {
812812 storage. top . insert ( key, value) ;
813813 }
814- } else if state. parent_storages . len ( ) == 1 {
815- let storage_key = PrefixedStorageKey :: new_ref ( & state. parent_storages [ 0 ] ) ;
816- let storage_key = match ChildType :: from_prefixed_key ( & storage_key) {
817- Some ( ( ChildType :: ParentKeyId , storage_key) ) => storage_key,
818- None => return Err ( Error :: Backend ( "Invalid child storage key." . to_string ( ) ) ) ,
819- } ;
820- let entry = storage. children_default . entry ( storage_key. to_vec ( ) )
821- . or_insert_with ( || StorageChild {
822- data : Default :: default ( ) ,
823- child_info : ChildInfo :: new_default ( storage_key) ,
824- } ) ;
825- for ( key, value) in state. key_values . into_iter ( ) {
826- entry. data . insert ( key, value) ;
814+ } else {
815+ for parent_storage in state. parent_storage_keys {
816+ let storage_key = PrefixedStorageKey :: new_ref ( & parent_storage) ;
817+ let storage_key = match ChildType :: from_prefixed_key ( & storage_key) {
818+ Some ( ( ChildType :: ParentKeyId , storage_key) ) => storage_key,
819+ None => return Err ( Error :: Backend ( "Invalid child storage key." . to_string ( ) ) ) ,
820+ } ;
821+ let entry = storage. children_default . entry ( storage_key. to_vec ( ) )
822+ . or_insert_with ( || StorageChild {
823+ data : Default :: default ( ) ,
824+ child_info : ChildInfo :: new_default ( storage_key) ,
825+ } ) ;
826+ for ( key, value) in state. key_values . iter ( ) {
827+ entry. data . insert ( key. clone ( ) , value. clone ( ) ) ;
828+ }
827829 }
828830 }
829- if state. parent_storages . len ( ) > 1 {
830- return Err ( Error :: InvalidState ) ;
831- }
832831 }
833832
834833 let state_root = operation. op . reset_storage ( storage) ?;
@@ -1397,24 +1396,32 @@ impl<B, E, Block, RA> ProofProvider<Block> for Client<B, E, Block, RA> where
13971396 }
13981397 } ;
13991398 let mut current_child = if start_key. len ( ) == 2 {
1400- Some ( child_info ( start_key. get ( 0 ) . expect ( "checked len" ) ) ?)
1399+ let start_key = start_key. get ( 0 ) . expect ( "checked len" ) ;
1400+ if let Some ( child_root) = state. storage ( & start_key)
1401+ . map_err ( |e| sp_blockchain:: Error :: from_state ( Box :: new ( e) ) ) ? {
1402+ Some ( ( child_info ( start_key) ?, child_root) )
1403+ } else {
1404+ return Err ( Error :: Backend ( "Invalid root start key." . to_string ( ) ) ) ;
1405+ }
14011406 } else {
14021407 None
14031408 } ;
14041409 let mut current_key = start_key. last ( ) . map ( Clone :: clone) . unwrap_or ( Vec :: new ( ) ) ;
14051410 let mut total_size = 0 ;
14061411 let mut result = vec ! [ ( KeyValueStorageLevel {
1407- parent_storages : Vec :: new( ) ,
1412+ state_root : Vec :: new( ) ,
14081413 key_values: Vec :: new( ) ,
1414+ parent_storage_keys: Vec :: new( ) ,
14091415 } , false ) ] ;
14101416
1417+ let mut child_roots = HashSet :: new ( ) ;
14111418 loop {
14121419 let mut entries = Vec :: new ( ) ;
14131420 let mut complete = true ;
14141421 let mut switch_child_key = None ;
14151422 while let Some ( next_key) = if let Some ( child) = current_child. as_ref ( ) {
14161423 state
1417- . next_child_storage_key ( child, & current_key)
1424+ . next_child_storage_key ( & child. 0 , & current_key)
14181425 . map_err ( |e| sp_blockchain:: Error :: from_state ( Box :: new ( e) ) ) ?
14191426 } else {
14201427 state
@@ -1423,7 +1430,7 @@ impl<B, E, Block, RA> ProofProvider<Block> for Client<B, E, Block, RA> where
14231430 } {
14241431 let value = if let Some ( child) = current_child. as_ref ( ) {
14251432 state
1426- . child_storage ( child, next_key. as_ref ( ) )
1433+ . child_storage ( & child. 0 , next_key. as_ref ( ) )
14271434 . map_err ( |e| sp_blockchain:: Error :: from_state ( Box :: new ( e) ) ) ?
14281435 . unwrap_or_default ( )
14291436 } else {
@@ -1438,24 +1445,29 @@ impl<B, E, Block, RA> ProofProvider<Block> for Client<B, E, Block, RA> where
14381445 break ;
14391446 }
14401447 total_size += size;
1441- entries. push ( ( next_key. clone ( ) , value) ) ;
14421448
14431449 if current_child. is_none ( )
14441450 && sp_core:: storage:: well_known_keys:: is_child_storage_key ( next_key. as_slice ( ) ) {
1445- switch_child_key = Some ( next_key) ;
1446- break ;
1451+ if !child_roots. contains ( value. as_slice ( ) ) {
1452+ child_roots. insert ( value. clone ( ) ) ;
1453+ switch_child_key = Some ( ( next_key. clone ( ) , value. clone ( ) ) ) ;
1454+ entries. push ( ( next_key. clone ( ) , value) ) ;
1455+ break ;
1456+ }
14471457 }
1458+ entries. push ( ( next_key. clone ( ) , value) ) ;
14481459 current_key = next_key;
14491460 }
1450- if let Some ( child) = switch_child_key. take ( ) {
1461+ if let Some ( ( child, child_root ) ) = switch_child_key. take ( ) {
14511462 result[ 0 ] . 0 . key_values . extend ( entries. into_iter ( ) ) ;
1452- current_child = Some ( child_info ( & child) ?) ;
1463+ current_child = Some ( ( child_info ( & child) ?, child_root ) ) ;
14531464 current_key = Vec :: new ( ) ;
1454- } else if let Some ( child) = current_child. take ( ) {
1465+ } else if let Some ( ( child, child_root ) ) = current_child. take ( ) {
14551466 current_key = child. into_prefixed_storage_key ( ) . into_inner ( ) ;
14561467 result. push ( ( KeyValueStorageLevel {
1457- parent_storages : vec ! [ current_key . clone ( ) ] ,
1468+ state_root : child_root ,
14581469 key_values : entries,
1470+ parent_storage_keys : Vec :: new ( ) ,
14591471 } , complete) ) ;
14601472 if !complete {
14611473 break ;
0 commit comments