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

Candidate agreement "glue" code #34

Merged
merged 56 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
9e3a67b
candidate statement importing
rphmeier Dec 12, 2017
6ee2205
import votes on validity
rphmeier Dec 12, 2017
abe2e67
import availability votes
rphmeier Dec 12, 2017
41dd470
candidate receipt type
rphmeier Dec 12, 2017
68b7b12
make table mod public
rphmeier Dec 12, 2017
773cecb
test context for table
rphmeier Dec 12, 2017
f0cd751
add harness for tests
rphmeier Dec 13, 2017
f510e3d
some tests for misbehavior
rphmeier Dec 13, 2017
ee2a865
produce proposal from table
rphmeier Dec 13, 2017
9f88742
count candidate issuance as implicit vote
rphmeier Dec 13, 2017
7b6436e
keep track of messages known by validators
rphmeier Dec 13, 2017
0e13e28
Merge branch 'master' into rh-candidate-agreement
rphmeier Dec 14, 2017
85b0bf0
fix primitives compilation
rphmeier Dec 14, 2017
946f160
simple BFT agreement
rphmeier Dec 18, 2017
2f5e375
kill unused macro_use annotation
rphmeier Dec 18, 2017
73ce658
tests for BFT agreement
rphmeier Dec 18, 2017
adf8984
test for not concluding on different prepares
rphmeier Dec 18, 2017
0112657
return summary upon statement import
rphmeier Dec 18, 2017
6a7c2c0
accept bft agreement on proposal not locally submitted
rphmeier Dec 18, 2017
b617079
check justification set for BFT
rphmeier Dec 18, 2017
e3a046d
BFT rewrite: vote accumulator with tests
rphmeier Dec 21, 2017
02ac220
squash some warnings
rphmeier Dec 21, 2017
a93b231
a few more tests for the accumulator
rphmeier Dec 22, 2017
a16bfd2
add sender to table's signed statement
rphmeier Dec 22, 2017
28ef13d
implement honest node strategy for BFT
rphmeier Dec 27, 2017
a52569e
inex -> index
rphmeier Dec 27, 2017
dfa1c12
import and broadcast lock proofs
rphmeier Dec 27, 2017
800ce6f
poll repeatedly when state changes
rphmeier Dec 27, 2017
92d8510
don't broadcast advance vote immediately if locked
rphmeier Dec 27, 2017
fefb5ca
do not check validity of locked candidate
rphmeier Dec 27, 2017
0c7928d
basic tests for the strategy
rphmeier Dec 27, 2017
409920a
remove unused context trait and fix warning
rphmeier Dec 29, 2017
922d547
address some review grumbles
rphmeier Dec 29, 2017
e594f61
address some more review nits
rphmeier Dec 29, 2017
f8b160f
fix lock import logic and add a test
rphmeier Dec 29, 2017
48712d6
fix spaces
rphmeier Dec 29, 2017
91fb389
fix a couple more style grumbles
rphmeier Dec 31, 2017
443d3ef
more type-safe justifications
rphmeier Jan 1, 2018
34f28c7
rename Communication enum variants
rphmeier Jan 1, 2018
0951a3b
improve some panic guard proofs
rphmeier Jan 1, 2018
96cc399
add trailing comma
rphmeier Jan 1, 2018
3f491ec
define context trait and initialize statement table
rphmeier Jan 3, 2018
1b52a6a
beginnings of shared table
rphmeier Jan 8, 2018
e490e3a
instantiate the agreement future
rphmeier Jan 8, 2018
7111e19
round-robin message handler
rphmeier Jan 9, 2018
854ed53
incoming message handler
rphmeier Jan 10, 2018
6edfd27
create the overarching agreement and IO futures
rphmeier Jan 10, 2018
e0248bd
Merge branch 'master' into rh-candidate-agreement-glue
rphmeier Jan 10, 2018
e6c0d09
update parking_lot
rphmeier Jan 10, 2018
e2dd5a4
fill batch statements from table
rphmeier Jan 12, 2018
17f489f
add test for batch filling
rphmeier Jan 12, 2018
4159bea
import a local candidate when it is available
rphmeier Jan 13, 2018
ec5e720
test context for full agreement protocol
rphmeier Jan 14, 2018
1aa5309
initial test harness
rphmeier Jan 16, 2018
43d4eaf
test consensus completion
rphmeier Jan 16, 2018
ad9913a
validator -> authority
rphmeier Jan 16, 2018
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
13 changes: 12 additions & 1 deletion Cargo.lock

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

5 changes: 3 additions & 2 deletions candidate-agreement/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ version = "0.1.0"
authors = ["Parity Technologies <[email protected]>"]

[dependencies]
futures = "0.1"
polkadot-primitives = { path = "../primitives" }
futures = "0.1.17"
parking_lot = "0.4"
tokio-timer = "0.1.2"
89 changes: 42 additions & 47 deletions candidate-agreement/src/bft/accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Candidate, Digest, ValidatorId, Signature>
pub struct Accumulator<Candidate, Digest, AuthorityId, Signature>
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<Candidate>,
prepares: HashMap<ValidatorId, (Digest, Signature)>,
commits: HashMap<ValidatorId, (Digest, Signature)>,
prepares: HashMap<AuthorityId, (Digest, Signature)>,
commits: HashMap<AuthorityId, (Digest, Signature)>,
vote_counts: HashMap<Digest, VoteCounts>,
advance_round: HashSet<ValidatorId>,
advance_round: HashSet<AuthorityId>,
state: State<Candidate, Digest, Signature>,
}

