Skip to content

Commit

Permalink
Accept an advertisement if there is a free spot for it at at least on…
Browse files Browse the repository at this point in the history
…e fork
  • Loading branch information
tdimitrov committed Dec 11, 2024
1 parent 33eeb6d commit 8014eba
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
27 changes: 21 additions & 6 deletions polkadot/node/network/collator-protocol/src/validator_side/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,30 +1065,45 @@ fn ensure_seconding_limit_is_respected(
"Checking seconding limit",
);

let mut has_claim_at_some_path = false;
for path in paths {
let mut cq_state = ClaimQueueState::new();
for ancestor in path {
for ancestor in &path {
let seconded_and_pending = state.seconded_and_pending_for_para(&ancestor, &para_id);
cq_state.add_leaf(
&ancestor,
&state
.per_relay_parent
.get(&ancestor)
.get(ancestor)
.ok_or(AdvertisementError::RelayParentUnknown)?
.assignment
.current,
);
for _ in 0..seconded_and_pending {
cq_state.claim_at(&ancestor, &para_id);
cq_state.claim_at(ancestor, &para_id);
}
}

if !cq_state.can_claim_at(relay_parent, &para_id) {
return Err(AdvertisementError::SecondedLimitReached)
if cq_state.can_claim_at(relay_parent, &para_id) {
gum::trace!(
target: LOG_TARGET,
?relay_parent,
?para_id,
?path,
"Seconding limit respected at path",
);
has_claim_at_some_path = true;
break
}
}

Ok(())
// If there is a place in the claim queue for the candidate at at least one path we will accept
// it.
if has_claim_at_some_path {
Ok(())
} else {
Err(AdvertisementError::SecondedLimitReached)
}
}

async fn handle_advertisement<Sender>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2286,20 +2286,15 @@ fn claims_above_are_counted_correctly() {
test_harness(ReputationAggregator::new(|_| true), |test_harness| async move {
let TestHarness { mut virtual_overseer, keystore } = test_harness;

let hash_a = Hash::from_low_u64_be(test_state.relay_parent.to_low_u64_be() - 1);
let hash_b = Hash::from_low_u64_be(hash_a.to_low_u64_be() - 1);
let hash_c = Hash::from_low_u64_be(hash_b.to_low_u64_be() - 1);
let hash_a = Hash::from_low_u64_be(test_state.relay_parent.to_low_u64_be() - 1); // block 0
let hash_b = Hash::from_low_u64_be(hash_a.to_low_u64_be() - 1); // block 1
let hash_c = Hash::from_low_u64_be(hash_b.to_low_u64_be() - 1); // block 2

let pair_a = CollatorPair::generate().0;
let collator_a = PeerId::random();
let para_id_a = test_state.chain_ids[0];

update_view(
&mut virtual_overseer,
&mut test_state,
vec![(hash_a, 0), (hash_b, 1), (hash_c, 2)],
)
.await;
update_view(&mut virtual_overseer, &mut test_state, vec![(hash_c, 2)]).await;

connect_and_declare_collator(
&mut virtual_overseer,
Expand Down Expand Up @@ -2397,20 +2392,15 @@ fn claim_fills_last_free_slot() {
test_harness(ReputationAggregator::new(|_| true), |test_harness| async move {
let TestHarness { mut virtual_overseer, keystore } = test_harness;

let hash_a = Hash::from_low_u64_be(test_state.relay_parent.to_low_u64_be() - 1);
let hash_b = Hash::from_low_u64_be(hash_a.to_low_u64_be() - 1);
let hash_c = Hash::from_low_u64_be(hash_b.to_low_u64_be() - 1);
let hash_a = Hash::from_low_u64_be(test_state.relay_parent.to_low_u64_be() - 1); // block 0
let hash_b = Hash::from_low_u64_be(hash_a.to_low_u64_be() - 1); // block 1
let hash_c = Hash::from_low_u64_be(hash_b.to_low_u64_be() - 1); // block 2

let pair_a = CollatorPair::generate().0;
let collator_a = PeerId::random();
let para_id_a = test_state.chain_ids[0];

update_view(
&mut virtual_overseer,
&mut test_state,
vec![(hash_a, 0), (hash_b, 1), (hash_c, 2)],
)
.await;
update_view(&mut virtual_overseer, &mut test_state, vec![(hash_c, 2)]).await;

connect_and_declare_collator(
&mut virtual_overseer,
Expand All @@ -2432,25 +2422,25 @@ fn claim_fills_last_free_slot() {
)
.await;

// Collation at hash_c claims its own spot
// Collation at hash_b claims its own spot
submit_second_and_assert(
&mut virtual_overseer,
keystore.clone(),
ParaId::from(test_state.chain_ids[0]),
hash_c,
hash_b,
collator_a,
HeadData(vec![2u8]),
HeadData(vec![3u8]),
)
.await;

// Collation at hash_b claims its own spot
// Collation at hash_c claims its own spot
submit_second_and_assert(
&mut virtual_overseer,
keystore.clone(),
ParaId::from(test_state.chain_ids[0]),
hash_b,
hash_c,
collator_a,
HeadData(vec![3u8]),
HeadData(vec![2u8]),
)
.await;

Expand Down

0 comments on commit 8014eba

Please sign in to comment.