Skip to content

Commit 60db405

Browse files
[stable2412] Backport #6864 (#6879)
Backport #6864 into `stable2412` from alexggh. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> Co-authored-by: Alexandru Gheorghe <[email protected]>
1 parent 4672a24 commit 60db405

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

polkadot/node/core/approval-voting/src/approval_db/v3/tests.rs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ fn add_block_entry_adds_child() {
264264
fn canonicalize_works() {
265265
let (mut db, store) = make_db();
266266

267-
// -> B1 -> C1 -> D1
268-
// A -> B2 -> C2 -> D2
267+
// -> B1 -> C1 -> D1 -> E1
268+
// A -> B2 -> C2 -> D2 -> E2
269269
//
270270
// We'll canonicalize C1. Everything except D1 should disappear.
271271
//
@@ -293,18 +293,22 @@ fn canonicalize_works() {
293293
let block_hash_c2 = Hash::repeat_byte(5);
294294
let block_hash_d1 = Hash::repeat_byte(6);
295295
let block_hash_d2 = Hash::repeat_byte(7);
296+
let block_hash_e1 = Hash::repeat_byte(8);
297+
let block_hash_e2 = Hash::repeat_byte(9);
296298

297299
let candidate_receipt_genesis = make_candidate(ParaId::from(1_u32), genesis);
298300
let candidate_receipt_a = make_candidate(ParaId::from(2_u32), block_hash_a);
299301
let candidate_receipt_b = make_candidate(ParaId::from(3_u32), block_hash_a);
300302
let candidate_receipt_b1 = make_candidate(ParaId::from(4_u32), block_hash_b1);
301303
let candidate_receipt_c1 = make_candidate(ParaId::from(5_u32), block_hash_c1);
304+
let candidate_receipt_e1 = make_candidate(ParaId::from(6_u32), block_hash_e1);
302305

303306
let cand_hash_1 = candidate_receipt_genesis.hash();
304307
let cand_hash_2 = candidate_receipt_a.hash();
305308
let cand_hash_3 = candidate_receipt_b.hash();
306309
let cand_hash_4 = candidate_receipt_b1.hash();
307310
let cand_hash_5 = candidate_receipt_c1.hash();
311+
let cand_hash_6 = candidate_receipt_e1.hash();
308312

309313
let block_entry_a = make_block_entry(block_hash_a, genesis, 1, Vec::new());
310314
let block_entry_b1 = make_block_entry(block_hash_b1, block_hash_a, 2, Vec::new());
@@ -326,6 +330,12 @@ fn canonicalize_works() {
326330
let block_entry_d2 =
327331
make_block_entry(block_hash_d2, block_hash_c2, 4, vec![(CoreIndex(0), cand_hash_5)]);
328332

333+
let block_entry_e1 =
334+
make_block_entry(block_hash_e1, block_hash_d1, 5, vec![(CoreIndex(0), cand_hash_6)]);
335+
336+
let block_entry_e2 =
337+
make_block_entry(block_hash_e2, block_hash_d2, 5, vec![(CoreIndex(0), cand_hash_6)]);
338+
329339
let candidate_info = {
330340
let mut candidate_info = HashMap::new();
331341
candidate_info.insert(
@@ -345,6 +355,8 @@ fn canonicalize_works() {
345355
candidate_info
346356
.insert(cand_hash_5, NewCandidateInfo::new(candidate_receipt_c1, GroupIndex(5), None));
347357

358+
candidate_info
359+
.insert(cand_hash_6, NewCandidateInfo::new(candidate_receipt_e1, GroupIndex(6), None));
348360
candidate_info
349361
};
350362

@@ -357,6 +369,8 @@ fn canonicalize_works() {
357369
block_entry_c2.clone(),
358370
block_entry_d1.clone(),
359371
block_entry_d2.clone(),
372+
block_entry_e1.clone(),
373+
block_entry_e2.clone(),
360374
];
361375

362376
let mut overlay_db = OverlayedBackend::new(&db);
@@ -438,7 +452,7 @@ fn canonicalize_works() {
438452

439453
assert_eq!(
440454
load_stored_blocks(store.as_ref(), &TEST_CONFIG).unwrap().unwrap(),
441-
StoredBlockRange(4, 5)
455+
StoredBlockRange(4, 6)
442456
);
443457

444458
check_candidates_in_store(vec![
@@ -447,6 +461,7 @@ fn canonicalize_works() {
447461
(cand_hash_3, Some(vec![block_hash_d1])),
448462
(cand_hash_4, Some(vec![block_hash_d1])),
449463
(cand_hash_5, None),
464+
(cand_hash_6, Some(vec![block_hash_e1])),
450465
]);
451466

452467
check_blocks_in_store(vec![
@@ -456,6 +471,37 @@ fn canonicalize_works() {
456471
(block_hash_c1, None),
457472
(block_hash_c2, None),
458473
(block_hash_d1, Some(vec![cand_hash_3, cand_hash_4])),
474+
(block_hash_e1, Some(vec![cand_hash_6])),
475+
(block_hash_d2, None),
476+
]);
477+
478+
let mut overlay_db = OverlayedBackend::new(&db);
479+
canonicalize(&mut overlay_db, 4, block_hash_d1).unwrap();
480+
let write_ops = overlay_db.into_write_ops();
481+
db.write(write_ops).unwrap();
482+
483+
assert_eq!(
484+
load_stored_blocks(store.as_ref(), &TEST_CONFIG).unwrap().unwrap(),
485+
StoredBlockRange(5, 6)
486+
);
487+
488+
check_candidates_in_store(vec![
489+
(cand_hash_1, None),
490+
(cand_hash_2, None),
491+
(cand_hash_3, None),
492+
(cand_hash_4, None),
493+
(cand_hash_5, None),
494+
(cand_hash_6, Some(vec![block_hash_e1])),
495+
]);
496+
497+
check_blocks_in_store(vec![
498+
(block_hash_a, None),
499+
(block_hash_b1, None),
500+
(block_hash_b2, None),
501+
(block_hash_c1, None),
502+
(block_hash_c2, None),
503+
(block_hash_d1, None),
504+
(block_hash_e1, Some(vec![cand_hash_6])),
459505
(block_hash_d2, None),
460506
]);
461507
}

polkadot/node/core/approval-voting/src/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub fn canonicalize(
9090
) -> SubsystemResult<()> {
9191
let range = match overlay_db.load_stored_blocks()? {
9292
None => return Ok(()),
93-
Some(range) if range.0 >= canon_number => return Ok(()),
93+
Some(range) if range.0 > canon_number => return Ok(()),
9494
Some(range) => range,
9595
};
9696

prdoc/pr_6864.prdoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: Fix approval-voting canonicalize off by one
5+
6+
doc:
7+
- audience: Node Dev
8+
description: |
9+
The approval-voting canonicalize was off by one, which lead to blocks being
10+
cleaned up every other 2 blocks. Normally, this is not an issue, but on restart
11+
we might end up sending NewBlocks to approval-distribution with finalized blocks.
12+
This would be problematic in the case were finalization was already lagging before
13+
restart, so after restart approval-distribution will trigger aggression on the wrong
14+
already finalized block.
15+
16+
crates:
17+
- name: polkadot-node-core-approval-voting
18+
bump: minor

0 commit comments

Comments
 (0)