@@ -244,12 +244,13 @@ impl ProspectiveParachainsMode {
244
244
struct ActiveLeafState {
245
245
prospective_parachains_mode : ProspectiveParachainsMode ,
246
246
/// The candidates seconded at various depths under this active
247
- /// leaf. A candidate can only be seconded when its hypothetical
248
- /// depth under every active leaf has an empty entry in this map.
247
+ /// leaf with respect to parachain id. A candidate can only be
248
+ /// seconded when its hypothetical depth under every active leaf
249
+ /// has an empty entry in this map.
249
250
///
250
251
/// When prospective parachains are disabled, the only depth
251
252
/// which is allowed is 0.
252
- seconded_at_depth : BTreeMap < usize , CandidateHash > ,
253
+ seconded_at_depth : HashMap < ParaId , BTreeMap < usize , CandidateHash > > ,
253
254
}
254
255
255
256
/// The state of the subsystem.
@@ -869,7 +870,7 @@ async fn handle_active_leaves_update<Context>(
869
870
// when prospective parachains are disabled is the leaf hash and 0,
870
871
// respectively. We've just learned about the leaf hash, so we cannot
871
872
// have any candidates seconded with it as a relay-parent yet.
872
- seconded_at_depth : BTreeMap :: new ( ) ,
873
+ seconded_at_depth : HashMap :: new ( ) ,
873
874
} ,
874
875
) ;
875
876
@@ -895,7 +896,8 @@ async fn handle_active_leaves_update<Context>(
895
896
896
897
for ( candidate_hash, para_id) in remaining_seconded {
897
898
let ( tx, rx) = oneshot:: channel ( ) ;
898
- membership_answers. push ( rx. map_ok ( move |membership| ( candidate_hash, membership) ) ) ;
899
+ membership_answers
900
+ . push ( rx. map_ok ( move |membership| ( para_id, candidate_hash, membership) ) ) ;
899
901
900
902
ctx. send_message ( ProspectiveParachainsMessage :: GetTreeMembership (
901
903
para_id,
@@ -905,7 +907,7 @@ async fn handle_active_leaves_update<Context>(
905
907
. await ;
906
908
}
907
909
908
- let mut seconded_at_depth = BTreeMap :: new ( ) ;
910
+ let mut seconded_at_depth = HashMap :: new ( ) ;
909
911
for response in membership_answers. next ( ) . await {
910
912
match response {
911
913
Err ( oneshot:: Canceled ) => {
@@ -916,15 +918,17 @@ async fn handle_active_leaves_update<Context>(
916
918
917
919
continue
918
920
} ,
919
- Ok ( ( candidate_hash, membership) ) => {
921
+ Ok ( ( para_id , candidate_hash, membership) ) => {
920
922
// This request gives membership in all fragment trees. We have some
921
923
// wasted data here, and it can be optimized if it proves
922
924
// relevant to performance.
923
925
if let Some ( ( _, depths) ) =
924
926
membership. into_iter ( ) . find ( |( leaf_hash, _) | leaf_hash == & leaf. hash )
925
927
{
928
+ let para_entry: & mut BTreeMap < usize , CandidateHash > =
929
+ seconded_at_depth. entry ( para_id) . or_default ( ) ;
926
930
for depth in depths {
927
- seconded_at_depth . insert ( depth, candidate_hash) ;
931
+ para_entry . insert ( depth, candidate_hash) ;
928
932
}
929
933
}
930
934
} ,
@@ -1163,7 +1167,11 @@ async fn seconding_sanity_check<Context>(
1163
1167
responses. push ( rx. map_ok ( move |depths| ( depths, head, leaf_state) ) . boxed ( ) ) ;
1164
1168
} else {
1165
1169
if head == & candidate_relay_parent {
1166
- if leaf_state. seconded_at_depth . contains_key ( & 0 ) {
1170
+ if leaf_state
1171
+ . seconded_at_depth
1172
+ . get ( & candidate_para)
1173
+ . map_or ( false , |occupied| occupied. contains_key ( & 0 ) )
1174
+ {
1167
1175
// The leaf is already occupied.
1168
1176
return SecondingAllowed :: No
1169
1177
}
@@ -1188,7 +1196,11 @@ async fn seconding_sanity_check<Context>(
1188
1196
} ,
1189
1197
Ok ( ( depths, head, leaf_state) ) => {
1190
1198
for depth in & depths {
1191
- if leaf_state. seconded_at_depth . contains_key ( & depth) {
1199
+ if leaf_state
1200
+ . seconded_at_depth
1201
+ . get ( & candidate_para)
1202
+ . map_or ( false , |occupied| occupied. contains_key ( & depth) )
1203
+ {
1192
1204
gum:: debug!(
1193
1205
target: LOG_TARGET ,
1194
1206
?candidate_hash,
@@ -1323,8 +1335,13 @@ async fn handle_validated_candidate_command<Context>(
1323
1335
Some ( d) => d,
1324
1336
} ;
1325
1337
1338
+ let seconded_at_depth = leaf_data
1339
+ . seconded_at_depth
1340
+ . entry ( candidate. descriptor ( ) . para_id )
1341
+ . or_default ( ) ;
1342
+
1326
1343
for depth in depths {
1327
- leaf_data . seconded_at_depth . insert ( depth, candidate_hash) ;
1344
+ seconded_at_depth. insert ( depth, candidate_hash) ;
1328
1345
}
1329
1346
}
1330
1347
0 commit comments