mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 02:51:08 +00:00
statement-distribution: validator disabling (#1841)
Closes #1591. The purpose of this PR is filter out backing statements from the network signed by disabled validators. This is just an optimization, since we will do filtering in the runtime in #1863 to avoid nodes to filter garbage out at block production time. - [x] Ensure it's ok to fiddle with the mask of manifests - [x] Write more unit tests - [x] Test locally - [x] simple zombienet test - [x] PRDoc --------- Co-authored-by: Tsvetomir Dimitrov <tsvetomir@parity.io>
This commit is contained in:
@@ -30,12 +30,13 @@
|
||||
//! (which requires state not owned by the request manager).
|
||||
|
||||
use super::{
|
||||
BENEFIT_VALID_RESPONSE, BENEFIT_VALID_STATEMENT, COST_IMPROPERLY_DECODED_RESPONSE,
|
||||
COST_INVALID_RESPONSE, COST_INVALID_SIGNATURE, COST_UNREQUESTED_RESPONSE_STATEMENT,
|
||||
REQUEST_RETRY_DELAY,
|
||||
seconded_and_sufficient, BENEFIT_VALID_RESPONSE, BENEFIT_VALID_STATEMENT,
|
||||
COST_IMPROPERLY_DECODED_RESPONSE, COST_INVALID_RESPONSE, COST_INVALID_SIGNATURE,
|
||||
COST_UNREQUESTED_RESPONSE_STATEMENT, REQUEST_RETRY_DELAY,
|
||||
};
|
||||
use crate::LOG_TARGET;
|
||||
|
||||
use bitvec::prelude::{BitVec, Lsb0};
|
||||
use polkadot_node_network_protocol::{
|
||||
request_response::{
|
||||
outgoing::{Recipient as RequestRecipient, RequestError},
|
||||
@@ -495,10 +496,6 @@ fn find_request_target_with_update(
|
||||
}
|
||||
}
|
||||
|
||||
fn seconded_and_sufficient(filter: &StatementFilter, backing_threshold: Option<usize>) -> bool {
|
||||
backing_threshold.map_or(true, |t| filter.has_seconded() && filter.backing_validators() >= t)
|
||||
}
|
||||
|
||||
/// A response to a request, which has not yet been handled.
|
||||
pub struct UnhandledResponse {
|
||||
response: TaggedResponse,
|
||||
@@ -542,6 +539,7 @@ impl UnhandledResponse {
|
||||
session: SessionIndex,
|
||||
validator_key_lookup: impl Fn(ValidatorIndex) -> Option<ValidatorId>,
|
||||
allowed_para_lookup: impl Fn(ParaId, GroupIndex) -> bool,
|
||||
disabled_mask: BitVec<u8, Lsb0>,
|
||||
) -> ResponseValidationOutput {
|
||||
let UnhandledResponse {
|
||||
response: TaggedResponse { identifier, requested_peer, props, response },
|
||||
@@ -625,6 +623,7 @@ impl UnhandledResponse {
|
||||
session,
|
||||
validator_key_lookup,
|
||||
allowed_para_lookup,
|
||||
disabled_mask,
|
||||
);
|
||||
|
||||
if let CandidateRequestStatus::Complete { .. } = output.request_status {
|
||||
@@ -644,6 +643,7 @@ fn validate_complete_response(
|
||||
session: SessionIndex,
|
||||
validator_key_lookup: impl Fn(ValidatorIndex) -> Option<ValidatorId>,
|
||||
allowed_para_lookup: impl Fn(ParaId, GroupIndex) -> bool,
|
||||
disabled_mask: BitVec<u8, Lsb0>,
|
||||
) -> ResponseValidationOutput {
|
||||
let RequestProperties { backing_threshold, mut unwanted_mask } = props;
|
||||
|
||||
@@ -751,6 +751,10 @@ fn validate_complete_response(
|
||||
},
|
||||
}
|
||||
|
||||
if disabled_mask.get(i).map_or(false, |x| *x) {
|
||||
continue
|
||||
}
|
||||
|
||||
let validator_public =
|
||||
match validator_key_lookup(unchecked_statement.unchecked_validator_index()) {
|
||||
None => {
|
||||
@@ -1013,6 +1017,7 @@ mod tests {
|
||||
let group = &[ValidatorIndex(0), ValidatorIndex(1), ValidatorIndex(2)];
|
||||
|
||||
let unwanted_mask = StatementFilter::blank(group_size);
|
||||
let disabled_mask: BitVec<u8, Lsb0> = Default::default();
|
||||
let request_properties = RequestProperties { unwanted_mask, backing_threshold: None };
|
||||
|
||||
// Get requests.
|
||||
@@ -1056,6 +1061,7 @@ mod tests {
|
||||
0,
|
||||
validator_key_lookup,
|
||||
allowed_para_lookup,
|
||||
disabled_mask.clone(),
|
||||
);
|
||||
assert_eq!(
|
||||
output,
|
||||
@@ -1094,6 +1100,7 @@ mod tests {
|
||||
0,
|
||||
validator_key_lookup,
|
||||
allowed_para_lookup,
|
||||
disabled_mask,
|
||||
);
|
||||
assert_eq!(
|
||||
output,
|
||||
@@ -1167,12 +1174,14 @@ mod tests {
|
||||
};
|
||||
let validator_key_lookup = |_v| None;
|
||||
let allowed_para_lookup = |_para, _g_index| true;
|
||||
let disabled_mask: BitVec<u8, Lsb0> = Default::default();
|
||||
let output = response.validate_response(
|
||||
&mut request_manager,
|
||||
group,
|
||||
0,
|
||||
validator_key_lookup,
|
||||
allowed_para_lookup,
|
||||
disabled_mask,
|
||||
);
|
||||
assert_eq!(
|
||||
output,
|
||||
@@ -1245,12 +1254,14 @@ mod tests {
|
||||
let validator_key_lookup = |_v| None;
|
||||
let allowed_para_lookup = |_para, _g_index| true;
|
||||
let statements = vec![];
|
||||
let disabled_mask: BitVec<u8, Lsb0> = Default::default();
|
||||
let output = response.validate_response(
|
||||
&mut request_manager,
|
||||
group,
|
||||
0,
|
||||
validator_key_lookup,
|
||||
allowed_para_lookup,
|
||||
disabled_mask,
|
||||
);
|
||||
assert_eq!(
|
||||
output,
|
||||
|
||||
Reference in New Issue
Block a user