Skip to content

Commit

Permalink
Remove unused
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiEres committed Sep 23, 2024
1 parent 1b28f37 commit 7989ec9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 51 deletions.
2 changes: 0 additions & 2 deletions polkadot/node/malus/src/variants/back_garbage_candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ impl OverseerGen for BackGarbageCandidates {
RuntimeClient: RuntimeApiSubsystemClient + ChainApiBackend + AuxStore + 'static,
Spawner: 'static + SpawnNamed + Clone + Unpin,
{
let spawner = args.spawner.clone();
let validation_filter = ReplaceValidationResult::new(
FakeCandidateValidation::BackingAndApprovalValid,
FakeCandidateValidationError::InvalidOutputs,
f64::from(self.percentage),
SpawnGlue(spawner),
);

validator_overseer_builder(
Expand Down
52 changes: 6 additions & 46 deletions polkadot/node/malus/src/variants/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::{
shared::{MALICIOUS_POV, MALUS},
};

use polkadot_node_core_candidate_validation::find_validation_data;
use polkadot_node_primitives::{InvalidCandidate, ValidationResult};

use polkadot_primitives::{
Expand Down Expand Up @@ -149,59 +148,21 @@ impl Into<InvalidCandidate> for FakeCandidateValidationError {
#[derive(Clone, Debug)]
/// An interceptor which fakes validation result with a preconfigured result.
/// Replaces `CandidateValidationSubsystem`.
pub struct ReplaceValidationResult<Spawner> {
pub struct ReplaceValidationResult {
fake_validation: FakeCandidateValidation,
fake_validation_error: FakeCandidateValidationError,
distribution: Bernoulli,
spawner: Spawner,
}

impl<Spawner> ReplaceValidationResult<Spawner>
where
Spawner: overseer::gen::Spawner,
{
impl ReplaceValidationResult {
pub fn new(
fake_validation: FakeCandidateValidation,
fake_validation_error: FakeCandidateValidationError,
percentage: f64,
spawner: Spawner,
) -> Self {
let distribution = Bernoulli::new(percentage / 100.0)
.expect("Invalid probability! Percentage must be in range [0..=100].");
Self { fake_validation, fake_validation_error, distribution, spawner }
}

/// Creates and sends the validation response for a given candidate. Queries the runtime to
/// obtain the validation data for the given candidate.
pub fn send_validation_response<Sender>(
&self,
candidate_descriptor: CandidateDescriptor,
subsystem_sender: Sender,
response_sender: oneshot::Sender<Result<ValidationResult, ValidationFailed>>,
) where
Sender: overseer::CandidateValidationSenderTrait + Clone + Send + 'static,
{
let _candidate_descriptor = candidate_descriptor.clone();
let mut subsystem_sender = subsystem_sender.clone();
let (sender, receiver) = std::sync::mpsc::channel();
self.spawner.spawn_blocking(
"malus-get-validation-data",
Some("malus"),
Box::pin(async move {
match find_validation_data(&mut subsystem_sender, &_candidate_descriptor).await {
Ok(Some((validation_data, validation_code))) => {
sender
.send((validation_data, validation_code))
.expect("channel is still open");
},
_ => {
panic!("Unable to fetch validation data");
},
}
}),
);
let (validation_data, _) = receiver.recv().unwrap();
create_validation_response(validation_data, candidate_descriptor, response_sender);
Self { fake_validation, fake_validation_error, distribution }
}
}

Expand Down Expand Up @@ -251,18 +212,17 @@ fn create_validation_response(
response_sender.send(result).unwrap();
}

impl<Sender, Spawner> MessageInterceptor<Sender> for ReplaceValidationResult<Spawner>
impl<Sender> MessageInterceptor<Sender> for ReplaceValidationResult
where
Sender: overseer::CandidateValidationSenderTrait + Clone + Send + 'static,
Spawner: overseer::gen::Spawner + Clone + 'static,
{
type Message = CandidateValidationMessage;

// Capture all (approval and backing) candidate validation requests and depending on
// configuration fail them.
fn intercept_incoming(
&self,
subsystem_sender: &mut Sender,
_subsystem_sender: &mut Sender,
msg: FromOrchestra<Self::Message>,
) -> Option<FromOrchestra<Self::Message>> {
match msg {
Expand Down Expand Up @@ -343,7 +303,7 @@ where
match behave_maliciously {
true => {
let validation_result =
ValidationResult::Invalid(InvalidCandidate::InvalidOutputs);
ValidationResult::Invalid(self.fake_validation_error.into());

gum::info!(
target: MALUS,
Expand Down
2 changes: 0 additions & 2 deletions polkadot/node/malus/src/variants/dispute_valid_candidates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,10 @@ impl OverseerGen for DisputeValidCandidates {
RuntimeClient: RuntimeApiSubsystemClient + ChainApiBackend + AuxStore + 'static,
Spawner: 'static + SpawnNamed + Clone + Unpin,
{
let spawner = args.spawner.clone();
let validation_filter = ReplaceValidationResult::new(
self.fake_validation,
self.fake_validation_error,
f64::from(self.percentage),
SpawnGlue(spawner.clone()),
);

validator_overseer_builder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ impl OverseerGen for SuggestGarbageCandidates {
FakeCandidateValidation::BackingAndApprovalValid,
FakeCandidateValidationError::InvalidOutputs,
fake_valid_probability,
SpawnGlue(args.spawner.clone()),
);

validator_overseer_builder(
Expand Down

0 comments on commit 7989ec9

Please sign in to comment.