Skip to content
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

Remove ProspectiveParachainsMode usage in backing subsystem #6215

Merged
merged 17 commits into from
Nov 18, 2024
Merged
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
399 changes: 91 additions & 308 deletions polkadot/node/core/backing/src/lib.rs

Large diffs are not rendered by default.

2,522 changes: 1,878 additions & 644 deletions polkadot/node/core/backing/src/tests/mod.rs

Large diffs are not rendered by default.

1,745 changes: 0 additions & 1,745 deletions polkadot/node/core/backing/src/tests/prospective_parachains.rs

This file was deleted.

17 changes: 6 additions & 11 deletions polkadot/node/subsystem-util/src/backing_implicit_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ use polkadot_node_subsystem::{
messages::{ChainApiMessage, ProspectiveParachainsMessage, RuntimeApiMessage},
SubsystemSender,
};
use polkadot_primitives::{BlockNumber, Hash, Id as ParaId};
use polkadot_primitives::{AsyncBackingParams, BlockNumber, Hash, Id as ParaId};

use std::collections::HashMap;

use crate::{
inclusion_emulator::RelayChainBlockInfo,
request_session_index_for_child,
runtime::{self, prospective_parachains_mode, recv_runtime, ProspectiveParachainsMode},
request_async_backing_params, request_session_index_for_child,
runtime::{self, recv_runtime},
};

// Always aim to retain 1 block before the active leaves.
Expand Down Expand Up @@ -396,13 +396,8 @@ where
+ SubsystemSender<RuntimeApiMessage>
+ SubsystemSender<ChainApiMessage>,
{
let Ok(ProspectiveParachainsMode::Enabled { allowed_ancestry_len, .. }) =
prospective_parachains_mode(sender, leaf_hash).await
else {
// This should never happen, leaves that don't have prospective parachains mode enabled
// should not use implicit view.
return Ok(None)
};
let AsyncBackingParams { allowed_ancestry_len, .. } =
recv_runtime(request_async_backing_params(leaf_hash, sender).await).await?;

// Fetch the session of the leaf. We must make sure that we stop at the ancestor which has a
// different session index.
Expand All @@ -416,7 +411,7 @@ where
sender
.send_message(ChainApiMessage::Ancestors {
hash: leaf_hash,
k: allowed_ancestry_len,
k: allowed_ancestry_len as usize,
response_channel: tx,
})
.await;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ Subsystem](../disputes/dispute-coordinator.md). Misbehavior reports are currentl
subsystem](../backing/candidate-backing.md) and contain the following misbehaviors:

1. `Misbehavior::ValidityDoubleVote`
2. `Misbehavior::MultipleCandidates`
3. `Misbehavior::UnauthorizedStatement`
4. `Misbehavior::DoubleSign`
2. `Misbehavior::UnauthorizedStatement`
3. `Misbehavior::DoubleSign`

But we choose not to punish these forms of misbehavior for the time being. Risks from misbehavior are sufficiently
mitigated at the protocol level via reputation changes. Punitive actions here may become desirable enough to dedicate
Expand Down
10 changes: 0 additions & 10 deletions polkadot/roadmap/implementers-guide/src/types/overseer-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -697,14 +697,6 @@ mod generic {
Invalidity(Digest, Signature, Signature),
}

/// Misbehavior: declaring multiple candidates.
pub struct MultipleCandidates<Candidate, Signature> {
/// The first candidate seen.
pub first: (Candidate, Signature),
/// The second candidate seen.
pub second: (Candidate, Signature),
}

