Skip to content

Commit c5987d6

Browse files
committed
fix prospective-parachains tests
1 parent 87dbad5 commit c5987d6

File tree

3 files changed

+152
-328
lines changed

3 files changed

+152
-328
lines changed

polkadot/node/core/prospective-parachains/src/fragment_chain/mod.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
//! The best chain contains all the candidates pending availability and a subsequent chain
3333
//! of candidates that have reached the backing quorum and are better than any other backable forks
3434
//! according to the fork selection rule (more on this rule later). It has a length of size at most
35-
//! `max_candidate_depth + 1`.
35+
//! `num_of_pending_candidates + num_of_assigned_cores_for_para`.
3636
//!
3737
//! The unconnected storage keeps a record of seconded/backable candidates that may be
3838
//! added to the best chain in the future.
@@ -100,13 +100,10 @@
100100
//! bounded. This means that higher-level code needs to be selective about limiting the amount of
101101
//! candidates that are considered.
102102
//!
103-
//! Practically speaking, the collator-protocol will not allow more than `max_candidate_depth + 1`
104-
//! collations to be fetched at a relay parent and statement-distribution will not allow more than
105-
//! `max_candidate_depth + 1` seconded candidates at a relay parent per each validator in the
106-
//! backing group. Considering the `allowed_ancestry_len` configuration value, the number of
107-
//! candidates in a `FragmentChain` (including its unconnected storage) should not exceed:
108-
//!
109-
//! `allowed_ancestry_len * (max_candidate_depth + 1) * backing_group_size`.
103+
//! Practically speaking, the collator-protocol will limit the number of fetched collations per
104+
//! core, to the number of claim queue assignments for the paraid on that core.
105+
//! Statement-distribution will not allow more than `scheduler_params.lookahead` seconded candidates
106+
//! at a relay parent per each validator in the backing group.
110107
//!
111108
//! The code in this module is not designed for speed or efficiency, but conceptual simplicity.
112109
//! Our assumption is that the amount of candidates and parachains we consider will be reasonably
@@ -515,6 +512,8 @@ impl Scope {
515512
}
516513
}
517514

