From 5137d1a1d0f97767f4d65c1208d7b9875127cf6f Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Tue, 16 Jan 2018 20:04:32 +0100 Subject: [PATCH] validator -> authority --- .../src/bft/accumulator.rs | 84 +++--- substrate/candidate-agreement/src/bft/mod.rs | 28 +- .../candidate-agreement/src/bft/tests.rs | 26 +- .../src/handle_incoming.rs | 8 +- substrate/candidate-agreement/src/lib.rs | 66 ++--- substrate/candidate-agreement/src/table.rs | 258 +++++++++--------- .../candidate-agreement/src/tests/mod.rs | 34 +-- 7 files changed, 252 insertions(+), 252 deletions(-) diff --git a/substrate/candidate-agreement/src/bft/accumulator.rs b/substrate/candidate-agreement/src/bft/accumulator.rs index 3e46c0c311..ab035737fb 100644 --- a/substrate/candidate-agreement/src/bft/accumulator.rs +++ b/substrate/candidate-agreement/src/bft/accumulator.rs @@ -117,37 +117,37 @@ struct VoteCounts { /// Accumulates messages for a given round of BFT consensus. /// -/// This isn't tied to the "view" of a single validator. It +/// This isn't tied to the "view" of a single authority. It /// keeps accurate track of the state of the BFT consensus based /// on all messages imported. #[derive(Debug)] -pub struct Accumulator +pub struct Accumulator where Candidate: Eq + Clone, Digest: Hash + Eq + Clone, - ValidatorId: Hash + Eq, + AuthorityId: Hash + Eq, Signature: Eq + Clone, { round_number: usize, threshold: usize, - round_proposer: ValidatorId, + round_proposer: AuthorityId, proposal: Option, - prepares: HashMap, - commits: HashMap, + prepares: HashMap, + commits: HashMap, vote_counts: HashMap, - advance_round: HashSet, + advance_round: HashSet, state: State, } -impl Accumulator +impl Accumulator where Candidate: Eq + Clone, Digest: Hash + Eq + Clone, - ValidatorId: Hash + Eq, + AuthorityId: Hash + Eq, Signature: Eq + Clone, { /// Create a new state accumulator. - pub fn new(round_number: usize, threshold: usize, round_proposer: ValidatorId) -> Self { + pub fn new(round_number: usize, threshold: usize, round_proposer: AuthorityId) -> Self { Accumulator { round_number, threshold, @@ -184,7 +184,7 @@ impl Accumulator, + message: LocalizedMessage, ) { // message from different round. @@ -205,7 +205,7 @@ impl Accumulator Accumulator Accumulator Accumulator::new(1, 7, ValidatorId(8)); + let mut accumulator = Accumulator::<_, Digest, _, _>::new(1, 7, AuthorityId(8)); assert_eq!(accumulator.state(), &State::Begin); accumulator.import_message(LocalizedMessage { - sender: ValidatorId(5), + sender: AuthorityId(5), signature: Signature(999, 5), message: Message::Propose(1, Candidate(999)), }); @@ -377,7 +377,7 @@ mod tests { assert_eq!(accumulator.state(), &State::Begin); accumulator.import_message(LocalizedMessage { - sender: ValidatorId(8), + sender: AuthorityId(8), signature: Signature(999, 8), message: Message::Propose(1, Candidate(999)), }); @@ -387,11 +387,11 @@ mod tests { #[test] fn reaches_prepare_phase() { - let mut accumulator = Accumulator::new(1, 7, ValidatorId(8)); + let mut accumulator = Accumulator::new(1, 7, AuthorityId(8)); assert_eq!(accumulator.state(), &State::Begin); accumulator.import_message(LocalizedMessage { - sender: ValidatorId(8), + sender: AuthorityId(8), signature: Signature(999, 8), message: Message::Propose(1, Candidate(999)), }); @@ -400,7 +400,7 @@ mod tests { for i in 0..6 { accumulator.import_message(LocalizedMessage { - sender: ValidatorId(i), + sender: AuthorityId(i), signature: Signature(999, i), message: Message::Prepare(1, Digest(999)), }); @@ -409,7 +409,7 @@ mod tests { } accumulator.import_message(LocalizedMessage { - sender: ValidatorId(7), + sender: AuthorityId(7), signature: Signature(999, 7), message: Message::Prepare(1, Digest(999)), }); @@ -422,11 +422,11 @@ mod tests { #[test] fn prepare_to_commit() { - let mut accumulator = Accumulator::new(1, 7, ValidatorId(8)); + let mut accumulator = Accumulator::new(1, 7, AuthorityId(8)); assert_eq!(accumulator.state(), &State::Begin); accumulator.import_message(LocalizedMessage { - sender: ValidatorId(8), + sender: AuthorityId(8), signature: Signature(999, 8), message: Message::Propose(1, Candidate(999)), }); @@ -435,7 +435,7 @@ mod tests { for i in 0..6 { accumulator.import_message(LocalizedMessage { - sender: ValidatorId(i), + sender: AuthorityId(i), signature: Signature(999, i), message: Message::Prepare(1, Digest(999)), }); @@ -444,7 +444,7 @@ mod tests { } accumulator.import_message(LocalizedMessage { - sender: ValidatorId(7), + sender: AuthorityId(7), signature: Signature(999, 7), message: Message::Prepare(1, Digest(999)), }); @@ -456,7 +456,7 @@ mod tests { for i in 0..6 { accumulator.import_message(LocalizedMessage { - sender: ValidatorId(i), + sender: AuthorityId(i), signature: Signature(999, i), message: Message::Commit(1, Digest(999)), }); @@ -468,7 +468,7 @@ mod tests { } accumulator.import_message(LocalizedMessage { - sender: ValidatorId(7), + sender: AuthorityId(7), signature: Signature(999, 7), message: Message::Commit(1, Digest(999)), }); @@ -481,11 +481,11 @@ mod tests { #[test] fn prepare_to_advance() { - let mut accumulator = Accumulator::new(1, 7, ValidatorId(8)); + let mut accumulator = Accumulator::new(1, 7, AuthorityId(8)); assert_eq!(accumulator.state(), &State::Begin); accumulator.import_message(LocalizedMessage { - sender: ValidatorId(8), + sender: AuthorityId(8), signature: Signature(999, 8), message: Message::Propose(1, Candidate(999)), }); @@ -494,7 +494,7 @@ mod tests { for i in 0..7 { accumulator.import_message(LocalizedMessage { - sender: ValidatorId(i), + sender: AuthorityId(i), signature: Signature(999, i), message: Message::Prepare(1, Digest(999)), }); @@ -507,7 +507,7 @@ mod tests { for i in 0..6 { accumulator.import_message(LocalizedMessage { - sender: ValidatorId(i), + sender: AuthorityId(i), signature: Signature(999, i), message: Message::AdvanceRound(1), }); @@ -519,7 +519,7 @@ mod tests { } accumulator.import_message(LocalizedMessage { - sender: ValidatorId(7), + sender: AuthorityId(7), signature: Signature(999, 7), message: Message::AdvanceRound(1), }); @@ -532,12 +532,12 @@ mod tests { #[test] fn conclude_different_than_proposed() { - let mut accumulator = Accumulator::::new(1, 7, ValidatorId(8)); + let mut accumulator = Accumulator::::new(1, 7, AuthorityId(8)); assert_eq!(accumulator.state(), &State::Begin); for i in 0..7 { accumulator.import_message(LocalizedMessage { - sender: ValidatorId(i), + sender: AuthorityId(i), signature: Signature(999, i), message: Message::Prepare(1, Digest(999)), }); @@ -550,7 +550,7 @@ mod tests { for i in 0..7 { accumulator.import_message(LocalizedMessage { - sender: ValidatorId(i), + sender: AuthorityId(i), signature: Signature(999, i), message: Message::Commit(1, Digest(999)), }); @@ -564,12 +564,12 @@ mod tests { #[test] fn begin_to_advance() { - let mut accumulator = Accumulator::::new(1, 7, ValidatorId(8)); + let mut accumulator = Accumulator::::new(1, 7, AuthorityId(8)); assert_eq!(accumulator.state(), &State::Begin); for i in 0..7 { accumulator.import_message(LocalizedMessage { - sender: ValidatorId(i), + sender: AuthorityId(i), signature: Signature(1, i), message: Message::AdvanceRound(1), }); @@ -583,12 +583,12 @@ mod tests { #[test] fn conclude_without_prepare() { - let mut accumulator = Accumulator::::new(1, 7, ValidatorId(8)); + let mut accumulator = Accumulator::::new(1, 7, AuthorityId(8)); assert_eq!(accumulator.state(), &State::Begin); for i in 0..7 { accumulator.import_message(LocalizedMessage { - sender: ValidatorId(i), + sender: AuthorityId(i), signature: Signature(999, i), message: Message::Commit(1, Digest(999)), }); diff --git a/substrate/candidate-agreement/src/bft/mod.rs b/substrate/candidate-agreement/src/bft/mod.rs index 2cdd6d5f4d..f131e44e1f 100644 --- a/substrate/candidate-agreement/src/bft/mod.rs +++ b/substrate/candidate-agreement/src/bft/mod.rs @@ -76,8 +76,8 @@ pub trait Context { type Candidate: Debug + Eq + Clone; /// Candidate digest. type Digest: Debug + Hash + Eq + Clone; - /// Validator ID. - type ValidatorId: Debug + Hash + Eq + Clone; + /// Authority ID. + type AuthorityId: Debug + Hash + Eq + Clone; /// Signature. type Signature: Debug + Eq + Clone; /// A future that resolves when a round timeout is concluded. @@ -85,8 +85,8 @@ pub trait Context { /// A future that resolves when a proposal is ready. type CreateProposal: Future; - /// Get the local validator ID. - fn local_id(&self) -> Self::ValidatorId; + /// Get the local authority ID. + fn local_id(&self) -> Self::AuthorityId; /// Get the best proposal. fn proposal(&self) -> Self::CreateProposal; @@ -94,12 +94,12 @@ pub trait Context { /// Get the digest of a candidate. fn candidate_digest(&self, candidate: &Self::Candidate) -> Self::Digest; - /// Sign a message using the local validator ID. + /// Sign a message using the local authority ID. fn sign_local(&self, message: Message) - -> LocalizedMessage; + -> LocalizedMessage; /// Get the proposer for a given round of consensus. - fn round_proposer(&self, round: usize) -> Self::ValidatorId; + fn round_proposer(&self, round: usize) -> Self::AuthorityId; /// Whether the candidate is valid. fn candidate_valid(&self, candidate: &Self::Candidate) -> bool; @@ -121,11 +121,11 @@ pub enum Communication { /// Type alias for a localized message using only type parameters from `Context`. // TODO: actual type alias when it's no longer a warning. -pub struct ContextCommunication(pub Communication); +pub struct ContextCommunication(pub Communication); impl Clone for ContextCommunication where - LocalizedMessage: Clone, + LocalizedMessage: Clone, PrepareJustification: Clone, { fn clone(&self) -> Self { @@ -242,7 +242,7 @@ enum LocalState { // - a higher threshold-prepare is broadcast to us. in this case we can // advance to the round of the threshold-prepare. this is an indication // that we have experienced severe asynchrony/clock drift with the remainder -// of the other validators, and it is unlikely that we can assist in +// of the other authorities, and it is unlikely that we can assist in // consensus meaningfully. nevertheless we make an attempt. struct Strategy { nodes: usize, @@ -252,9 +252,9 @@ struct Strategy { local_state: LocalState, locked: Option>, notable_candidates: HashMap, - current_accumulator: Accumulator, - future_accumulator: Accumulator, - local_id: C::ValidatorId, + current_accumulator: Accumulator, + future_accumulator: Accumulator, + local_id: C::AuthorityId, } impl Strategy { @@ -290,7 +290,7 @@ impl Strategy { fn import_message( &mut self, - msg: LocalizedMessage + msg: LocalizedMessage ) { let round_number = msg.message.round_number(); diff --git a/substrate/candidate-agreement/src/bft/tests.rs b/substrate/candidate-agreement/src/bft/tests.rs index cb20bcce62..10ef932124 100644 --- a/substrate/candidate-agreement/src/bft/tests.rs +++ b/substrate/candidate-agreement/src/bft/tests.rs @@ -34,10 +34,10 @@ struct Candidate(usize); struct Digest(usize); #[derive(Debug, PartialEq, Eq, Clone, Hash)] -struct ValidatorId(usize); +struct AuthorityId(usize); #[derive(Debug, PartialEq, Eq, Clone)] -struct Signature(Message, ValidatorId); +struct Signature(Message, AuthorityId); struct SharedContext { node_count: usize, @@ -89,13 +89,13 @@ impl SharedContext { self.current_round += 1; } - fn round_proposer(&self, round: usize) -> ValidatorId { - ValidatorId(round % self.node_count) + fn round_proposer(&self, round: usize) -> AuthorityId { + AuthorityId(round % self.node_count) } } struct TestContext { - local_id: ValidatorId, + local_id: AuthorityId, proposal: Mutex, shared: Arc>, } @@ -103,12 +103,12 @@ struct TestContext { impl Context for TestContext { type Candidate = Candidate; type Digest = Digest; - type ValidatorId = ValidatorId; + type AuthorityId = AuthorityId; type Signature = Signature; type RoundTimeout = Box>; type CreateProposal = FutureResult; - fn local_id(&self) -> ValidatorId { + fn local_id(&self) -> AuthorityId { self.local_id.clone() } @@ -128,7 +128,7 @@ impl Context for TestContext { } fn sign_local(&self, message: Message) - -> LocalizedMessage + -> LocalizedMessage { let signature = Signature(message.clone(), self.local_id.clone()); LocalizedMessage { @@ -138,7 +138,7 @@ impl Context for TestContext { } } - fn round_proposer(&self, round: usize) -> ValidatorId { + fn round_proposer(&self, round: usize) -> AuthorityId { self.shared.lock().unwrap().round_proposer(round) } @@ -178,7 +178,7 @@ fn consensus_completes_with_minimum_good() { .enumerate() .map(|(i, (tx, rx))| { let ctx = TestContext { - local_id: ValidatorId(i), + local_id: AuthorityId(i), proposal: Mutex::new(i), shared: shared_context.clone(), }; @@ -234,7 +234,7 @@ fn consensus_does_not_complete_without_enough_nodes() { .enumerate() .map(|(i, (tx, rx))| { let ctx = TestContext { - local_id: ValidatorId(i), + local_id: AuthorityId(i), proposal: Mutex::new(i), shared: shared_context.clone(), }; @@ -273,7 +273,7 @@ fn threshold_plus_one_locked_on_proposal_only_one_with_candidate() { round_number: locked_round, digest: locked_digest.clone(), signatures: (0..7) - .map(|i| Signature(Message::Prepare(locked_round, locked_digest.clone()), ValidatorId(i))) + .map(|i| Signature(Message::Prepare(locked_round, locked_digest.clone()), AuthorityId(i))) .collect() }.check(7, |_, _, s| Some(s.1.clone())).unwrap(); @@ -290,7 +290,7 @@ fn threshold_plus_one_locked_on_proposal_only_one_with_candidate() { .enumerate() .map(|(i, (tx, rx))| { let ctx = TestContext { - local_id: ValidatorId(i), + local_id: AuthorityId(i), proposal: Mutex::new(i), shared: shared_context.clone(), }; diff --git a/substrate/candidate-agreement/src/handle_incoming.rs b/substrate/candidate-agreement/src/handle_incoming.rs index 150f0faf68..625c950784 100644 --- a/substrate/candidate-agreement/src/handle_incoming.rs +++ b/substrate/candidate-agreement/src/handle_incoming.rs @@ -75,7 +75,7 @@ pub struct HandleIncoming { table: SharedTable, messages_in: Fuse, bft_out: mpsc::UnboundedSender<::BftCommunication>, - local_id: C::ValidatorId, + local_id: C::AuthorityId, requesting_about: FuturesUnordered::Future, @@ -98,7 +98,7 @@ impl HandleIncoming { self.table.sign_and_import(statement); } - fn import_message(&mut self, origin: C::ValidatorId, message: CheckedMessage) { + fn import_message(&mut self, origin: C::AuthorityId, message: CheckedMessage) { match message { CheckedMessage::Bft(msg) => { let _ = self.bft_out.unbounded_send(msg); } CheckedMessage::Table(table_messages) => { @@ -161,7 +161,7 @@ impl HandleIncoming { impl HandleIncoming where C: Context, - I: Stream),Error=E>, + I: Stream),Error=E>, C::CheckAvailability: IntoFuture, C::CheckCandidate: IntoFuture, { @@ -187,7 +187,7 @@ impl HandleIncoming impl Future for HandleIncoming where C: Context, - I: Stream),Error=E>, + I: Stream),Error=E>, C::CheckAvailability: IntoFuture, C::CheckCandidate: IntoFuture, { diff --git a/substrate/candidate-agreement/src/lib.rs b/substrate/candidate-agreement/src/lib.rs index 20da23c59b..2cf4be5c54 100644 --- a/substrate/candidate-agreement/src/lib.rs +++ b/substrate/candidate-agreement/src/lib.rs @@ -16,18 +16,18 @@ //! Propagation and agreement of candidates. //! -//! Validators are split into groups by parachain, and each validator might come -//! up its own candidate for their parachain. Within groups, validators pass around +//! Authorities are split into groups by parachain, and each authority might come +//! up its own candidate for their parachain. Within groups, authorities pass around //! their candidates and produce statements of validity. //! -//! Any candidate that receives majority approval by the validators in a group -//! may be subject to inclusion, unless any validators flag that candidate as invalid. +//! Any candidate that receives majority approval by the authorities in a group +//! may be subject to inclusion, unless any authorities flag that candidate as invalid. //! //! Wrongly flagging as invalid should be strongly disincentivized, so that in the //! equilibrium state it is not expected to happen. Likewise with the submission //! of invalid blocks. //! -//! Groups themselves may be compromised by malicious validators. +//! Groups themselves may be compromised by malicious authorities. #[macro_use] extern crate futures; @@ -57,8 +57,8 @@ pub mod tests; /// Context necessary for agreement. pub trait Context: Send + Clone { - /// A validator ID - type ValidatorId: Debug + Hash + Eq + Clone + Ord; + /// A authority ID + type AuthorityId: Debug + Hash + Eq + Clone + Ord; /// The digest (hash or other unique attribute) of a candidate. type Digest: Debug + Hash + Eq + Clone; /// The group ID type @@ -83,8 +83,8 @@ pub trait Context: Send + Clone { /// The statement batch type. type StatementBatch: StatementBatch< - Self::ValidatorId, - table::SignedStatement, + Self::AuthorityId, + table::SignedStatement, >; /// Get the digest of a candidate. @@ -97,7 +97,7 @@ pub trait Context: Send + Clone { fn candidate_group(candidate: &Self::ParachainCandidate) -> Self::GroupId; /// Get the primary for a given round. - fn round_proposer(&self, round: usize) -> Self::ValidatorId; + fn round_proposer(&self, round: usize) -> Self::AuthorityId; /// Check a candidate for validity. fn check_validity(&self, candidate: &Self::ParachainCandidate) -> Self::CheckCandidate; @@ -120,8 +120,8 @@ pub trait Context: Send + Clone { fn proposal_valid(&self, proposal: &Self::Proposal, check_candidate: F) -> bool where F: FnMut(&Self::ParachainCandidate) -> bool; - /// Get the local validator ID. - fn local_id(&self) -> Self::ValidatorId; + /// Get the local authority ID. + fn local_id(&self) -> Self::AuthorityId; /// Sign a table validity statement with the local key. fn sign_table_statement( @@ -142,18 +142,18 @@ pub trait TypeResolve { } impl TypeResolve for C { - type SignedTableStatement = table::SignedStatement; - type BftCommunication = bft::Communication; + type SignedTableStatement = table::SignedStatement; + type BftCommunication = bft::Communication; type BftCommitted = bft::Committed; - type Misbehavior = table::Misbehavior; + type Misbehavior = table::Misbehavior; } /// Information about a specific group. #[derive(Debug, Clone)] pub struct GroupInfo { - /// Validators meant to check validity of candidates. + /// Authorities meant to check validity of candidates. pub validity_guarantors: HashSet, - /// Validators meant to check availability of candidate data. + /// Authorities meant to check availability of candidate data. pub availability_guarantors: HashSet, /// Number of votes needed for validity. pub needed_validity: usize, @@ -163,7 +163,7 @@ pub struct GroupInfo { struct TableContext { context: C, - groups: HashMap>, + groups: HashMap>, } impl ::std::ops::Deref for TableContext { @@ -175,7 +175,7 @@ impl ::std::ops::Deref for TableContext { } impl table::Context for TableContext { - type ValidatorId = C::ValidatorId; + type AuthorityId = C::AuthorityId; type Digest = C::Digest; type GroupId = C::GroupId; type Signature = C::Signature; @@ -189,12 +189,12 @@ impl table::Context for TableContext { C::candidate_group(candidate) } - fn is_member_of(&self, validator: &Self::ValidatorId, group: &Self::GroupId) -> bool { - self.groups.get(group).map_or(false, |g| g.validity_guarantors.contains(validator)) + fn is_member_of(&self, authority: &Self::AuthorityId, group: &Self::GroupId) -> bool { + self.groups.get(group).map_or(false, |g| g.validity_guarantors.contains(authority)) } - fn is_availability_guarantor_of(&self, validator: &Self::ValidatorId, group: &Self::GroupId) -> bool { - self.groups.get(group).map_or(false, |g| g.availability_guarantors.contains(validator)) + fn is_availability_guarantor_of(&self, authority: &Self::AuthorityId, group: &Self::GroupId) -> bool { + self.groups.get(group).map_or(false, |g| g.availability_guarantors.contains(authority)) } fn requisite_votes(&self, group: &Self::GroupId) -> (usize, usize) { @@ -217,7 +217,7 @@ impl SharedTableInner { &mut self, context: &TableContext, statement: ::SignedTableStatement, - received_from: Option + received_from: Option ) -> Option> { self.table.import_statement(context, statement, received_from) } @@ -265,7 +265,7 @@ impl Clone for SharedTable { impl SharedTable { /// Create a new shared table. - pub fn new(context: C, groups: HashMap>) -> Self { + pub fn new(context: C, groups: HashMap>) -> Self { SharedTable { context: Arc::new(TableContext { context, groups }), inner: Arc::new(Mutex::new(SharedTableInner { @@ -280,7 +280,7 @@ impl SharedTable { pub fn import_statement( &self, statement: ::SignedTableStatement, - received_from: Option, + received_from: Option, ) -> Option> { self.inner.lock().import_statement(&*self.context, statement, received_from) } @@ -314,7 +314,7 @@ impl SharedTable { /// Provide an iterator yielding pairs of (statement, received_from). pub fn import_statements(&self, iterable: I) -> U where - I: IntoIterator::SignedTableStatement, Option)>, + I: IntoIterator::SignedTableStatement, Option)>, U: ::std::iter::FromIterator>, { let mut inner = self.inner.lock(); @@ -351,7 +351,7 @@ impl SharedTable { } /// Get all witnessed misbehavior. - pub fn get_misbehavior(&self) -> HashMap::Misbehavior> { + pub fn get_misbehavior(&self) -> HashMap::Misbehavior> { self.inner.lock().table.get_misbehavior().clone() } @@ -396,14 +396,14 @@ pub struct BftContext { impl bft::Context for BftContext where C::Proposal: 'static, { - type ValidatorId = C::ValidatorId; + type AuthorityId = C::AuthorityId; type Digest = C::Digest; type Signature = C::Signature; type Candidate = C::Proposal; type RoundTimeout = Box>; type CreateProposal = Box>; - fn local_id(&self) -> Self::ValidatorId { + fn local_id(&self) -> Self::AuthorityId { self.context.local_id() } @@ -416,7 +416,7 @@ impl bft::Context for BftContext } fn sign_local(&self, message: bft::Message) - -> bft::LocalizedMessage + -> bft::LocalizedMessage { let sender = self.local_id(); let signature = self.context.sign_bft_message(&message); @@ -427,7 +427,7 @@ impl bft::Context for BftContext } } - fn round_proposer(&self, round: usize) -> Self::ValidatorId { + fn round_proposer(&self, round: usize) -> Self::AuthorityId { self.context.round_proposer(round) } @@ -533,7 +533,7 @@ pub fn agree< Context: ::Context + 'static, Context::CheckCandidate: IntoFuture, Context::CheckAvailability: IntoFuture, - NetIn: Stream),Error=Err> + 'static, + NetIn: Stream),Error=Err> + 'static, NetOut: Sink> + 'static, Recovery: MessageRecovery + 'static, PropagateStatements: Stream + 'static, diff --git a/substrate/candidate-agreement/src/table.rs b/substrate/candidate-agreement/src/table.rs index a54cd908b7..2909d219c6 100644 --- a/substrate/candidate-agreement/src/table.rs +++ b/substrate/candidate-agreement/src/table.rs @@ -16,14 +16,14 @@ //! The statement table. //! -//! This stores messages other validators issue about candidates. +//! This stores messages other authorities issue about candidates. //! //! These messages are used to create a proposal submitted to a BFT consensus process. //! //! Proposals are formed of sets of candidates which have the requisite number of //! validity and availability votes. //! -//! Each parachain is associated with two sets of validators: those which can +//! Each parachain is associated with two sets of authorities: those which can //! propose and attest to validity of candidates, and those who can only attest //! to availability. @@ -36,8 +36,8 @@ use super::StatementBatch; /// Context for the statement table. pub trait Context { - /// A validator ID - type ValidatorId: Debug + Hash + Eq + Clone; + /// A authority ID + type AuthorityId: Debug + Hash + Eq + Clone; /// The digest (hash or other unique attribute) of a candidate. type Digest: Debug + Hash + Eq + Clone; /// The group ID type @@ -53,16 +53,16 @@ pub trait Context { /// get the group of a candidate. fn candidate_group(candidate: &Self::Candidate) -> Self::GroupId; - /// Whether a validator is a member of a group. + /// Whether a authority is a member of a group. /// Members are meant to submit candidates and vote on validity. - fn is_member_of(&self, validator: &Self::ValidatorId, group: &Self::GroupId) -> bool; + fn is_member_of(&self, authority: &Self::AuthorityId, group: &Self::GroupId) -> bool; - /// Whether a validator is an availability guarantor of a group. + /// Whether a authority is an availability guarantor of a group. /// Guarantors are meant to vote on availability for candidates submitted /// in a group. fn is_availability_guarantor_of( &self, - validator: &Self::ValidatorId, + authority: &Self::AuthorityId, group: &Self::GroupId, ) -> bool; @@ -73,18 +73,18 @@ pub trait Context { /// Statements circulated among peers. #[derive(PartialEq, Eq, Debug, Clone)] pub enum Statement { - /// Broadcast by a validator to indicate that this is his candidate for + /// Broadcast by a authority to indicate that this is his candidate for /// inclusion. /// /// Broadcasting two different candidate messages per round is not allowed. Candidate(C), - /// Broadcast by a validator to attest that the candidate with given digest + /// Broadcast by a authority to attest that the candidate with given digest /// is valid. Valid(D), - /// Broadcast by a validator to attest that the auxiliary data for a candidate + /// Broadcast by a authority to attest that the auxiliary data for a candidate /// with given digest is available. Available(D), - /// Broadcast by a validator to attest that the candidate with given digest + /// Broadcast by a authority to attest that the candidate with given digest /// is invalid. Invalid(D), } @@ -100,23 +100,23 @@ pub struct SignedStatement { pub sender: V, } -// A unique trace for a class of valid statements issued by a validator. +// A unique trace for a class of valid statements issued by a authority. // -// We keep track of which statements we have received or sent to other validators +// We keep track of which statements we have received or sent to other authorities // in order to prevent relaying the same data multiple times. // -// The signature of the statement is replaced by the validator because the validator +// The signature of the statement is replaced by the authority because the authority // is unique while signatures are not (at least under common schemes like // Schnorr or ECDSA). #[derive(Hash, PartialEq, Eq, Clone)] enum StatementTrace { - /// The candidate proposed by the validator. + /// The candidate proposed by the authority. Candidate(V), - /// A validity statement from that validator about the given digest. + /// A validity statement from that authority about the given digest. Valid(V, D), - /// An invalidity statement from that validator about the given digest. + /// An invalidity statement from that authority about the given digest. Invalid(V, D), - /// An availability statement from that validator about the given digest. + /// An availability statement from that authority about the given digest. Available(V, D), } @@ -170,7 +170,7 @@ pub trait ResolveMisbehavior { } impl ResolveMisbehavior for C { - type Misbehavior = Misbehavior; + type Misbehavior = Misbehavior; } // kinds of votes for validity @@ -203,9 +203,9 @@ pub struct Summary { pub struct CandidateData { group_id: C::GroupId, candidate: C::Candidate, - validity_votes: HashMap>, - availability_votes: HashMap, - indicated_bad_by: Vec, + validity_votes: HashMap>, + availability_votes: HashMap, + indicated_bad_by: Vec, } impl CandidateData { @@ -216,7 +216,7 @@ impl CandidateData { // Candidate data can be included in a proposal // if it has enough validity and availability votes - // and no validators have called it bad. + // and no authorities have called it bad. fn can_be_included(&self, validity_threshold: usize, availability_threshold: usize) -> bool { self.indicated_bad_by.is_empty() && self.validity_votes.len() >= validity_threshold @@ -234,15 +234,15 @@ impl CandidateData { } } -// validator metadata -struct ValidatorData { +// authority metadata +struct AuthorityData { proposal: Option<(C::Digest, C::Signature)>, - known_statements: HashSet>, + known_statements: HashSet>, } -impl Default for ValidatorData { +impl Default for AuthorityData { fn default() -> Self { - ValidatorData { + AuthorityData { proposal: None, known_statements: HashSet::default(), } @@ -251,15 +251,15 @@ impl Default for ValidatorData { /// Stores votes pub struct Table { - validator_data: HashMap>, - detected_misbehavior: HashMap::Misbehavior>, + authority_data: HashMap>, + detected_misbehavior: HashMap::Misbehavior>, candidate_votes: HashMap>, } impl Default for Table { fn default() -> Self { Table { - validator_data: HashMap::new(), + authority_data: HashMap::new(), detected_misbehavior: HashMap::new(), candidate_votes: HashMap::new(), } @@ -307,15 +307,15 @@ impl Table { } /// Import a signed statement. Signatures should be checked for validity, and the - /// sender should be checked to actually be a validator. + /// sender should be checked to actually be a authority. /// /// This can note the origin of the statement to indicate that he has /// seen it already. pub fn import_statement( &mut self, context: &C, - statement: SignedStatement, - from: Option + statement: SignedStatement, + from: Option ) -> Option> { let SignedStatement { statement, signature, sender: signer } = statement; @@ -375,7 +375,7 @@ impl Table { /// Access all witnessed misbehavior. pub fn get_misbehavior(&self) - -> &HashMap::Misbehavior> + -> &HashMap::Misbehavior> { &self.detected_misbehavior } @@ -383,8 +383,8 @@ impl Table { /// Fill a statement batch and note messages seen by the targets. pub fn fill_batch(&mut self, batch: &mut B) where B: StatementBatch< - C::ValidatorId, - SignedStatement, + C::AuthorityId, + SignedStatement, > { // naively iterate all statements so far, taking any that @@ -394,24 +394,24 @@ impl Table { // entries out of a hashmap mutably -- we just move them out and // replace them when we're done. struct SwappedTargetData<'a, C: 'a + Context> { - validator_data: &'a mut HashMap>, - target_data: Vec<(C::ValidatorId, ValidatorData)>, + authority_data: &'a mut HashMap>, + target_data: Vec<(C::AuthorityId, AuthorityData)>, } impl<'a, C: 'a + Context> Drop for SwappedTargetData<'a, C> { fn drop(&mut self) { for (id, data) in self.target_data.drain(..) { - self.validator_data.insert(id, data); + self.authority_data.insert(id, data); } } } // pre-fetch authority data for all the targets. let mut target_data = { - let validator_data = &mut self.validator_data; + let authority_data = &mut self.authority_data; let mut target_data = Vec::with_capacity(batch.targets().len()); for target in batch.targets() { - let active_data = match validator_data.get_mut(target) { + let active_data = match authority_data.get_mut(target) { None => Default::default(), Some(x) => ::std::mem::replace(x, Default::default()), }; @@ -420,7 +420,7 @@ impl Table { } SwappedTargetData { - validator_data, + authority_data, target_data } }; @@ -503,8 +503,8 @@ impl Table { } - fn note_trace_seen(&mut self, trace: StatementTrace, known_by: C::ValidatorId) { - self.validator_data.entry(known_by).or_insert_with(|| ValidatorData { + fn note_trace_seen(&mut self, trace: StatementTrace, known_by: C::AuthorityId) { + self.authority_data.entry(known_by).or_insert_with(|| AuthorityData { proposal: None, known_statements: HashSet::default(), }).known_statements.insert(trace); @@ -513,7 +513,7 @@ impl Table { fn import_candidate( &mut self, context: &C, - from: C::ValidatorId, + from: C::AuthorityId, candidate: C::Candidate, signature: C::Signature, ) -> (Option<::Misbehavior>, Option>) { @@ -531,10 +531,10 @@ impl Table { ); } - // check that validator hasn't already specified another candidate. + // check that authority hasn't already specified another candidate. let digest = C::candidate_digest(&candidate); - let new_proposal = match self.validator_data.entry(from.clone()) { + let new_proposal = match self.authority_data.entry(from.clone()) { Entry::Occupied(mut occ) => { // if digest is different, fetch candidate and // note misbehavior. @@ -543,7 +543,7 @@ impl Table { if let Some((ref old_digest, ref old_sig)) = existing.proposal { if old_digest != &digest { const EXISTENCE_PROOF: &str = - "when proposal first received from validator, candidate \ + "when proposal first received from authority, candidate \ votes entry is created. proposal here is `Some`, therefore \ candidate votes entry exists; qed"; @@ -568,7 +568,7 @@ impl Table { } } Entry::Vacant(vacant) => { - vacant.insert(ValidatorData { + vacant.insert(AuthorityData { proposal: Some((digest.clone(), signature.clone())), known_statements: HashSet::new(), }); @@ -599,7 +599,7 @@ impl Table { fn validity_vote( &mut self, context: &C, - from: C::ValidatorId, + from: C::AuthorityId, digest: C::Digest, vote: ValidityVote, ) -> (Option<::Misbehavior>, Option>) { @@ -608,7 +608,7 @@ impl Table { Some(votes) => votes, }; - // check that this validator actually can vote in this group. + // check that this authority actually can vote in this group. if !context.is_member_of(&from, &votes.group_id) { let (sig, valid) = match vote { ValidityVote::Valid(s) => (s, true), @@ -678,7 +678,7 @@ impl Table { fn availability_vote( &mut self, context: &C, - from: C::ValidatorId, + from: C::AuthorityId, digest: C::Digest, signature: C::Signature, ) -> (Option<::Misbehavior>, Option>) { @@ -687,7 +687,7 @@ impl Table { Some(votes) => votes, }; - // check that this validator actually can vote in this group. + // check that this authority actually can vote in this group. if !context.is_availability_guarantor_of(&from, &votes.group_id) { return ( Some(Misbehavior::UnauthorizedStatement(UnauthorizedStatement { @@ -714,14 +714,14 @@ mod tests { fn create() -> Table { Table { - validator_data: HashMap::default(), + authority_data: HashMap::default(), detected_misbehavior: HashMap::default(), candidate_votes: HashMap::default(), } } #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] - struct ValidatorId(usize); + struct AuthorityId(usize); #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] struct GroupId(usize); @@ -739,11 +739,11 @@ mod tests { #[derive(Debug, PartialEq, Eq)] struct TestContext { // v -> (validity, availability) - validators: HashMap + authorities: HashMap } impl Context for TestContext { - type ValidatorId = ValidatorId; + type AuthorityId = AuthorityId; type Digest = Digest; type Candidate = Candidate; type GroupId = GroupId; @@ -759,18 +759,18 @@ mod tests { fn is_member_of( &self, - validator: &ValidatorId, + authority: &AuthorityId, group: &GroupId ) -> bool { - self.validators.get(validator).map(|v| &v.0 == group).unwrap_or(false) + self.authorities.get(authority).map(|v| &v.0 == group).unwrap_or(false) } fn is_availability_guarantor_of( &self, - validator: &ValidatorId, + authority: &AuthorityId, group: &GroupId ) -> bool { - self.validators.get(validator).map(|v| &v.1 == group).unwrap_or(false) + self.authorities.get(authority).map(|v| &v.1 == group).unwrap_or(false) } fn requisite_votes(&self, _id: &GroupId) -> (usize, usize) { @@ -781,9 +781,9 @@ mod tests { #[test] fn submitting_two_candidates_is_misbehavior() { let context = TestContext { - validators: { + authorities: { let mut map = HashMap::new(); - map.insert(ValidatorId(1), (GroupId(2), GroupId(455))); + map.insert(AuthorityId(1), (GroupId(2), GroupId(455))); map } }; @@ -792,21 +792,21 @@ mod tests { let statement_a = SignedStatement { statement: Statement::Candidate(Candidate(2, 100)), signature: Signature(1), - sender: ValidatorId(1), + sender: AuthorityId(1), }; let statement_b = SignedStatement { statement: Statement::Candidate(Candidate(2, 999)), signature: Signature(1), - sender: ValidatorId(1), + sender: AuthorityId(1), }; table.import_statement(&context, statement_a, None); - assert!(!table.detected_misbehavior.contains_key(&ValidatorId(1))); + assert!(!table.detected_misbehavior.contains_key(&AuthorityId(1))); table.import_statement(&context, statement_b, None); assert_eq!( - table.detected_misbehavior.get(&ValidatorId(1)).unwrap(), + table.detected_misbehavior.get(&AuthorityId(1)).unwrap(), &Misbehavior::MultipleCandidates(MultipleCandidates { first: (Candidate(2, 100), Signature(1)), second: (Candidate(2, 999), Signature(1)), @@ -817,9 +817,9 @@ mod tests { #[test] fn submitting_candidate_from_wrong_group_is_misbehavior() { let context = TestContext { - validators: { + authorities: { let mut map = HashMap::new(); - map.insert(ValidatorId(1), (GroupId(3), GroupId(455))); + map.insert(AuthorityId(1), (GroupId(3), GroupId(455))); map } }; @@ -828,18 +828,18 @@ mod tests { let statement = SignedStatement { statement: Statement::Candidate(Candidate(2, 100)), signature: Signature(1), - sender: ValidatorId(1), + sender: AuthorityId(1), }; table.import_statement(&context, statement, None); assert_eq!( - table.detected_misbehavior.get(&ValidatorId(1)).unwrap(), + table.detected_misbehavior.get(&AuthorityId(1)).unwrap(), &Misbehavior::UnauthorizedStatement(UnauthorizedStatement { statement: SignedStatement { statement: Statement::Candidate(Candidate(2, 100)), signature: Signature(1), - sender: ValidatorId(1), + sender: AuthorityId(1), }, }) ); @@ -848,10 +848,10 @@ mod tests { #[test] fn unauthorized_votes() { let context = TestContext { - validators: { + authorities: { let mut map = HashMap::new(); - map.insert(ValidatorId(1), (GroupId(2), GroupId(455))); - map.insert(ValidatorId(2), (GroupId(3), GroupId(222))); + map.insert(AuthorityId(1), (GroupId(2), GroupId(455))); + map.insert(AuthorityId(2), (GroupId(3), GroupId(222))); map } }; @@ -861,56 +861,56 @@ mod tests { let candidate_a = SignedStatement { statement: Statement::Candidate(Candidate(2, 100)), signature: Signature(1), - sender: ValidatorId(1), + sender: AuthorityId(1), }; let candidate_a_digest = Digest(100); let candidate_b = SignedStatement { statement: Statement::Candidate(Candidate(3, 987)), signature: Signature(2), - sender: ValidatorId(2), + sender: AuthorityId(2), }; let candidate_b_digest = Digest(987); table.import_statement(&context, candidate_a, None); table.import_statement(&context, candidate_b, None); - assert!(!table.detected_misbehavior.contains_key(&ValidatorId(1))); - assert!(!table.detected_misbehavior.contains_key(&ValidatorId(2))); + assert!(!table.detected_misbehavior.contains_key(&AuthorityId(1))); + assert!(!table.detected_misbehavior.contains_key(&AuthorityId(2))); - // validator 1 votes for availability on 2's candidate. + // authority 1 votes for availability on 2's candidate. let bad_availability_vote = SignedStatement { statement: Statement::Available(candidate_b_digest.clone()), signature: Signature(1), - sender: ValidatorId(1), + sender: AuthorityId(1), }; table.import_statement(&context, bad_availability_vote, None); assert_eq!( - table.detected_misbehavior.get(&ValidatorId(1)).unwrap(), + table.detected_misbehavior.get(&AuthorityId(1)).unwrap(), &Misbehavior::UnauthorizedStatement(UnauthorizedStatement { statement: SignedStatement { statement: Statement::Available(candidate_b_digest), signature: Signature(1), - sender: ValidatorId(1), + sender: AuthorityId(1), }, }) ); - // validator 2 votes for validity on 1's candidate. + // authority 2 votes for validity on 1's candidate. let bad_validity_vote = SignedStatement { statement: Statement::Valid(candidate_a_digest.clone()), signature: Signature(2), - sender: ValidatorId(2), + sender: AuthorityId(2), }; table.import_statement(&context, bad_validity_vote, None); assert_eq!( - table.detected_misbehavior.get(&ValidatorId(2)).unwrap(), + table.detected_misbehavior.get(&AuthorityId(2)).unwrap(), &Misbehavior::UnauthorizedStatement(UnauthorizedStatement { statement: SignedStatement { statement: Statement::Valid(candidate_a_digest), signature: Signature(2), - sender: ValidatorId(2), + sender: AuthorityId(2), }, }) ); @@ -919,10 +919,10 @@ mod tests { #[test] fn validity_double_vote_is_misbehavior() { let context = TestContext { - validators: { + authorities: { let mut map = HashMap::new(); - map.insert(ValidatorId(1), (GroupId(2), GroupId(455))); - map.insert(ValidatorId(2), (GroupId(2), GroupId(246))); + map.insert(AuthorityId(1), (GroupId(2), GroupId(455))); + map.insert(AuthorityId(2), (GroupId(2), GroupId(246))); map } }; @@ -931,32 +931,32 @@ mod tests { let statement = SignedStatement { statement: Statement::Candidate(Candidate(2, 100)), signature: Signature(1), - sender: ValidatorId(1), + sender: AuthorityId(1), }; let candidate_digest = Digest(100); table.import_statement(&context, statement, None); - assert!(!table.detected_misbehavior.contains_key(&ValidatorId(1))); + assert!(!table.detected_misbehavior.contains_key(&AuthorityId(1))); let valid_statement = SignedStatement { statement: Statement::Valid(candidate_digest.clone()), signature: Signature(2), - sender: ValidatorId(2), + sender: AuthorityId(2), }; let invalid_statement = SignedStatement { statement: Statement::Invalid(candidate_digest.clone()), signature: Signature(2), - sender: ValidatorId(2), + sender: AuthorityId(2), }; table.import_statement(&context, valid_statement, None); - assert!(!table.detected_misbehavior.contains_key(&ValidatorId(2))); + assert!(!table.detected_misbehavior.contains_key(&AuthorityId(2))); table.import_statement(&context, invalid_statement, None); assert_eq!( - table.detected_misbehavior.get(&ValidatorId(2)).unwrap(), + table.detected_misbehavior.get(&AuthorityId(2)).unwrap(), &Misbehavior::ValidityDoubleVote(ValidityDoubleVote::ValidityAndInvalidity( candidate_digest, Signature(2), @@ -968,9 +968,9 @@ mod tests { #[test] fn issue_and_vote_is_misbehavior() { let context = TestContext { - validators: { + authorities: { let mut map = HashMap::new(); - map.insert(ValidatorId(1), (GroupId(2), GroupId(455))); + map.insert(AuthorityId(1), (GroupId(2), GroupId(455))); map } }; @@ -979,22 +979,22 @@ mod tests { let statement = SignedStatement { statement: Statement::Candidate(Candidate(2, 100)), signature: Signature(1), - sender: ValidatorId(1), + sender: AuthorityId(1), }; let candidate_digest = Digest(100); table.import_statement(&context, statement, None); - assert!(!table.detected_misbehavior.contains_key(&ValidatorId(1))); + assert!(!table.detected_misbehavior.contains_key(&AuthorityId(1))); let extra_vote = SignedStatement { statement: Statement::Valid(candidate_digest.clone()), signature: Signature(1), - sender: ValidatorId(1), + sender: AuthorityId(1), }; table.import_statement(&context, extra_vote, None); assert_eq!( - table.detected_misbehavior.get(&ValidatorId(1)).unwrap(), + table.detected_misbehavior.get(&AuthorityId(1)).unwrap(), &Misbehavior::ValidityDoubleVote(ValidityDoubleVote::IssuedAndValidity( (Candidate(2, 100), Signature(1)), (Digest(100), Signature(1)), @@ -1018,18 +1018,18 @@ mod tests { assert!(!candidate.can_be_included(validity_threshold, availability_threshold)); for i in 0..validity_threshold { - candidate.validity_votes.insert(ValidatorId(i + 100), ValidityVote::Valid(Signature(i + 100))); + candidate.validity_votes.insert(AuthorityId(i + 100), ValidityVote::Valid(Signature(i + 100))); } assert!(!candidate.can_be_included(validity_threshold, availability_threshold)); for i in 0..availability_threshold { - candidate.availability_votes.insert(ValidatorId(i + 255), Signature(i + 255)); + candidate.availability_votes.insert(AuthorityId(i + 255), Signature(i + 255)); } assert!(candidate.can_be_included(validity_threshold, availability_threshold)); - candidate.indicated_bad_by.push(ValidatorId(1024)); + candidate.indicated_bad_by.push(AuthorityId(1024)); assert!(!candidate.can_be_included(validity_threshold, availability_threshold)); } @@ -1037,9 +1037,9 @@ mod tests { #[test] fn candidate_import_gives_summary() { let context = TestContext { - validators: { + authorities: { let mut map = HashMap::new(); - map.insert(ValidatorId(1), (GroupId(2), GroupId(455))); + map.insert(AuthorityId(1), (GroupId(2), GroupId(455))); map } }; @@ -1048,7 +1048,7 @@ mod tests { let statement = SignedStatement { statement: Statement::Candidate(Candidate(2, 100)), signature: Signature(1), - sender: ValidatorId(1), + sender: AuthorityId(1), }; let summary = table.import_statement(&context, statement, None) @@ -1063,10 +1063,10 @@ mod tests { #[test] fn candidate_vote_gives_summary() { let context = TestContext { - validators: { + authorities: { let mut map = HashMap::new(); - map.insert(ValidatorId(1), (GroupId(2), GroupId(455))); - map.insert(ValidatorId(2), (GroupId(2), GroupId(455))); + map.insert(AuthorityId(1), (GroupId(2), GroupId(455))); + map.insert(AuthorityId(2), (GroupId(2), GroupId(455))); map } }; @@ -1075,23 +1075,23 @@ mod tests { let statement = SignedStatement { statement: Statement::Candidate(Candidate(2, 100)), signature: Signature(1), - sender: ValidatorId(1), + sender: AuthorityId(1), }; let candidate_digest = Digest(100); table.import_statement(&context, statement, None); - assert!(!table.detected_misbehavior.contains_key(&ValidatorId(1))); + assert!(!table.detected_misbehavior.contains_key(&AuthorityId(1))); let vote = SignedStatement { statement: Statement::Valid(candidate_digest.clone()), signature: Signature(2), - sender: ValidatorId(2), + sender: AuthorityId(2), }; let summary = table.import_statement(&context, vote, None) .expect("candidate vote to give summary"); - assert!(!table.detected_misbehavior.contains_key(&ValidatorId(2))); + assert!(!table.detected_misbehavior.contains_key(&AuthorityId(2))); assert_eq!(summary.candidate, Digest(100)); assert_eq!(summary.group_id, GroupId(2)); @@ -1102,10 +1102,10 @@ mod tests { #[test] fn availability_vote_gives_summary() { let context = TestContext { - validators: { + authorities: { let mut map = HashMap::new(); - map.insert(ValidatorId(1), (GroupId(2), GroupId(455))); - map.insert(ValidatorId(2), (GroupId(5), GroupId(2))); + map.insert(AuthorityId(1), (GroupId(2), GroupId(455))); + map.insert(AuthorityId(2), (GroupId(5), GroupId(2))); map } }; @@ -1114,23 +1114,23 @@ mod tests { let statement = SignedStatement { statement: Statement::Candidate(Candidate(2, 100)), signature: Signature(1), - sender: ValidatorId(1), + sender: AuthorityId(1), }; let candidate_digest = Digest(100); table.import_statement(&context, statement, None); - assert!(!table.detected_misbehavior.contains_key(&ValidatorId(1))); + assert!(!table.detected_misbehavior.contains_key(&AuthorityId(1))); let vote = SignedStatement { statement: Statement::Available(candidate_digest.clone()), signature: Signature(2), - sender: ValidatorId(2), + sender: AuthorityId(2), }; let summary = table.import_statement(&context, vote, None) .expect("candidate vote to give summary"); - assert!(!table.detected_misbehavior.contains_key(&ValidatorId(2))); + assert!(!table.detected_misbehavior.contains_key(&AuthorityId(2))); assert_eq!(summary.candidate, Digest(100)); assert_eq!(summary.group_id, GroupId(2)); @@ -1141,10 +1141,10 @@ mod tests { #[test] fn filling_batch_sets_known_flag() { let context = TestContext { - validators: { + authorities: { let mut map = HashMap::new(); for i in 1..10 { - map.insert(ValidatorId(i), (GroupId(2), GroupId(400 + i))); + map.insert(AuthorityId(i), (GroupId(2), GroupId(400 + i))); } map } @@ -1154,7 +1154,7 @@ mod tests { let statement = SignedStatement { statement: Statement::Candidate(Candidate(2, 100)), signature: Signature(1), - sender: ValidatorId(1), + sender: AuthorityId(1), }; table.import_statement(&context, statement, None); @@ -1163,7 +1163,7 @@ mod tests { let statement = SignedStatement { statement: Statement::Valid(Digest(100)), signature: Signature(i), - sender: ValidatorId(i), + sender: AuthorityId(i), }; table.import_statement(&context, statement, None); @@ -1171,7 +1171,7 @@ mod tests { let mut batch = VecBatch { max_len: 5, - targets: (1..10).map(ValidatorId).collect(), + targets: (1..10).map(AuthorityId).collect(), items: Vec::new(), }; diff --git a/substrate/candidate-agreement/src/tests/mod.rs b/substrate/candidate-agreement/src/tests/mod.rs index ec67964d28..1599a94aa6 100644 --- a/substrate/candidate-agreement/src/tests/mod.rs +++ b/substrate/candidate-agreement/src/tests/mod.rs @@ -31,7 +31,7 @@ use tokio_timer::Timer; use super::*; #[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Clone, Copy)] -struct ValidatorId(usize); +struct AuthorityId(usize); #[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Clone)] struct Digest(Vec); @@ -52,8 +52,8 @@ struct Proposal { #[derive(PartialEq, Eq, Debug, Clone)] enum Signature { - Table(ValidatorId, table::Statement), - Bft(ValidatorId, bft::Message), + Table(AuthorityId, table::Statement), + Bft(AuthorityId, bft::Message), } enum Error { @@ -72,11 +72,11 @@ struct SharedTestContext { #[derive(Debug, Clone)] struct TestContext { shared: Arc, - local_id: ValidatorId, + local_id: AuthorityId, } impl Context for TestContext { - type ValidatorId = ValidatorId; + type AuthorityId = AuthorityId; type Digest = Digest; type GroupId = GroupId; type Signature = Signature; @@ -87,8 +87,8 @@ impl Context for TestContext { type CheckAvailability = Box>; type StatementBatch = VecBatch< - ValidatorId, - table::SignedStatement + AuthorityId, + table::SignedStatement >; fn candidate_digest(candidate: &ParachainCandidate) -> Digest { @@ -106,8 +106,8 @@ impl Context for TestContext { candidate.group.clone() } - fn round_proposer(&self, round: usize) -> ValidatorId { - ValidatorId(round % self.shared.n_authorities) + fn round_proposer(&self, round: usize) -> AuthorityId { + AuthorityId(round % self.shared.n_authorities) } fn check_validity(&self, _candidate: &ParachainCandidate) -> Self::CheckCandidate { @@ -151,7 +151,7 @@ impl Context for TestContext { } } - fn local_id(&self) -> ValidatorId { + fn local_id(&self) -> AuthorityId { self.local_id.clone() } @@ -261,7 +261,7 @@ impl ::StatementBatch for VecBatch { } fn make_group_assignments(n_authorities: usize, n_groups: usize) - -> HashMap> + -> HashMap> { let mut map = HashMap::new(); let threshold = (n_authorities / n_groups) / 2; @@ -286,23 +286,23 @@ fn make_group_assignments(n_authorities: usize, n_groups: usize) map.entry(GroupId(primary_group)) .or_insert_with(&make_blank_group) .validity_guarantors - .insert(ValidatorId(a_id)); + .insert(AuthorityId(a_id)); for &availability_group in &availability_groups { map.entry(GroupId(availability_group)) .or_insert_with(&make_blank_group) .availability_guarantors - .insert(ValidatorId(a_id)); + .insert(AuthorityId(a_id)); } } map } -fn make_blank_batch(n_authorities: usize) -> VecBatch { +fn make_blank_batch(n_authorities: usize) -> VecBatch { VecBatch { max_len: 20, - targets: (0..n_authorities).map(ValidatorId).collect(), + targets: (0..n_authorities).map(AuthorityId).collect(), items: Vec::new(), } } @@ -318,7 +318,7 @@ fn consensus_completes_with_minimum_good() { .num_slots(1 << 16) .build(); - let (network, inputs, outputs) = Network::<(ValidatorId, OutgoingMessage)>::new(n - f); + let (network, inputs, outputs) = Network::<(AuthorityId, OutgoingMessage)>::new(n - f); network.route_on_thread(); let shared_test_context = Arc::new(SharedTestContext { @@ -330,7 +330,7 @@ fn consensus_completes_with_minimum_good() { let groups = make_group_assignments(n, n_groups); let authorities = inputs.into_iter().zip(outputs).enumerate().map(|(raw_id, (input, output))| { - let id = ValidatorId(raw_id); + let id = AuthorityId(raw_id); let context = TestContext { shared: shared_test_context.clone(), local_id: id,