Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
62184b4
BEGIN ASYNC candidate-backing CHANGES
rphmeier Apr 28, 2022
821ed42
rename & document modes
rphmeier Apr 29, 2022
1fc4928
answer prospective validation data requests
rphmeier May 18, 2022
39f2076
GetMinimumRelayParents request is now plural
rphmeier May 19, 2022
80af4be
implement an implicit view utility for backing subsystems
rphmeier May 19, 2022
7c58f7a
implicit-view: get allowed relay parents
rphmeier May 23, 2022
fbcedac
refactorings and improvements to implicit view
rphmeier May 23, 2022
126ed91
add some TODOs for tests
rphmeier May 23, 2022
a5994a7
split implicit view updates into 2 functions
rphmeier May 25, 2022
8944760
backing: define State to prepare for functional refactor
rphmeier May 25, 2022
c34d0e6
add some docs
rphmeier May 25, 2022
20cd422
backing: implement bones of new leaf activation logic
rphmeier May 25, 2022
2b7d883
backing: create per-relay-parent-states
rphmeier May 25, 2022
923b28a
use new handle_active_leaves_update
rphmeier May 25, 2022
b9280d1
begin extracting logic from CandidateBackingJob
rphmeier May 27, 2022
967156e
mostly extract statement import from job logic
rphmeier May 27, 2022
b25acb7
handle statement imports outside of job logic
rphmeier May 27, 2022
df95962
do some TODO planning for prospective parachains integration
rphmeier May 27, 2022
458d24d
finish rewriting backing subsystem in functional style
rphmeier May 27, 2022
22a9d5e
add prospective parachains mode to relay parent entries
rphmeier May 27, 2022
fc0c4e4
fmt
rphmeier May 27, 2022
a4df277
add a RejectedByProspectiveParachains error
rphmeier May 27, 2022
2f202d0
notify prospective parachains of seconded and backed candidates
rphmeier May 28, 2022
910b997
always validate candidates exhaustively in backing.
rphmeier May 28, 2022
19d7a43
return persisted_validation_data from validation
rphmeier May 28, 2022
7f24629
handle rejections by prospective parachains
rphmeier May 28, 2022
22ead26
implement seconding sanity check
rphmeier May 28, 2022
6738ee9
invoke validate_and_second
rphmeier May 28, 2022
c54e1ca
Alter statement table to allow multiple seconded messages per validator
rphmeier May 28, 2022
e855b6c
refactor backing to have statements carry PVD
rphmeier May 30, 2022
eb0ee29
clean up all warnings
rphmeier May 30, 2022
d80c190
Add tests for implicit view
slumber May 31, 2022
21a381b
fix per_relay_parent pruning in backing
rphmeier May 31, 2022
47a9832
BEGIN STATEMENT DISTRIBUTION WORK
rphmeier May 31, 2022
b8f5282
mostly make network bridge amenable to vstaging
rphmeier May 31, 2022
843cb7b
network-bridge: fully adapt to vstaging
rphmeier May 31, 2022
89cf386
add some TODOs for tests
rphmeier May 31, 2022
a320e44
fix fallout in bitfield-distribution
rphmeier May 31, 2022
3cc56d1
add some test TODOs
rphmeier May 31, 2022
00f410d
fix fallout in gossip-support
rphmeier May 31, 2022
1a60a0c
fmt
rphmeier May 31, 2022
6f16adf
collator-protocol: fix message fallout
rphmeier May 31, 2022
7e46d8a
collator-protocol: load PVD from runtime
rphmeier May 31, 2022
86007fb
make things compile
rphmeier Jun 2, 2022
faf00f6
fmt
rphmeier Jun 2, 2022
f43c8f6
begin extracting view logic to separate module
rphmeier Jun 2, 2022
759e1d1
create deeper submodule and add per-peer knowledge
rphmeier Jun 2, 2022
51ca0ef
add ProspectiveParachainsMessage to statement-distribution
rphmeier Jun 2, 2022
778627b
make recv_runtime public
rphmeier Jun 2, 2022
df6f7c0
add ChainApiMessage to outgoing of statement-dist
rphmeier Jun 2, 2022
9af0013
begin new handle_active_leaves_update
rphmeier Jun 2, 2022
ce6e3d8
instantiate relay-parent-info without prospective data
rphmeier Jun 2, 2022
5bdb0ec
add staging-network feature to protocol
rphmeier Jun 5, 2022
8c9158a
rename to network-protocol staging
rphmeier Jun 5, 2022
dc6ee0d
refactor view to better accomodate both protcools
rphmeier Jun 5, 2022
a45cb24
begin fleshing out with_prospective
rphmeier Jun 5, 2022
d5e8e88
extract some tests to without_prospective; comment the rest
rphmeier Jun 5, 2022
3a095e6
begin high-level View API
rphmeier Jun 5, 2022
406d87d
fmt
rphmeier Jun 5, 2022
5c8e048
Merge branch 'rh-async-backing-feature' into rh-async-backing-integra…
slumber Jun 22, 2022
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
Prev Previous commit
Next Next commit
Alter statement table to allow multiple seconded messages per validator
  • Loading branch information
