Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Malus: Implement storing invalid chunks #4711

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion node/malus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ polkadot-node-core-backing = { path = "../core/backing" }
polkadot-node-primitives = { path = "../primitives" }
polkadot-primitives = { path = "../../primitives" }
polkadot-node-core-pvf = { path = "../core/pvf" }
polkadot-node-core-av-store = { path = "../core/av-store" }
parity-util-mem = { version = "0.10.0", default-features = false, features = ["jemalloc-global"] }
parity-scale-codec = { version = "2.3.1", features = ["derive"] }
color-eyre = { version = "0.5.11", default-features = false }
assert_matches = "1.5"
async-trait = "0.1.52"
Expand All @@ -32,11 +34,14 @@ clap = { version = "3.0", features = ["derive"] }
futures = "0.3.19"
futures-timer = "3.0.2"
tracing = "0.1.26"
bitvec = "0.20.1"
kvdb = "0.10.0"
erasure = { package = "polkadot-erasure-coding", path = "../../erasure-coding" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }

[features]
default = []

[dev-dependencies]
polkadot-node-subsystem-test-helpers = { path = "../subsystem-test-helpers" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
futures = { version = "0.3.19", features = ["thread-pool"] }
10 changes: 5 additions & 5 deletions node/malus/src/malus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ use variants::*;
#[clap(about = "Malus - the nemesis of polkadot.", version)]
#[clap(rename_all = "kebab-case")]
enum NemesisVariant {
/// Store garbage chunks in the availability store
StoreMaliciousAvailableData(RunCmd),
/// Suggest a candidate with an invalid proof of validity.
SuggestGarbageCandidate(RunCmd),
/// Back a candidate with a specifically crafted proof of validity.
BackGarbageCandidate(RunCmd),
/// Delayed disputing of ancestors that are perfectly fine.
DisputeAncestor(RunCmd),

Expand Down Expand Up @@ -63,10 +63,10 @@ impl MalusCli {
/// Launch a malus node.
fn launch(self) -> eyre::Result<()> {
match self.variant {
NemesisVariant::BackGarbageCandidate(cmd) =>
polkadot_cli::run_node(run_cmd(cmd), BackGarbageCandidate)?,
NemesisVariant::StoreMaliciousAvailableData(cmd) =>
polkadot_cli::run_node(run_cmd(cmd), StoreMaliciousAvailableDataWrapper)?,
NemesisVariant::SuggestGarbageCandidate(cmd) =>
polkadot_cli::run_node(run_cmd(cmd), SuggestGarbageCandidate)?,
polkadot_cli::run_node(run_cmd(cmd), BackGarbageCandidateWrapper)?,
Comment on lines +66 to +69
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to maybe combine these eventually? So we can run tests with malicious stored available data and dispute valid candidates for example.

NemesisVariant::DisputeAncestor(cmd) =>
polkadot_cli::run_node(run_cmd(cmd), DisputeValidCandidates)?,
NemesisVariant::PvfPrepareWorker(cmd) => {
Expand Down
12 changes: 8 additions & 4 deletions node/malus/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use super::*;

use polkadot_node_subsystem_test_helpers::*;

use polkadot_node_subsystem::{
messages::{AllMessages, AvailabilityStoreMessage},
overseer::{dummy::DummySubsystem, gen::TimeoutExt, Subsystem},
overseer::{self, dummy::DummySubsystem, gen::TimeoutExt, OverseerSignal, Subsystem},
SubsystemError,
};

use futures::Future;

// Filter wrapping related types.
use crate::interceptor::*;

#[derive(Clone, Debug)]
struct BlackHoleInterceptor;

Expand Down Expand Up @@ -131,7 +134,8 @@ fn integrity_test_pass() {
AvailabilityStoreMessage::QueryChunk(Default::default(), 0.into(), tx),
)
.await;
let _ = rx.timeout(std::time::Duration::from_millis(100)).await.unwrap();
let resp = rx.timeout(std::time::Duration::from_secs(10)).await.unwrap();
println!("RESP {:?}", resp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add these as logs ?

overseer
},
sub_intercepted,
Expand Down
11 changes: 1 addition & 10 deletions node/malus/src/variants/dispute_valid_candidates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ use crate::interceptor::*;

// Import extra types relevant to the particular
// subsystem.
use polkadot_node_core_backing::CandidateBackingSubsystem;
use polkadot_node_subsystem::messages::{
ApprovalDistributionMessage, CandidateBackingMessage, DisputeCoordinatorMessage,
};
use sp_keystore::SyncCryptoStorePtr;

use std::sync::Arc;

Expand Down Expand Up @@ -104,17 +102,10 @@ impl OverseerGen for DisputeValidCandidates {
RuntimeClient::Api: ParachainHost<Block> + BabeApi<Block> + AuthorityDiscoveryApi<Block>,
Spawner: 'static + SpawnNamed + Clone + Unpin,
{
let spawner = args.spawner.clone();
let crypto_store_ptr = args.keystore.clone() as SyncCryptoStorePtr;
let filter = ReplaceApprovalsWithDisputes;

prepared_overseer_builder(args)?
.replace_candidate_backing(move |cb| {
InterceptedSubsystem::new(
CandidateBackingSubsystem::new(spawner, crypto_store_ptr, cb.params.metrics),
filter,
)
})
.replace_candidate_backing(move |cb| InterceptedSubsystem::new(cb, filter))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

.build_with_connector(connector)
.map_err(|e| e.into())
}
Expand Down
6 changes: 4 additions & 2 deletions node/malus/src/variants/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

mod back_garbage_candidate;
mod dispute_valid_candidates;
mod store_malicious_available_data;
mod suggest_garbage_candidate;

pub(crate) use self::{
back_garbage_candidate::BackGarbageCandidate, dispute_valid_candidates::DisputeValidCandidates,
suggest_garbage_candidate::SuggestGarbageCandidate,
dispute_valid_candidates::DisputeValidCandidates,
store_malicious_available_data::StoreMaliciousAvailableDataWrapper,
suggest_garbage_candidate::BackGarbageCandidateWrapper,
};
Loading