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>:
https://github.com/paritytech/polkadot/pull/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 <andrei-mihail@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
This commit is contained in:
Andrei Sandu
2023-11-06 15:21:32 +02:00
committed by GitHub
parent 4ac9c4a364
commit 0570b6fa9e
55 changed files with 5643 additions and 1799 deletions
+122 -5
View File
@@ -28,23 +28,129 @@ use sc_network::{
};
use polkadot_node_network_protocol::{
peer_set::{PeerSet, PeerSetProtocolNames, ProtocolVersion},
peer_set::{
CollationVersion, PeerSet, PeerSetProtocolNames, ProtocolVersion, ValidationVersion,
},
request_response::{OutgoingRequest, Recipient, ReqProtocolNames, Requests},
PeerId,
v1 as protocol_v1, v2 as protocol_v2, vstaging as protocol_vstaging, PeerId,
};
use polkadot_primitives::{AuthorityDiscoveryId, Block, Hash};
use crate::validator_discovery::AuthorityDiscovery;
use crate::{metrics::Metrics, validator_discovery::AuthorityDiscovery, WireMessage};
// network bridge network abstraction log target
const LOG_TARGET: &'static str = "parachain::network-bridge-net";
/// Send a message to the network.
// Helper function to send a validation v1 message to a list of peers.
// Messages are always sent via the main protocol, even legacy protocol messages.
pub(crate) fn send_validation_message_v1(
net: &mut impl Network,
peers: Vec<PeerId>,
peerset_protocol_names: &PeerSetProtocolNames,
message: WireMessage<protocol_v1::ValidationProtocol>,
metrics: &Metrics,
) {
gum::trace!(target: LOG_TARGET, ?peers, ?message, "Sending validation v1 message to peers",);
send_message(
net,
peers,
PeerSet::Validation,
ValidationVersion::V1.into(),
peerset_protocol_names,
message,
metrics,
);
}
// Helper function to send a validation vstaging message to a list of peers.
// Messages are always sent via the main protocol, even legacy protocol messages.
pub(crate) fn send_validation_message_vstaging(
net: &mut impl Network,
peers: Vec<PeerId>,
peerset_protocol_names: &PeerSetProtocolNames,
message: WireMessage<protocol_vstaging::ValidationProtocol>,
metrics: &Metrics,
) {
gum::trace!(target: LOG_TARGET, ?peers, ?message, "Sending validation vstaging message to peers",);
send_message(
net,
peers,
PeerSet::Validation,
ValidationVersion::VStaging.into(),
peerset_protocol_names,
message,
metrics,
);
}
// Helper function to send a validation v2 message to a list of peers.
// Messages are always sent via the main protocol, even legacy protocol messages.
pub(crate) fn send_validation_message_v2(
net: &mut impl Network,
peers: Vec<PeerId>,
protocol_names: &PeerSetProtocolNames,
message: WireMessage<protocol_v2::ValidationProtocol>,
metrics: &Metrics,
) {
send_message(
net,
peers,
PeerSet::Validation,
ValidationVersion::V2.into(),
protocol_names,
message,
metrics,
);
}
// Helper function to send a collation v1 message to a list of peers.
// Messages are always sent via the main protocol, even legacy protocol messages.
pub(crate) fn send_collation_message_v1(
net: &mut impl Network,
peers: Vec<PeerId>,
peerset_protocol_names: &PeerSetProtocolNames,
message: WireMessage<protocol_v1::CollationProtocol>,
metrics: &Metrics,
) {
send_message(
net,
peers,
PeerSet::Collation,
CollationVersion::V1.into(),
peerset_protocol_names,
message,
metrics,
);
}
// Helper function to send a collation v2 message to a list of peers.
// Messages are always sent via the main protocol, even legacy protocol messages.
pub(crate) fn send_collation_message_v2(
net: &mut impl Network,
peers: Vec<PeerId>,
peerset_protocol_names: &PeerSetProtocolNames,
message: WireMessage<protocol_v2::CollationProtocol>,
metrics: &Metrics,
) {
send_message(
net,
peers,
PeerSet::Collation,
CollationVersion::V2.into(),
peerset_protocol_names,
message,
metrics,
);
}
/// Lower level function that sends a message to the network using the main protocol version.
///
/// This function is only used internally by the network-bridge, which is responsible to only send
/// messages that are compatible with the passed peer set, as that is currently not enforced by
/// this function. These are messages of type `WireMessage` parameterized on the matching type.
pub(crate) fn send_message<M>(
fn send_message<M>(
net: &mut impl Network,
mut peers: Vec<PeerId>,
peer_set: PeerSet,
@@ -65,6 +171,17 @@ pub(crate) fn send_message<M>(
encoded
};
// optimization: generate the protocol name once.
let protocol_name = protocol_names.get_name(peer_set, version);
gum::trace!(
target: LOG_TARGET,
?peers,
?version,
?protocol_name,
?message,
"Sending message to peers",
);
// optimization: avoid cloning the message for the last peer in the
// list. The message payload can be quite large. If the underlying
// network used `Bytes` this would not be necessary.
+57 -98
View File
@@ -21,6 +21,7 @@ use super::*;
use always_assert::never;
use bytes::Bytes;
use futures::stream::{BoxStream, StreamExt};
use net_protocol::filter_by_peer_version;
use parity_scale_codec::{Decode, DecodeAll};
use sc_network::Event as NetworkEvent;
@@ -33,8 +34,8 @@ use polkadot_node_network_protocol::{
CollationVersion, PeerSet, PeerSetProtocolNames, PerPeerSet, ProtocolVersion,
ValidationVersion,
},
v1 as protocol_v1, v2 as protocol_v2, ObservedRole, OurView, PeerId,
UnifiedReputationChange as Rep, View,
v1 as protocol_v1, v2 as protocol_v2, vstaging as protocol_vstaging, ObservedRole, OurView,
PeerId, UnifiedReputationChange as Rep, View,
};
use polkadot_node_subsystem::{
@@ -64,9 +65,11 @@ use super::validator_discovery;
/// Actual interfacing to the network based on the `Network` trait.
///
/// Defines the `Network` trait with an implementation for an `Arc<NetworkService>`.
use crate::network::{send_message, Network};
use crate::network::get_peer_id_by_authority_id;
use crate::network::{
send_collation_message_v1, send_collation_message_v2, send_validation_message_v1,
send_validation_message_v2, send_validation_message_vstaging, Network,
};
use crate::{network::get_peer_id_by_authority_id, WireMessage};
use super::metrics::Metrics;
@@ -251,22 +254,27 @@ where
match ValidationVersion::try_from(version)
.expect("try_get_protocol has already checked version is known; qed")
{
ValidationVersion::V1 => send_message(
ValidationVersion::V1 => send_validation_message_v1(
&mut network_service,
vec![peer],
PeerSet::Validation,
version,
&peerset_protocol_names,
WireMessage::<protocol_v1::ValidationProtocol>::ViewUpdate(
local_view,
),
&metrics,
),
ValidationVersion::V2 => send_message(
ValidationVersion::VStaging => send_validation_message_vstaging(
&mut network_service,
vec![peer],
&peerset_protocol_names,
WireMessage::<protocol_vstaging::ValidationProtocol>::ViewUpdate(
local_view,
),
&metrics,
),
ValidationVersion::V2 => send_validation_message_v2(
&mut network_service,
vec![peer],
PeerSet::Validation,
version,
&peerset_protocol_names,
WireMessage::<protocol_v2::ValidationProtocol>::ViewUpdate(
local_view,
@@ -293,22 +301,18 @@ where
match CollationVersion::try_from(version)
.expect("try_get_protocol has already checked version is known; qed")
{
CollationVersion::V1 => send_message(
CollationVersion::V1 => send_collation_message_v1(
&mut network_service,
vec![peer],
PeerSet::Collation,
version,
&peerset_protocol_names,
WireMessage::<protocol_v1::CollationProtocol>::ViewUpdate(
local_view,
),
&metrics,
),
CollationVersion::V2 => send_message(
CollationVersion::V2 => send_collation_message_v2(
&mut network_service,
vec![peer],
PeerSet::Collation,
version,
&peerset_protocol_names,
WireMessage::<protocol_v2::CollationProtocol>::ViewUpdate(
local_view,
@@ -386,8 +390,16 @@ where
.filter_map(|(protocol, msg_bytes)| {
// version doesn't matter because we always receive on the 'correct'
// protocol name, not the negotiated fallback.
let (peer_set, _version) =
let (peer_set, version) =
peerset_protocol_names.try_get_protocol(protocol)?;
gum::trace!(
target: LOG_TARGET,
?peer_set,
?protocol,
?version,
"Received notification"
);
if peer_set == PeerSet::Validation {
if expected_versions[PeerSet::Validation].is_none() {
return Some(Err(UNCONNECTED_PEERSET_COST))
@@ -474,6 +486,16 @@ where
v_messages,
&metrics,
)
} else if expected_versions[PeerSet::Validation] ==
Some(ValidationVersion::VStaging.into())
{
handle_peer_messages::<protocol_vstaging::ValidationProtocol, _>(
remote,
PeerSet::Validation,
&mut shared.0.lock().validation_peers,
v_messages,
&metrics,
)
} else {
gum::warn!(
target: LOG_TARGET,
@@ -815,15 +837,16 @@ fn update_our_view<Net, Context>(
)
};
let filter_by_version = |peers: &[(PeerId, ProtocolVersion)], version| {
peers.iter().filter(|(_, v)| v == &version).map(|(p, _)| *p).collect::<Vec<_>>()
};
let v1_validation_peers =
filter_by_peer_version(&validation_peers, ValidationVersion::V1.into());
let v1_collation_peers = filter_by_peer_version(&collation_peers, CollationVersion::V1.into());
let v1_validation_peers = filter_by_version(&validation_peers, ValidationVersion::V1.into());
let v1_collation_peers = filter_by_version(&collation_peers, CollationVersion::V1.into());
let v2_validation_peers =
filter_by_peer_version(&validation_peers, ValidationVersion::V2.into());
let v2_collation_peers = filter_by_peer_version(&collation_peers, CollationVersion::V2.into());
let v2_validation_peers = filter_by_version(&validation_peers, ValidationVersion::V2.into());
let v2_collation_peers = filter_by_version(&collation_peers, ValidationVersion::V2.into());
let vstaging_validation_peers =
filter_by_peer_version(&validation_peers, ValidationVersion::VStaging.into());
send_validation_message_v1(
net,
@@ -853,7 +876,15 @@ fn update_our_view<Net, Context>(
net,
v2_collation_peers,
peerset_protocol_names,
WireMessage::ViewUpdate(new_view),
WireMessage::ViewUpdate(new_view.clone()),
metrics,
);
send_validation_message_vstaging(
net,
vstaging_validation_peers,
peerset_protocol_names,
WireMessage::ViewUpdate(new_view.clone()),
metrics,
);
@@ -926,78 +957,6 @@ fn handle_peer_messages<RawMessage: Decode, OutMessage: From<RawMessage>>(
(outgoing_events, reports)
}
fn send_validation_message_v1(
net: &mut impl Network,
peers: Vec<PeerId>,
peerset_protocol_names: &PeerSetProtocolNames,
message: WireMessage<protocol_v1::ValidationProtocol>,
metrics: &Metrics,
) {
send_message(
net,
peers,
PeerSet::Validation,
ValidationVersion::V1.into(),
peerset_protocol_names,
message,
metrics,
);
}
fn send_collation_message_v1(
net: &mut impl Network,
peers: Vec<PeerId>,
peerset_protocol_names: &PeerSetProtocolNames,
message: WireMessage<protocol_v1::CollationProtocol>,
metrics: &Metrics,
) {
send_message(
net,
peers,
PeerSet::Collation,
CollationVersion::V1.into(),
peerset_protocol_names,
message,
metrics,
);
}
fn send_validation_message_v2(
net: &mut impl Network,
peers: Vec<PeerId>,
protocol_names: &PeerSetProtocolNames,
message: WireMessage<protocol_v2::ValidationProtocol>,
metrics: &Metrics,
) {
send_message(
net,
peers,
PeerSet::Validation,
ValidationVersion::V2.into(),
protocol_names,
message,
metrics,
);
}
fn send_collation_message_v2(
net: &mut impl Network,
peers: Vec<PeerId>,
protocol_names: &PeerSetProtocolNames,
message: WireMessage<protocol_v2::CollationProtocol>,
metrics: &Metrics,
) {
send_message(
net,
peers,
PeerSet::Collation,
CollationVersion::V2.into(),
protocol_names,
message,
metrics,
);
}
async fn dispatch_validation_event_to_all(
event: NetworkBridgeEvent<net_protocol::VersionedValidationProtocol>,
ctx: &mut impl overseer::NetworkBridgeRxSenderTrait,
@@ -1248,6 +1248,9 @@ fn network_protocol_versioning_view_update() {
ValidationVersion::V2 =>
WireMessage::<protocol_v2::ValidationProtocol>::ViewUpdate(view.clone())
.encode(),
ValidationVersion::VStaging =>
WireMessage::<protocol_vstaging::ValidationProtocol>::ViewUpdate(view.clone())
.encode(),
};
assert_network_actions_contains(
&actions,
+23 -78
View File
@@ -18,9 +18,7 @@
use super::*;
use polkadot_node_network_protocol::{
peer_set::{CollationVersion, PeerSet, PeerSetProtocolNames, ValidationVersion},
request_response::ReqProtocolNames,
v1 as protocol_v1, v2 as protocol_v2, PeerId, Versioned,
peer_set::PeerSetProtocolNames, request_response::ReqProtocolNames, Versioned,
};
use polkadot_node_subsystem::{
@@ -41,7 +39,10 @@ use crate::validator_discovery;
/// Actual interfacing to the network based on the `Network` trait.
///
/// Defines the `Network` trait with an implementation for an `Arc<NetworkService>`.
use crate::network::{send_message, Network};
use crate::network::{
send_collation_message_v1, send_collation_message_v2, send_validation_message_v1,
send_validation_message_v2, send_validation_message_vstaging, Network,
};
use crate::metrics::Metrics;
@@ -187,6 +188,7 @@ where
gum::trace!(
target: LOG_TARGET,
action = "SendValidationMessages",
?msg,
num_messages = 1usize,
);
@@ -198,6 +200,13 @@ where
WireMessage::ProtocolMessage(msg),
&metrics,
),
Versioned::VStaging(msg) => send_validation_message_vstaging(
&mut network_service,
peers,
peerset_protocol_names,
WireMessage::ProtocolMessage(msg),
&metrics,
),
Versioned::V2(msg) => send_validation_message_v2(
&mut network_service,
peers,
@@ -212,6 +221,7 @@ where
target: LOG_TARGET,
action = "SendValidationMessages",
num_messages = %msgs.len(),
?msgs,
);
for (peers, msg) in msgs {
@@ -223,6 +233,13 @@ where
WireMessage::ProtocolMessage(msg),
&metrics,
),
Versioned::VStaging(msg) => send_validation_message_vstaging(
&mut network_service,
peers,
peerset_protocol_names,
WireMessage::ProtocolMessage(msg),
&metrics,
),
Versioned::V2(msg) => send_validation_message_v2(
&mut network_service,
peers,
@@ -248,7 +265,7 @@ where
WireMessage::ProtocolMessage(msg),
&metrics,
),
Versioned::V2(msg) => send_collation_message_v2(
Versioned::V2(msg) | Versioned::VStaging(msg) => send_collation_message_v2(
&mut network_service,
peers,
peerset_protocol_names,
@@ -273,7 +290,7 @@ where
WireMessage::ProtocolMessage(msg),
&metrics,
),
Versioned::V2(msg) => send_collation_message_v2(
Versioned::V2(msg) | Versioned::VStaging(msg) => send_collation_message_v2(
&mut network_service,
peers,
peerset_protocol_names,
@@ -386,75 +403,3 @@ where
Ok(())
}
fn send_validation_message_v1(
net: &mut impl Network,
peers: Vec<PeerId>,
protocol_names: &PeerSetProtocolNames,
message: WireMessage<protocol_v1::ValidationProtocol>,
metrics: &Metrics,
) {
send_message(
net,
peers,
PeerSet::Validation,
ValidationVersion::V1.into(),
protocol_names,
message,
metrics,
);
}
fn send_collation_message_v1(
net: &mut impl Network,
peers: Vec<PeerId>,
protocol_names: &PeerSetProtocolNames,
message: WireMessage<protocol_v1::CollationProtocol>,
metrics: &Metrics,
) {
send_message(
net,
peers,
PeerSet::Collation,
CollationVersion::V1.into(),
protocol_names,
message,
metrics,
);
}
fn send_validation_message_v2(
net: &mut impl Network,
peers: Vec<PeerId>,
protocol_names: &PeerSetProtocolNames,
message: WireMessage<protocol_v2::ValidationProtocol>,
metrics: &Metrics,
) {
send_message(
net,
peers,
PeerSet::Validation,
ValidationVersion::V2.into(),
protocol_names,
message,
metrics,
);
}
fn send_collation_message_v2(
net: &mut impl Network,
peers: Vec<PeerId>,
protocol_names: &PeerSetProtocolNames,
message: WireMessage<protocol_v2::CollationProtocol>,
metrics: &Metrics,
) {
send_message(
net,
peers,
PeerSet::Collation,
CollationVersion::V2.into(),
protocol_names,
message,
metrics,
);
}
+2 -3
View File
@@ -25,9 +25,9 @@ use std::collections::HashSet;
use sc_network::{Event as NetworkEvent, IfDisconnected, ProtocolName, ReputationChange};
use polkadot_node_network_protocol::{
peer_set::PeerSetProtocolNames,
peer_set::{PeerSetProtocolNames, ValidationVersion},
request_response::{outgoing::Requests, ReqProtocolNames},
ObservedRole, Versioned,
v1 as protocol_v1, v2 as protocol_v2, ObservedRole, Versioned,
};
use polkadot_node_subsystem::{FromOrchestra, OverseerSignal};
use polkadot_node_subsystem_test_helpers::TestSubsystemContextHandle;
@@ -356,7 +356,6 @@ fn network_protocol_versioning_send() {
}
// send a validation protocol message.
{
let approval_distribution_message =
protocol_v2::ApprovalDistributionMessage::Approvals(Vec::new());