rphmeier committed May 28, 2022
commit c54e1ca603ba56c4eac3ff5a4ceb1ce867ea4518
14 changes: 8 additions & 6 deletions node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ use statement_table::{
SignedStatement as TableSignedStatement, Statement as TableStatement,
Summary as TableSummary,
},
Context as TableContextTrait, Table,
Config as TableConfig, Context as TableContextTrait, Table,
};

mod error;
Expand Down Expand Up @@ -1061,6 +1061,12 @@ async fn construct_per_relay_parent_state<Context>(
}

let table_context = TableContext { groups, validators, validator };
let table_config = TableConfig {
allow_multiple_seconded: match mode {
ProspectiveParachainsMode::Enabled => true,
ProspectiveParachainsMode::Disabled => false,
},
};

// TODO [now]: I've removed the `required_collator` more broadly,
// because it's not used in practice and was intended for parathreads.
Expand All @@ -1075,7 +1081,7 @@ async fn construct_per_relay_parent_state<Context>(
session_index,
assignment,
backed: HashSet::new(),
table: Table::default(),
table: Table::new(table_config),
table_context,
issued_statements: HashSet::new(),
awaiting_validation: HashSet::new(),
Expand Down Expand Up @@ -1544,10 +1550,6 @@ async fn import_statement<Context>(

let stmt = primitive_statement_to_table(statement);

// TODO [now]: we violate the pre-existing checks that each validator may
// only second one candidate.
//
// We will need to address this so we don't get errors incorrectly.
let summary = rp_state.table.import_statement(&rp_state.table_context, stmt);

if let Some(attested) = summary
Expand Down
97 changes: 74 additions & 23 deletions statement-table/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ pub trait Context {
fn requisite_votes(&self, group: &Self::GroupId) -> 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 @@ -270,12 +278,12 @@ impl<Ctx: Context> CandidateData<Ctx> {

// authority metadata
struct AuthorityData<Ctx: Context> {
proposal: Option<(Ctx::Digest, Ctx::Signature)>,
proposals: Vec<(Ctx::Digest, Ctx::Signature)>,
}

impl<Ctx: Context> Default for AuthorityData<Ctx> {
fn default() -> Self {
AuthorityData { proposal: None }
AuthorityData { proposals: Vec::new() }
}
}

Expand All @@ -290,19 +298,20 @@ 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> Default for Table<Ctx> {
fn default() -> Self {
impl<Ctx: Context> Table<Ctx> {
/// Create a new `Table` from a `Config`.
pub fn new(config: Config) -> Self {
Table {
authority_data: HashMap::new(),
detected_misbehavior: HashMap::new(),
candidate_votes: HashMap::new(),
authority_data: HashMap::default(),
detected_misbehavior: HashMap::default(),
candidate_votes: HashMap::default(),
config,
}
}
}

impl<Ctx: Context> Table<Ctx> {
/// Get the attested candidate for `digest`.
///
/// Returns `Some(_)` if the candidate exists and is includable.
Expand Down Expand Up @@ -393,7 +402,9 @@ impl<Ctx: Context> Table<Ctx> {
// note misbehavior.
let existing = occ.get_mut();

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

if old_digest != &digest {
const EXISTENCE_PROOF: &str =
"when proposal first received from authority, candidate \
Expand All @@ -413,15 +424,17 @@ impl<Ctx: Context> Table<Ctx> {
}))
}

false
} else if self.config.allow_multiple_seconded && existing.proposals.iter().find(|(ref od, _)| od == &digest).is_some() {
false
} else {
existing.proposal = Some((digest.clone(), signature.clone()));
existing.proposals.push((digest.clone(), signature.clone()));
true
}
},
Entry::Vacant(vacant) => {
vacant
.insert(AuthorityData { proposal: Some((digest.clone(), signature.clone())) });
.insert(AuthorityData { proposals: vec![(digest.clone(), signature.clone())] });
true
},
};
Expand Down Expand Up @@ -571,8 +584,16 @@ mod tests {
use super::*;
use std::collections::HashMap;

fn create<Candidate: Context>() -> Table<Candidate> {
Table::default()
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)]
Expand Down Expand Up @@ -630,7 +651,7 @@ mod tests {
}

#[test]
fn submitting_two_candidates_is_misbehavior() {
fn submitting_two_candidates_can_be_misbehavior() {
let context = TestContext {
authorities: {
let mut map = HashMap::new();
Expand All @@ -639,7 +660,7 @@ mod tests {
},
};

let mut table = create();
let mut table = create_single_seconded();
let statement_a = SignedStatement {
statement: Statement::Seconded(Candidate(2, 100)),
signature: Signature(1),
Expand All @@ -665,6 +686,36 @@ mod tests {
);
}

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

let mut table = create_many_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, statement_a);
assert!(!table.detected_misbehavior.contains_key(&AuthorityId(1)));

table.import_statement(&context, statement_b);
assert!(!table.detected_misbehavior.contains_key(&AuthorityId(1)));
}

#[test]
fn submitting_candidate_from_wrong_group_is_misbehavior() {
let context = TestContext {
Expand All @@ -675,7 +726,7 @@ mod tests {
},
};

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

let mut table = create();
let mut table = create_single_seconded();

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

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

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

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

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

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

pub mod generic;

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

/// Concrete instantiations suitable for v2 primitives.
pub mod v2 {
Expand Down