impl<Candidate, Digest, ValidatorId, Signature> Accumulator<Candidate, Digest, ValidatorId, Signature>
impl<Candidate, Digest, AuthorityId, Signature> Accumulator<Candidate, Digest, AuthorityId, Signature>
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,
Expand All @@ -171,11 +171,6 @@ impl<Candidate, Digest, ValidatorId, Signature> Accumulator<Candidate, Digest, V
self.round_number.clone()
}

/// Get the round proposer.
pub fn round_proposer(&self) -> &ValidatorId {
&self.round_proposer
}

pub fn proposal(&self) -> Option<&Candidate> {
self.proposal.as_ref()
}
Expand All @@ -189,7 +184,7 @@ impl<Candidate, Digest, ValidatorId, Signature> Accumulator<Candidate, Digest, V
/// and authorization should have already been checked.
pub fn import_message(
&mut self,
message: LocalizedMessage<Candidate, Digest, ValidatorId, Signature>,
message: LocalizedMessage<Candidate, Digest, AuthorityId, Signature>,
)
{
// message from different round.
Expand All @@ -210,7 +205,7 @@ impl<Candidate, Digest, ValidatorId, Signature> Accumulator<Candidate, Digest, V
fn import_proposal(
&mut self,
proposal: Candidate,
sender: ValidatorId,
sender: AuthorityId,
) {
if sender != self.round_proposer || self.proposal.is_some() { return }

Expand All @@ -221,7 +216,7 @@ impl<Candidate, Digest, ValidatorId, Signature> Accumulator<Candidate, Digest, V
fn import_prepare(
&mut self,
digest: Digest,
sender: ValidatorId,
sender: AuthorityId,
signature: Signature,
) {
// ignore any subsequent prepares by the same sender.
Expand Down Expand Up @@ -264,7 +259,7 @@ impl<Candidate, Digest, ValidatorId, Signature> Accumulator<Candidate, Digest, V
fn import_commit(
&mut self,
digest: Digest,
sender: ValidatorId,
sender: AuthorityId,
signature: Signature,
) {
// ignore any subsequent commits by the same sender.
Expand Down Expand Up @@ -304,7 +299,7 @@ impl<Candidate, Digest, ValidatorId, Signature> Accumulator<Candidate, Digest, V

fn import_advance_round(
&mut self,
sender: ValidatorId,
sender: AuthorityId,
) {
self.advance_round.insert(sender);

Expand Down Expand Up @@ -332,7 +327,7 @@ mod tests {
pub struct Digest(usize);

#[derive(Hash, PartialEq, Eq, Debug)]
pub struct ValidatorId(usize);
pub struct AuthorityId(usize);

#[derive(PartialEq, Eq, Clone, Debug)]
pub struct Signature(usize, usize);
Expand All @@ -347,7 +342,7 @@ mod tests {

let check_message = |r, d: &Digest, s: &Signature| {
if r == 2 && d.0 == 600 && s.0 == 600 {
Some(ValidatorId(s.1))
Some(AuthorityId(s.1))
} else {
None
}
Expand All @@ -370,19 +365,19 @@ mod tests {

#[test]
fn accepts_proposal_from_proposer_only() {
let mut accumulator = Accumulator::<_, Digest, _, _>::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)),
});

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)),
});
Expand All @@ -392,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)),
});
Expand All @@ -405,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)),
});
Expand All @@ -414,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)),
});
Expand All @@ -427,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)),
});
Expand All @@ -440,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)),
});
Expand All @@ -449,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)),
});
Expand All @@ -461,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)),
});
Expand All @@ -473,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)),
});
Expand All @@ -486,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)),
});
Expand All @@ -499,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)),
});
Expand All @@ -512,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),
});
Expand All @@ -524,7 +519,7 @@ mod tests {
}

accumulator.import_message(LocalizedMessage {
sender: ValidatorId(7),
sender: AuthorityId(7),
signature: Signature(999, 7),
message: Message::AdvanceRound(1),
});
Expand All @@ -537,12 +532,12 @@ mod tests {

#[test]
fn conclude_different_than_proposed() {
let mut accumulator = Accumulator::<Candidate, _, _, _>::new(1, 7, ValidatorId(8));
let mut accumulator = Accumulator::<Candidate, _, _, _>::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)),
});
Expand All @@ -555,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)),
});
Expand All @@ -569,12 +564,12 @@ mod tests {

#[test]
fn begin_to_advance() {
let mut accumulator = Accumulator::<Candidate, Digest, _, _>::new(1, 7, ValidatorId(8));
let mut accumulator = Accumulator::<Candidate, Digest, _, _>::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),
});
Expand All @@ -588,12 +583,12 @@ mod tests {

#[test]
fn conclude_without_prepare() {
let mut accumulator = Accumulator::<Candidate, _, _, _>::new(1, 7, ValidatorId(8));
let mut accumulator = Accumulator::<Candidate, _, _, _>::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)),
});
Expand Down
Loading