-
Notifications
You must be signed in to change notification settings - Fork 689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Statement Distribution Per Peer Rate Limit #3444
Merged
Merged
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
1b1ba25
minimal scaffolding
Overkillus 3345aa6
respond task select overhaul
Overkillus 1734c09
test adjustment
Overkillus cb1d210
fmt
Overkillus 58d828d
Rate limit sending from the requester side
Overkillus b5e7e06
sender side rate limiter test
Overkillus 456a466
spammer malus variant
Overkillus 975e3bd
Duplicate requests
Overkillus 7056159
Filtering test
Overkillus 3f234e1
fmt
Overkillus 7e817fa
prdoc
Overkillus 913b234
pipeline
Overkillus e812dcc
increment test
Overkillus c01be29
Merge branch 'master' into mkz-statement-distribution-rate-limit
Overkillus af234ef
crate bump
Overkillus fdaaf4a
clippy nits
Overkillus e988c60
zombienet test simplification
Overkillus 83cf297
review fixes
Overkillus 37fd618
debug -> trace
Overkillus adf84a2
cleanup
Overkillus f0a40d5
metric registered
Overkillus 6099498
reverting paste mistake
Overkillus 07d44ee
registering max parallel requests metric
Overkillus 09e7367
updating metrics in statement distribution respond task
Overkillus d1f50c5
fmt
Overkillus e9680d1
Merge branch 'master' into mkz-statement-distribution-rate-limit
Overkillus 678b141
param typo
Overkillus 7ff1ddd
Bump test numbering
Overkillus f6e8def
remove unused malus param
Overkillus 8e79dc4
tracing
Overkillus a38762b
fmt
Overkillus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
polkadot/node/malus/src/variants/spam_statement_requests.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Polkadot is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! A malicious node variant that attempts spam statement requests. | ||
//! | ||
//! This malus variant behaves honestly in everything except when propagating statement distribution | ||
//! requests through the network bridge subsystem. Instead of sending a single request when it needs | ||
//! something it attempts to spam the peer with multiple requests. | ||
//! | ||
//! Attention: For usage with `zombienet` only! | ||
|
||
#![allow(missing_docs)] | ||
|
||
use polkadot_cli::{ | ||
service::{ | ||
AuxStore, Error, ExtendedOverseerGenArgs, Overseer, OverseerConnector, OverseerGen, | ||
OverseerGenArgs, OverseerHandle, | ||
}, | ||
validator_overseer_builder, Cli, | ||
}; | ||
use polkadot_node_network_protocol::request_response::{outgoing::Requests, OutgoingRequest}; | ||
use polkadot_node_subsystem::{messages::NetworkBridgeTxMessage, SpawnGlue}; | ||
use polkadot_node_subsystem_types::{ChainApiBackend, RuntimeApiSubsystemClient}; | ||
use sp_core::traits::SpawnNamed; | ||
|
||
// Filter wrapping related types. | ||
use crate::{interceptor::*, shared::MALUS}; | ||
|
||
use std::sync::Arc; | ||
|
||
/// Wraps around network bridge and replaces it. | ||
#[derive(Clone)] | ||
struct RequestSpammer<Spawner> { | ||
spawner: Spawner, //stores the actual network bridge subsystem spawner | ||
spam_factor: u32, // How many statement distribution requests to send. | ||
} | ||
|
||
impl<Sender, Spawner> MessageInterceptor<Sender> for RequestSpammer<Spawner> | ||
where | ||
Sender: overseer::NetworkBridgeTxSenderTrait + Clone + Send + 'static, | ||
Spawner: overseer::gen::Spawner + Clone + 'static, | ||
{ | ||
type Message = NetworkBridgeTxMessage; | ||
|
||
/// Intercept NetworkBridgeTxMessage::SendRequests with Requests::AttestedCandidateV2 inside and | ||
/// duplicate that request | ||
fn intercept_incoming( | ||
&self, | ||
_subsystem_sender: &mut Sender, | ||
msg: FromOrchestra<Self::Message>, | ||
) -> Option<FromOrchestra<Self::Message>> { | ||
match msg { | ||
FromOrchestra::Communication { | ||
msg: NetworkBridgeTxMessage::SendRequests(requests, if_disconnected), | ||
} => { | ||
let mut new_requests = Vec::new(); | ||
|
||
for request in requests { | ||
match request { | ||
Requests::AttestedCandidateV2(ref req) => { | ||
// Temporarily store peer and payload for duplication | ||
let peer_to_duplicate = req.peer.clone(); | ||
let payload_to_duplicate = req.payload.clone(); | ||
// Push the original request | ||
new_requests.push(request); | ||
|
||
// Duplicate for spam purposes | ||
gum::info!( | ||
target: MALUS, | ||
"😈 Duplicating AttestedCandidateV2 request extra {:?} times to peer: {:?}.", self.spam_factor, peer_to_duplicate, | ||
); | ||
new_requests.extend((0..self.spam_factor - 1).map(|_| { | ||
let (new_outgoing_request, _) = OutgoingRequest::new( | ||
peer_to_duplicate.clone(), | ||
payload_to_duplicate.clone(), | ||
); | ||
Requests::AttestedCandidateV2(new_outgoing_request) | ||
})); | ||
}, | ||
_ => { | ||
new_requests.push(request); | ||
}, | ||
} | ||
} | ||
|
||
// Passthrough the message with a potentially modified number of requests | ||
Some(FromOrchestra::Communication { | ||
msg: NetworkBridgeTxMessage::SendRequests(new_requests, if_disconnected), | ||
}) | ||
}, | ||
FromOrchestra::Communication { msg } => Some(FromOrchestra::Communication { msg }), | ||
FromOrchestra::Signal(signal) => Some(FromOrchestra::Signal(signal)), | ||
} | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------------- | ||
|
||
#[derive(Debug, clap::Parser)] | ||
#[clap(rename_all = "kebab-case")] | ||
#[allow(missing_docs)] | ||
pub struct SpamStatementRequestsOptions { | ||
/// How many statement distribution requests to send. | ||
#[clap(long, ignore_case = true, default_value_t = 1000, value_parser = clap::value_parser!(u32).range(0..=10000000))] | ||
pub spam_factor: u32, | ||
|
||
#[clap(flatten)] | ||
pub cli: Cli, | ||
} | ||
|
||
/// SpamStatementRequests implementation wrapper which implements `OverseerGen` glue. | ||
pub(crate) struct SpamStatementRequests { | ||
/// How many statement distribution requests to send. | ||
pub spam_factor: u32, | ||
} | ||
|
||
impl OverseerGen for SpamStatementRequests { | ||
fn generate<Spawner, RuntimeClient>( | ||
&self, | ||
connector: OverseerConnector, | ||
args: OverseerGenArgs<'_, Spawner, RuntimeClient>, | ||
ext_args: Option<ExtendedOverseerGenArgs>, | ||
) -> Result<(Overseer<SpawnGlue<Spawner>, Arc<RuntimeClient>>, OverseerHandle), Error> | ||
where | ||
RuntimeClient: RuntimeApiSubsystemClient + ChainApiBackend + AuxStore + 'static, | ||
Spawner: 'static + SpawnNamed + Clone + Unpin, | ||
{ | ||
gum::info!( | ||
target: MALUS, | ||
"😈 Started Malus node that duplicates each statement distribution request spam_factor = {:?} times.", | ||
&self.spam_factor, | ||
); | ||
|
||
let request_spammer = RequestSpammer { | ||
spawner: SpawnGlue(args.spawner.clone()), | ||
spam_factor: self.spam_factor, | ||
}; | ||
|
||
validator_overseer_builder( | ||
args, | ||
ext_args.expect("Extended arguments required to build validator overseer are provided"), | ||
)? | ||
.replace_network_bridge_tx(move |cb| InterceptedSubsystem::new(cb, request_spammer)) | ||
.build_with_connector(connector) | ||
.map_err(|e| e.into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can dedup this line by moving it above the match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is somewhat of a conscious trade-off but if you see a graceful way of doing it feel free to suggest it.
Problem is Request does not implement copy/clone. I could possibly track the index where I push it but this will make it even less readable imo.