/// Misbehavior: submitted statement for wrong group.
pub struct UnauthorizedStatement<Candidate, Digest, AuthorityId, Signature> {
/// A signed statement which was submitted without proper authority.
Expand All @@ -714,8 +706,6 @@ mod generic {
pub enum Misbehavior<Candidate, Digest, AuthorityId, Signature> {
/// Voted invalid and valid on validity.
ValidityDoubleVote(ValidityDoubleVote<Candidate, Digest, Signature>),
/// Submitted multiple candidates.
MultipleCandidates(MultipleCandidates<Candidate, Signature>),
/// Submitted a message that was unauthorized.
UnauthorizedStatement(UnauthorizedStatement<Candidate, Digest, AuthorityId, Signature>),
/// Submitted two valid signatures for the same message.
Expand Down
112 changes: 10 additions & 102 deletions polkadot/statement-table/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ pub trait Context {
fn get_group_size(&self, group: &Self::GroupId) -> Option<usize>;
}

/// Table configuration.
pub struct Config {
/// When this is true, the table will allow multiple seconded candidates
/// per authority. This flag means that higher-level code is responsible for
/// bounding the number of candidates.
pub allow_multiple_seconded: bool,
}

/// Statements circulated among peers.
#[derive(PartialEq, Eq, Debug, Clone, Encode, Decode)]
pub enum Statement<Candidate, Digest> {
Expand Down Expand Up @@ -143,15 +135,6 @@ impl<Candidate, Digest, Signature> DoubleSign<Candidate, Digest, Signature> {
}
}

/// Misbehavior: declaring multiple candidates.
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct MultipleCandidates<Candidate, Signature> {
/// The first candidate seen.
pub first: (Candidate, Signature),
/// The second candidate seen.
pub second: (Candidate, Signature),
}

/// Misbehavior: submitted statement for wrong group.
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct UnauthorizedStatement<Candidate, Digest, AuthorityId, Signature> {
Expand All @@ -165,8 +148,6 @@ pub struct UnauthorizedStatement<Candidate, Digest, AuthorityId, Signature> {
pub enum Misbehavior<Candidate, Digest, AuthorityId, Signature> {
/// Voted invalid and valid on validity.
ValidityDoubleVote(ValidityDoubleVote<Candidate, Digest, Signature>),
/// Submitted multiple candidates.
MultipleCandidates(MultipleCandidates<Candidate, Signature>),
/// Submitted a message that was unauthorized.
UnauthorizedStatement(UnauthorizedStatement<Candidate, Digest, AuthorityId, Signature>),
/// Submitted two valid signatures for the same message.
Expand Down Expand Up @@ -300,17 +281,14 @@ pub struct Table<Ctx: Context> {
authority_data: HashMap<Ctx::AuthorityId, AuthorityData<Ctx>>,
detected_misbehavior: HashMap<Ctx::AuthorityId, Vec<MisbehaviorFor<Ctx>>>,
candidate_votes: HashMap<Ctx::Digest, CandidateData<Ctx>>,
config: Config,
}

impl<Ctx: Context> Table<Ctx> {
/// Create a new `Table` from a `Config`.
pub fn new(config: Config) -> Self {
pub fn new() -> Self {
Table {
authority_data: HashMap::default(),
detected_misbehavior: HashMap::default(),
candidate_votes: HashMap::default(),
config,
}
}

Expand Down Expand Up @@ -408,33 +386,7 @@ impl<Ctx: Context> Table<Ctx> {
// if digest is different, fetch candidate and
// note misbehavior.
let existing = occ.get_mut();

if !self.config.allow_multiple_seconded && existing.proposals.len() == 1 {
let (old_digest, old_sig) = &existing.proposals[0];

if old_digest != &digest {
const EXISTENCE_PROOF: &str =
"when proposal first received from authority, candidate \
votes entry is created. proposal here is `Some`, therefore \
candidate votes entry exists; qed";

let old_candidate = self
.candidate_votes
.get(old_digest)
.expect(EXISTENCE_PROOF)
.candidate
.clone();

return Err(Misbehavior::MultipleCandidates(MultipleCandidates {
tdimitrov marked this conversation as resolved.
Show resolved Hide resolved
first: (old_candidate, old_sig.clone()),
second: (candidate, signature.clone()),
}))
}

false
} else if self.config.allow_multiple_seconded &&
existing.proposals.iter().any(|(ref od, _)| od == &digest)
{
if existing.proposals.iter().any(|(ref od, _)| od == &digest) {
false
} else {
existing.proposals.push((digest.clone(), signature.clone()));
Expand Down Expand Up @@ -591,14 +543,6 @@ mod tests {
use super::*;
use std::collections::HashMap;

fn create_single_seconded<Candidate: Context>() -> Table<Candidate> {
Table::new(Config { allow_multiple_seconded: false })
}

fn create_many_seconded<Candidate: Context>() -> Table<Candidate> {
Table::new(Config { allow_multiple_seconded: true })
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
struct AuthorityId(usize);

Expand Down Expand Up @@ -646,42 +590,6 @@ mod tests {
}
}

#[test]
fn submitting_two_candidates_can_be_misbehavior() {
let context = TestContext {
authorities: {
let mut map = HashMap::new();
map.insert(AuthorityId(1), GroupId(2));
map
},
};

let mut table = create_single_seconded();
let statement_a = SignedStatement {
statement: Statement::Seconded(Candidate(2, 100)),
signature: Signature(1),
sender: AuthorityId(1),
};

let statement_b = SignedStatement {
statement: Statement::Seconded(Candidate(2, 999)),
signature: Signature(1),
sender: AuthorityId(1),
};

table.import_statement(&context, GroupId(2), statement_a);
assert!(!table.detected_misbehavior.contains_key(&AuthorityId(1)));

table.import_statement(&context, GroupId(2), statement_b);
assert_eq!(
table.detected_misbehavior[&AuthorityId(1)][0],
Misbehavior::MultipleCandidates(MultipleCandidates {
first: (Candidate(2, 100), Signature(1)),
second: (Candidate(2, 999), Signature(1)),
})
);
}

#[test]
fn submitting_two_candidates_can_be_allowed() {
let context = TestContext {
Expand All @@ -692,7 +600,7 @@ mod tests {
},
};

let mut table = create_many_seconded();
let mut table = Table::new();
let statement_a = SignedStatement {
statement: Statement::Seconded(Candidate(2, 100)),
signature: Signature(1),
Expand Down Expand Up @@ -722,7 +630,7 @@ mod tests {
},
};

let mut table = create_single_seconded();
let mut table = Table::new();
let statement = SignedStatement {
statement: Statement::Seconded(Candidate(2, 100)),
signature: Signature(1),
Expand Down Expand Up @@ -754,7 +662,7 @@ mod tests {
},
};

let mut table = create_single_seconded();
let mut table = Table::new();

let candidate_a = SignedStatement {
statement: Statement::Seconded(Candidate(2, 100)),
Expand Down Expand Up @@ -798,7 +706,7 @@ mod tests {
},
};

let mut table = create_single_seconded();
let mut table = Table::new();
let statement = SignedStatement {
statement: Statement::Seconded(Candidate(2, 100)),
signature: Signature(1),
Expand Down Expand Up @@ -828,7 +736,7 @@ mod tests {
},
};

let mut table = create_single_seconded();
let mut table = Table::new();
let statement = SignedStatement {
statement: Statement::Seconded(Candidate(2, 100)),
signature: Signature(1),
Expand Down Expand Up @@ -896,7 +804,7 @@ mod tests {
};

// have 2/3 validity guarantors note validity.
let mut table = create_single_seconded();
let mut table = Table::new();
let statement = SignedStatement {
statement: Statement::Seconded(Candidate(2, 100)),
signature: Signature(1),
Expand Down Expand Up @@ -930,7 +838,7 @@ mod tests {
},
};

let mut table = create_single_seconded();
let mut table = Table::new();
let statement = SignedStatement {
statement: Statement::Seconded(Candidate(2, 100)),
signature: Signature(1),
Expand All @@ -957,7 +865,7 @@ mod tests {
},
};

let mut table = create_single_seconded();
let mut table = Table::new();
let statement = SignedStatement {
statement: Statement::Seconded(Candidate(2, 100)),
signature: Signature(1),
Expand Down
2 changes: 1 addition & 1 deletion polkadot/statement-table/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

pub mod generic;

pub use generic::{Config, Context, Table};
pub use generic::{Context, Table};

/// Concrete instantiations suitable for v2 primitives.
pub mod v2 {
Expand Down
16 changes: 16 additions & 0 deletions prdoc/pr_6215.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Remove `ProspectiveParachainsMode` from backing subsystem
doc:
- audience: "Node Dev"
description: |
Removes `ProspectiveParachainsMode` usage from the backing subsystem and assumes
`async_backing_params` runtime api is always available. Since the runtime api v7 is released on
all networks it should always be true.

crates:
- name: polkadot-node-core-backing
bump: patch
- name: polkadot-statement-table
bump: major
Loading