Skip to content

Commit 0570b6f

Browse files
sandreimalexggh
andauthored
approval-voting improvement: include all tranche0 assignments in one certificate (#1178)
**_PR migrated from https://github.com/paritytech/polkadot/pull/6782_** This PR will upgrade the network protocol to version 3 -> VStaging which will later be renamed to V3. This version introduces a new kind of assignment certificate that will be used for tranche0 assignments. Instead of issuing/importing one tranche0 assignment per candidate, there will be just one certificate per relay chain block per validator. However, we will not be sending out the new assignment certificates, yet. So everything should work exactly as before. Once the majority of the validators have been upgraded to the new protocol version we will enable the new certificates (starting at a specific relay chain block) with a new client update. There are still a few things that need to be done: - [x] Use bitfield instead of Vec<CandidateIndex>: paritytech/polkadot#6802 - [x] Fix existing approval-distribution and approval-voting tests - [x] Fix bitfield-distribution and statement-distribution tests - [x] Fix network bridge tests - [x] Implement todos in the code - [x] Add tests to cover new code - [x] Update metrics - [x] Remove the approval distribution aggression levels: TBD PR - [x] Parachains DB migration - [x] Test network protocol upgrade on Versi - [x] Versi Load test - [x] Add Zombienet test - [x] Documentation updates - [x] Fix for sending DistributeAssignment for each candidate claimed by a v2 assignment (warning: Importing locally an already known assignment) - [x] Fix AcceptedDuplicate - [x] Fix DB migration so that we can still keep old data. - [x] Final Versi burn in --------- Signed-off-by: Andrei Sandu <[email protected]> Signed-off-by: Alexandru Gheorghe <[email protected]> Co-authored-by: Alexandru Gheorghe <[email protected]>
1 parent 4ac9c4a commit 0570b6f

File tree

55 files changed

+5641
-1797
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+5641
-1797
lines changed

.gitlab/pipeline/zombienet/polkadot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ zombienet-polkadot-functional-0005-parachains-disputes-past-session:
105105
--local-dir="${LOCAL_DIR}/functional"
106106
--test="0005-parachains-disputes-past-session.zndsl"
107107

108+
zombienet-polkadot-functional-0006-parachains-max-tranche0:
109+
extends:
110+
- .zombienet-polkadot-common
111+
script:
112+
- /home/nonroot/zombie-net/scripts/ci/run-test-local-env-manager.sh
113+
--local-dir="${LOCAL_DIR}/functional"
114+
--test="0006-parachains-max-tranche0.zndsl"
115+
108116
zombienet-polkadot-smoke-0001-parachains-smoke-test:
109117
extends:
110118
- .zombienet-polkadot-common

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

polkadot/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ jemalloc-allocator = [
6464
"polkadot-node-core-pvf/jemalloc-allocator",
6565
"polkadot-overseer/jemalloc-allocator",
6666
]
67+
network-protocol-staging = [ "polkadot-cli/network-protocol-staging" ]
68+
6769

6870
# Enables timeout-based tests supposed to be run only in CI environment as they may be flaky
6971
# when run locally depending on system load

polkadot/cli/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,5 @@ runtime-metrics = [
7474
"polkadot-node-metrics/runtime-metrics",
7575
"service/runtime-metrics",
7676
]
77+
78+
network-protocol-staging = [ "service/network-protocol-staging" ]

polkadot/node/core/approval-voting/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ schnorrkel = "0.9.1"
1717
kvdb = "0.13.0"
1818
derive_more = "0.99.17"
1919
thiserror = "1.0.48"
20+
itertools = "0.10.5"
2021

2122
polkadot-node-subsystem = { path = "../../subsystem" }
2223
polkadot-node-subsystem-util = { path = "../../subsystem-util" }
@@ -30,6 +31,9 @@ sp-consensus = { path = "../../../../substrate/primitives/consensus/common", def
3031
sp-consensus-slots = { path = "../../../../substrate/primitives/consensus/slots", default-features = false }
3132
sp-application-crypto = { path = "../../../../substrate/primitives/application-crypto", default-features = false, features = ["full_crypto"] }
3233
sp-runtime = { path = "../../../../substrate/primitives/runtime", default-features = false }
34+
rand_core = "0.5.1"
35+
rand_chacha = { version = "0.3.1" }
36+
rand = "0.8.5"
3337

3438
[dev-dependencies]
3539
async-trait = "0.1.57"
@@ -43,3 +47,5 @@ polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" }
4347
assert_matches = "1.4.0"
4448
kvdb-memorydb = "0.13.0"
4549
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../../primitives/test-helpers" }
50+
log = "0.4.17"
51+
env_logger = "0.9.0"

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! Utilities for checking whether a candidate has been approved under a given block.
1818
1919
use bitvec::{order::Lsb0 as BitOrderLsb0, slice::BitSlice};
20-
use polkadot_node_primitives::approval::DelayTranche;
20+
use polkadot_node_primitives::approval::v1::DelayTranche;
2121
use polkadot_primitives::ValidatorIndex;
2222

2323
use crate::{
@@ -472,9 +472,9 @@ mod tests {
472472
}
473473
.into();
474474

475-
let approval_entry = approval_db::v1::ApprovalEntry {
475+
let approval_entry = approval_db::v2::ApprovalEntry {
476476
tranches: Vec::new(),
477-
assignments: BitVec::default(),
477+
assigned_validators: BitVec::default(),
478478
our_assignment: None,
479479
our_approval_sig: None,
480480
backing_group: GroupIndex(0),
@@ -509,22 +509,22 @@ mod tests {
509509
candidate.mark_approval(ValidatorIndex(i));
510510
}
511511

512-
let approval_entry = approval_db::v1::ApprovalEntry {
512+
let approval_entry = approval_db::v2::ApprovalEntry {
513513
tranches: vec![
514-
approval_db::v1::TrancheEntry {
514+
approval_db::v2::TrancheEntry {
515515
tranche: 0,
516516
assignments: (0..2).map(|i| (ValidatorIndex(i), 0.into())).collect(),
517517
},
518-
approval_db::v1::TrancheEntry {
518+
approval_db::v2::TrancheEntry {
519519
tranche: 1,
520520
assignments: (2..5).map(|i| (ValidatorIndex(i), 1.into())).collect(),
521521
},
522-
approval_db::v1::TrancheEntry {
522+
approval_db::v2::TrancheEntry {
523523
tranche: 2,
524524
assignments: (5..10).map(|i| (ValidatorIndex(i), 0.into())).collect(),
525525
},
526526
],
527-
assignments: bitvec![u8, BitOrderLsb0; 1; 10],
527+
assigned_validators: bitvec![u8, BitOrderLsb0; 1; 10],
528528
our_assignment: None,
529529
our_approval_sig: None,
530530
backing_group: GroupIndex(0),
@@ -581,22 +581,22 @@ mod tests {
581581
candidate.mark_approval(ValidatorIndex(i));
582582
}
583583

584-
let approval_entry = approval_db::v1::ApprovalEntry {
584+
let approval_entry = approval_db::v2::ApprovalEntry {
585585
tranches: vec![
586-
approval_db::v1::TrancheEntry {
586+
approval_db::v2::TrancheEntry {
587587
tranche: 0,
588588
assignments: (0..4).map(|i| (ValidatorIndex(i), 0.into())).collect(),
589589
},
590-
approval_db::v1::TrancheEntry {
590+
approval_db::v2::TrancheEntry {
591591
tranche: 1,
592592
assignments: (4..6).map(|i| (ValidatorIndex(i), 1.into())).collect(),
593593
},
594-
approval_db::v1::TrancheEntry {
594+
approval_db::v2::TrancheEntry {
595595
tranche: 2,
596596
assignments: (6..10).map(|i| (ValidatorIndex(i), 0.into())).collect(),
597597
},
598598
],
599-
assignments: bitvec![u8, BitOrderLsb0; 1; 10],
599+
assigned_validators: bitvec![u8, BitOrderLsb0; 1; 10],
600600
our_assignment: None,
601601
our_approval_sig: None,
602602
backing_group: GroupIndex(0),
@@ -647,9 +647,9 @@ mod tests {
647647
let no_show_duration = 10;
648648
let needed_approvals = 4;
649649

650-
let mut approval_entry: ApprovalEntry = approval_db::v1::ApprovalEntry {
650+
let mut approval_entry: ApprovalEntry = approval_db::v2::ApprovalEntry {
651651
tranches: Vec::new(),
652-
assignments: bitvec![u8, BitOrderLsb0; 0; 5],
652+
assigned_validators: bitvec![u8, BitOrderLsb0; 0; 5],
653653
our_assignment: None,
654654
our_approval_sig: None,
655655
backing_group: GroupIndex(0),
@@ -691,9 +691,9 @@ mod tests {
691691
let no_show_duration = 10;
692692
let needed_approvals = 4;
693693

694-
let mut approval_entry: ApprovalEntry = approval_db::v1::ApprovalEntry {
694+
let mut approval_entry: ApprovalEntry = approval_db::v2::ApprovalEntry {
695695
tranches: Vec::new(),
696-
assignments: bitvec![u8, BitOrderLsb0; 0; 10],
696+
assigned_validators: bitvec![u8, BitOrderLsb0; 0; 10],
697697
our_assignment: None,
698698
our_approval_sig: None,
699699
backing_group: GroupIndex(0),
@@ -731,9 +731,9 @@ mod tests {
731731
let no_show_duration = 10;
732732
let needed_approvals = 4;
733733

734-
let mut approval_entry: ApprovalEntry = approval_db::v1::ApprovalEntry {
734+
let mut approval_entry: ApprovalEntry = approval_db::v2::ApprovalEntry {
735735
tranches: Vec::new(),
736-
assignments: bitvec![u8, BitOrderLsb0; 0; 10],
736+
assigned_validators: bitvec![u8, BitOrderLsb0; 0; 10],
737737
our_assignment: None,
738738
our_approval_sig: None,
739739
backing_group: GroupIndex(0),
@@ -776,9 +776,9 @@ mod tests {
776776
let needed_approvals = 4;
777777
let n_validators = 8;
778778

779-
let mut approval_entry: ApprovalEntry = approval_db::v1::ApprovalEntry {
779+
let mut approval_entry: ApprovalEntry = approval_db::v2::ApprovalEntry {
780780
tranches: Vec::new(),
781-
assignments: bitvec![u8, BitOrderLsb0; 0; n_validators],
781+
assigned_validators: bitvec![u8, BitOrderLsb0; 0; n_validators],
782782
our_assignment: None,
783783
our_approval_sig: None,
784784
backing_group: GroupIndex(0),
@@ -843,9 +843,9 @@ mod tests {
843843
let needed_approvals = 4;
844844
let n_validators = 8;
845845

846-
let mut approval_entry: ApprovalEntry = approval_db::v1::ApprovalEntry {
846+
let mut approval_entry: ApprovalEntry = approval_db::v2::ApprovalEntry {
847847
tranches: Vec::new(),
848-
assignments: bitvec![u8, BitOrderLsb0; 0; n_validators],
848+
assigned_validators: bitvec![u8, BitOrderLsb0; 0; n_validators],
849849
our_assignment: None,
850850
our_approval_sig: None,
851851
backing_group: GroupIndex(0),
@@ -934,9 +934,9 @@ mod tests {
934934
let needed_approvals = 4;
935935
let n_validators = 8;
936936

937-
let mut approval_entry: ApprovalEntry = approval_db::v1::ApprovalEntry {
937+
let mut approval_entry: ApprovalEntry = approval_db::v2::ApprovalEntry {
938938
tranches: Vec::new(),
939-
assignments: bitvec![u8, BitOrderLsb0; 0; n_validators],
939+
assigned_validators: bitvec![u8, BitOrderLsb0; 0; n_validators],
940940
our_assignment: None,
941941
our_approval_sig: None,
942942
backing_group: GroupIndex(0),
@@ -1041,15 +1041,15 @@ mod tests {
10411041
candidate.mark_approval(ValidatorIndex(i));
10421042
}
10431043

1044-
let approval_entry = approval_db::v1::ApprovalEntry {
1044+
let approval_entry = approval_db::v2::ApprovalEntry {
10451045
tranches: vec![
10461046
// Assignments with invalid validator indexes.
1047-
approval_db::v1::TrancheEntry {
1047+
approval_db::v2::TrancheEntry {
10481048
tranche: 1,
10491049
assignments: (2..5).map(|i| (ValidatorIndex(i), 1.into())).collect(),
10501050
},
10511051
],
1052-
assignments: bitvec![u8, BitOrderLsb0; 1; 3],
1052+
assigned_validators: bitvec![u8, BitOrderLsb0; 1; 3],
10531053
our_assignment: None,
10541054
our_approval_sig: None,
10551055
backing_group: GroupIndex(0),
@@ -1094,12 +1094,12 @@ mod tests {
10941094
];
10951095

10961096
for test_tranche in test_tranches {
1097-
let mut approval_entry: ApprovalEntry = approval_db::v1::ApprovalEntry {
1097+
let mut approval_entry: ApprovalEntry = approval_db::v2::ApprovalEntry {
10981098
tranches: Vec::new(),
10991099
backing_group: GroupIndex(0),
11001100
our_assignment: None,
11011101
our_approval_sig: None,
1102-
assignments: bitvec![u8, BitOrderLsb0; 0; 3],
1102+
assigned_validators: bitvec![u8, BitOrderLsb0; 0; 3],
11031103
approved: false,
11041104
}
11051105
.into();

polkadot/node/core/approval-voting/src/approval_db/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@
3131
//! time being we share the same DB with the rest of Substrate.
3232
3333
pub mod v1;
34+
pub mod v2;

0 commit comments

Comments
 (0)