515+
println!("ALIN: {max_backable_len}");
516+
518517
Ok(Scope {
519518
relay_parent,
520519
base_constraints,
@@ -1182,7 +1181,7 @@ impl FragmentChain {
11821181
let Some(mut earliest_rp) = self.earliest_relay_parent() else { return };
11831182

11841183
loop {
1185-
if self.best_chain.chain.len() > self.scope.max_backable_len {
1184+
if self.best_chain.chain.len() >= self.scope.max_backable_len {
11861185
break;
11871186
}
11881187

polkadot/node/core/prospective-parachains/src/fragment_chain/tests.rs

+42-21
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn scope_rejects_ancestors_that_skip_blocks() {
115115
storage_root: Hash::repeat_byte(69),
116116
}];
117117

118-
let max_depth = 2;
118+
let max_depth = 3;
119119
let base_constraints = make_constraints(8, vec![8, 9], vec![1, 2, 3].into());
120120
let pending_availability = Vec::new();
121121

@@ -145,7 +145,7 @@ fn scope_rejects_ancestor_for_0_block() {
145145
storage_root: Hash::repeat_byte(69),
146146
}];
147147

148-
let max_depth = 2;
148+
let max_depth = 3;
149149
let base_constraints = make_constraints(0, vec![], vec![1, 2, 3].into());
150150
let pending_availability = Vec::new();
151151

@@ -187,7 +187,7 @@ fn scope_only_takes_ancestors_up_to_min() {
187187
},
188188
];
189189

190-
let max_depth = 2;
190+
let max_depth = 3;
191191
let base_constraints = make_constraints(3, vec![2], vec![1, 2, 3].into());
192192
let pending_availability = Vec::new();
193193

@@ -230,7 +230,7 @@ fn scope_rejects_unordered_ancestors() {
230230
},
231231
];
232232

233-
let max_depth = 2;
233+
let max_depth = 3;
234234
let base_constraints = make_constraints(0, vec![2], vec![1, 2, 3].into());
235235
let pending_availability = Vec::new();
236236

@@ -496,7 +496,7 @@ fn test_populate_and_check_potential() {
496496
relay_parent_z_info.clone(),
497497
wrong_constraints.clone(),
498498
vec![],
499-
4,
499+
5,
500500
ancestors.clone(),
501501
)
502502
.unwrap();
@@ -529,7 +529,7 @@ fn test_populate_and_check_potential() {
529529

530530
// Various depths
531531
{
532-
// Depth is 0, only allows one candidate, but the others will be kept as potential.
532+
// Depth is 0, doesn't allow any candidate, but the others will be kept as potential.
533533
let scope = Scope::with_ancestors(
534534
relay_parent_z_info.clone(),
535535
base_constraints.clone(),
@@ -543,19 +543,40 @@ fn test_populate_and_check_potential() {
543543
assert!(chain.can_add_candidate_as_potential(&candidate_b_entry).is_ok());
544544
assert!(chain.can_add_candidate_as_potential(&candidate_c_entry).is_ok());
545545

546+
let chain = populate_chain_from_previous_storage(&scope, &storage);
547+
assert!(chain.best_chain_vec().is_empty());
548+
assert_eq!(
549+
chain.unconnected().map(|c| c.candidate_hash).collect::<HashSet<_>>(),
550+
[candidate_a_hash, candidate_b_hash, candidate_c_hash].into_iter().collect()
551+
);
552+
553+
// Depth is 1, only allows one candidate, but the others will be kept as potential.
554+
let scope = Scope::with_ancestors(
555+
relay_parent_z_info.clone(),
556+
base_constraints.clone(),
557+
vec![],
558+
1,
559+
ancestors.clone(),
560+
)
561+
.unwrap();
562+
let chain = FragmentChain::init(scope.clone(), CandidateStorage::default());
563+
assert!(chain.can_add_candidate_as_potential(&candidate_a_entry).is_ok());
564+
assert!(chain.can_add_candidate_as_potential(&candidate_b_entry).is_ok());
565+
assert!(chain.can_add_candidate_as_potential(&candidate_c_entry).is_ok());
566+
546567
let chain = populate_chain_from_previous_storage(&scope, &storage);
547568
assert_eq!(chain.best_chain_vec(), vec![candidate_a_hash]);
548569
assert_eq!(
549570
chain.unconnected().map(|c| c.candidate_hash).collect::<HashSet<_>>(),
550571
[candidate_b_hash, candidate_c_hash].into_iter().collect()
551572
);
552573

553-
// depth is 1, allows two candidates
574+
// depth is 2, allows two candidates
554575
let scope = Scope::with_ancestors(
555576
relay_parent_z_info.clone(),
556577
base_constraints.clone(),
557578
vec![],
558-
1,
579+
2,
559580
ancestors.clone(),
560581
)
561582
.unwrap();
@@ -571,8 +592,8 @@ fn test_populate_and_check_potential() {
571592
[candidate_c_hash].into_iter().collect()
572593
);
573594

574-
// depth is larger than 2, allows all three candidates
575-
for depth in 2..6 {
595+
// depth is at least 3, allows all three candidates
596+
for depth in 3..6 {
576597
let scope = Scope::with_ancestors(
577598
relay_parent_z_info.clone(),
578599
base_constraints.clone(),
@@ -604,7 +625,7 @@ fn test_populate_and_check_potential() {
604625
relay_parent_z_info.clone(),
605626
base_constraints.clone(),
606627
vec![],
607-
4,
628+
5,
608629
ancestors_without_x,
609630
)
610631
.unwrap();
@@ -627,7 +648,7 @@ fn test_populate_and_check_potential() {
627648
relay_parent_z_info.clone(),
628649
base_constraints.clone(),
629650
vec![],
630-
4,
651+
5,
631652
vec![],
632653
)
633654
.unwrap();
@@ -673,7 +694,7 @@ fn test_populate_and_check_potential() {
673694
relay_parent_z_info.clone(),
674695
base_constraints.clone(),
675696
vec![],
676-
4,
697+
5,
677698
ancestors.clone(),
678699
)
679700
.unwrap();
@@ -715,7 +736,7 @@ fn test_populate_and_check_potential() {
715736
relay_parent_z_info.clone(),
716737
base_constraints.clone(),
717738
vec![],
718-
4,
739+
5,
719740
ancestors.clone(),
720741
)
721742
.unwrap();
@@ -757,7 +778,7 @@ fn test_populate_and_check_potential() {
757778
relay_parent_z_info.clone(),
758779
base_constraints.clone(),
759780
vec![],
760-
4,
781+
5,
761782
ancestors.clone(),
762783
)
763784
.unwrap();
@@ -986,7 +1007,7 @@ fn test_populate_and_check_potential() {
9861007
relay_parent_z_info.clone(),
9871008
base_constraints.clone(),
9881009
vec![],
989-
2,
1010+
3,
9901011
ancestors.clone(),
9911012
)
9921013
.unwrap();
@@ -1301,7 +1322,7 @@ fn test_populate_and_check_potential() {
13011322
relay_parent: relay_parent_z_info.clone(),
13021323
},
13031324
],
1304-
2,
1325+
0,
13051326
ancestors.clone(),
13061327
)
13071328
.unwrap();
@@ -1326,7 +1347,7 @@ fn test_populate_and_check_potential() {
13261347
relay_parent_z_info.clone(),
13271348
base_constraints.clone(),
13281349
vec![],
1329-
2,
1350+
3,
13301351
ancestors.clone(),
13311352
)
13321353
.unwrap();
@@ -1355,7 +1376,7 @@ fn test_populate_and_check_potential() {
13551376
fn test_find_ancestor_path_and_find_backable_chain_empty_best_chain() {
13561377
let relay_parent = Hash::repeat_byte(1);
13571378
let required_parent: HeadData = vec![0xff].into();
1358-
let max_depth = 10;
1379+
let max_depth = 11;
13591380

13601381
// Empty chain
13611382
let base_constraints = make_constraints(0, vec![0], required_parent.clone());
@@ -1382,7 +1403,7 @@ fn test_find_ancestor_path_and_find_backable_chain() {
13821403
let para_id = ParaId::from(5u32);
13831404
let relay_parent = Hash::repeat_byte(1);
13841405
let required_parent: HeadData = vec![0xff].into();
1385-
let max_depth = 5;
1406+
let max_depth = 6;
13861407
let relay_parent_number = 0;
13871408
let relay_parent_storage_root = Hash::zero();
13881409

@@ -1567,7 +1588,7 @@ fn test_find_ancestor_path_and_find_backable_chain() {
15671588
candidate_hash: candidates[3],
15681589
relay_parent: relay_parent_info,
15691590
}],
1570-
max_depth,
1591+
max_depth - 1,
15711592
vec![],
15721593
)
15731594
.unwrap();

0 commit comments

Comments
 (0)