-
Notifications
You must be signed in to change notification settings - Fork 65
apollo_consensus: add faulty nodes to the sim test #10964
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
apollo_consensus: add faulty nodes to the sim test #10964
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
5959058 to
333735c
Compare
70fb297 to
178a8c3
Compare
333735c to
c034f88
Compare
178a8c3 to
d6d2d07
Compare
c034f88 to
e3f73d7
Compare
d6d2d07 to
900acc4
Compare
e3f73d7 to
c228f4a
Compare
matanl-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matanl-starkware reviewed 1 file and all commit messages, and made 10 comments.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @asmaastarkware and @dafnamatsry).
crates/apollo_consensus/src/simulation_test.rs line 99 at r1 (raw file):
/// Generates a "fake" commitment for equivocation/conflict attacks. fn fake_commitment_for_round(round: Round) -> ProposalCommitment {
Consider using existing proposal_commitment_for_round() fn, with an additional parameter
Code quote:
fake_commitment_for_roundcrates/apollo_consensus/src/simulation_test.rs line 134 at r1 (raw file):
round_stats: HashMap<(Round, ProposalCommitment), (HashSet<Vote>, bool)>, /// Tracks which voters have already voted for each round (to detect conflicts/duplicates). voter_first_vote: HashSet<(Round, ValidatorId)>,
Wouldn't it be easier to keep a HashMap with the value of commitment, to easily count equivocators?
Code quote:
HashSet<(Round, ValidatorId)>crates/apollo_consensus/src/simulation_test.rs line 139 at r1 (raw file):
impl DiscreteEventSimulation { fn new(total_nodes: usize, honest_nodes: usize, seed: u64, keep_ratio: f64) -> Self { assert!(honest_nodes <= total_nodes, "honest_nodes must be <= total_nodes");
You can also verify: 0<= keep_ratio <= 1
crates/apollo_consensus/src/simulation_test.rs line 173 at r1 (raw file):
/// Uses deterministic randomness based on node index and round. fn get_fault_type(&mut self, node_idx: usize, round: Round) -> FaultType { let node_idx_u64 = u64::try_from(node_idx).unwrap_or(0);
It should never be a problem, unless there's a bug.
Suggestion:
unwrap()crates/apollo_consensus/src/simulation_test.rs line 184 at r1 (raw file):
// Randomly select a fault type let fault_types = [
Suggestion:
const FAULT_TYPES: &[FaultType] = &[crates/apollo_consensus/src/simulation_test.rs line 191 at r1 (raw file):
FaultType::NonValidator, ]; let idx = fault_rng.gen_range(0..fault_types.len());
use rand::seq::SliceRandom;
Suggestion:
let fault = *FAULT_TYPES.choose(&mut fault_rng).unwrap();crates/apollo_consensus/src/simulation_test.rs line 273 at r1 (raw file):
// Handle leader proposal (only if leader is honest and not node 0) if leader_idx != 0 && leader_idx < self.honest_nodes {
Define as const
Code quote:
0crates/apollo_consensus/src/simulation_test.rs line 273 at r1 (raw file):
// Handle leader proposal (only if leader is honest and not node 0) if leader_idx != 0 && leader_idx < self.honest_nodes {
If self.honest_nodes = 2, you want to allow leader_idx [1,2] to propose.
Suggestion:
<= crates/apollo_consensus/src/simulation_test.rs line 315 at r1 (raw file):
self.schedule_prevote_and_precommit(node_id, round, proposal_commitment); let conflicting_commitment = Some(fake_commitment_for_round(round)); self.schedule_prevote_and_precommit(node_id, round, conflicting_commitment);
Order of voting matters?
Consider sometimes sending the erroneous vote first
Code quote:
self.schedule_prevote_and_precommit(node_id, round, proposal_commitment);
let conflicting_commitment = Some(fake_commitment_for_round(round));
self.schedule_prevote_and_precommit(node_id, round, conflicting_commitment);crates/apollo_consensus/src/simulation_test.rs line 352 at r1 (raw file):
if !self.validators.contains(&vote.voter) { return; }
Since you know how it was implemented, you can compare the id vs. TOTAL_NODES.
Current check is O(n)
Code quote:
if !self.validators.contains(&vote.voter) {
return;
}c228f4a to
a1c1a15
Compare
asmaastarkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asmaastarkware made 8 comments.
Reviewable status: 0 of 1 files reviewed, 10 unresolved discussions (waiting on @dafnamatsry and @matanl-starkware).
crates/apollo_consensus/src/simulation_test.rs line 99 at r1 (raw file):
Previously, matanl-starkware (Matan Lior) wrote…
Consider using existing proposal_commitment_for_round() fn, with an additional parameter
Done.
crates/apollo_consensus/src/simulation_test.rs line 134 at r1 (raw file):
Previously, matanl-starkware (Matan Lior) wrote…
Wouldn't it be easier to keep a HashMap with the value of commitment, to easily count equivocators?
For equivocation we count the first vote not the second.. the value doesn't matter
crates/apollo_consensus/src/simulation_test.rs line 139 at r1 (raw file):
Previously, matanl-starkware (Matan Lior) wrote…
You can also verify: 0<= keep_ratio <= 1
Done.
crates/apollo_consensus/src/simulation_test.rs line 173 at r1 (raw file):
Previously, matanl-starkware (Matan Lior) wrote…
It should never be a problem, unless there's a bug.
Done.
crates/apollo_consensus/src/simulation_test.rs line 273 at r1 (raw file):
Previously, matanl-starkware (Matan Lior) wrote…
Define as const
Done.
crates/apollo_consensus/src/simulation_test.rs line 273 at r1 (raw file):
Previously, matanl-starkware (Matan Lior) wrote…
If self.honest_nodes = 2, you want to allow leader_idx [1,2] to propose.
Done.
crates/apollo_consensus/src/simulation_test.rs line 315 at r1 (raw file):
Previously, matanl-starkware (Matan Lior) wrote…
Order of voting matters?
Consider sometimes sending the erroneous vote first
Done.
crates/apollo_consensus/src/simulation_test.rs line 352 at r1 (raw file):
Previously, matanl-starkware (Matan Lior) wrote…
Since you know how it was implemented, you can compare the id vs. TOTAL_NODES.
Current check is O(n)
voter is a ContractAddress :(
matanl-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matanl-starkware reviewed 1 file and all commit messages, made 3 comments, and resolved 7 discussions.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @asmaastarkware and @dafnamatsry).
crates/apollo_consensus/src/simulation_test.rs line 352 at r1 (raw file):
Previously, asmaastarkware (asmaa-starkware) wrote…
voter is a ContractAddress :(
Maybe add TODO (keep validators as set)?
crates/apollo_consensus/src/simulation_test.rs line 309 at r2 (raw file):
FaultType::EquivocatorRealFirst => { self.schedule_prevote_and_precommit(node_id, round, proposal_commitment); let conflicting_commitment = Some(proposal_commitment_for_round(round, true));
Consider moving outside the match, for clarity.
Code quote:
let conflicting_commitment = Some(proposal_commitment_for_round(round, true));a1c1a15 to
3d8e367
Compare
matanl-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matanl-starkware reviewed 1 file and all commit messages, and resolved 2 discussions.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @asmaastarkware and @dafnamatsry).
3d8e367 to
fa562d7
Compare
900acc4 to
b353350
Compare
fa562d7 to
df15f49
Compare
b353350 to
fba9829
Compare
fba9829 to
a57fcc5
Compare
df15f49 to
eae26d0
Compare
a57fcc5 to
20f105c
Compare
5b94f3d to
42f99a2
Compare
1500d7a to
54525f0
Compare
42f99a2 to
3c5d331
Compare
7834218 to
db5fd8e
Compare
3c5d331 to
e4b0be8
Compare
db5fd8e to
4af840c
Compare
e4b0be8 to
bc1f76f
Compare
4af840c to
c367da5
Compare
64d8ab3 to
8f7eded
Compare
c367da5 to
a9f614d
Compare
matanl-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matanl-starkware reviewed 1 file and all commit messages, made 3 comments, and resolved 1 discussion.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @dafnamatsry).
crates/apollo_consensus/src/simulation_test.rs line 310 at r8 (raw file):
let proposal_tick = (round_start_tick + self.rng.gen_range(PROPOSAL_ARRIVAL_DELAY_RANGE)) .min(round_start_tick + ROUND_DURATION);
No need to leave some spare time for the votes?
Code quote:
ROUND_DURATIONcrates/apollo_consensus/src/simulation_test.rs line 434 at r8 (raw file):
if let Some(commitment) = commitment { let key = (round, commitment); let entry = self.round_stats.entry(key).or_insert_with(|| (HashSet::new(), false));
Consider extracting to a helper function to be also used in track_precommit
Code quote:
let key = (round, commitment);
let entry = self.round_stats.entry(key).or_insert_with(|| (HashSet::new(), false));crates/apollo_consensus/src/simulation_test.rs line 593 at r8 (raw file):
if total_precommits >= THRESHOLD { Some((*r, *commitment, precommits.clone()))
I'm not sure the clone is necessary
Code quote:
.clone()8f7eded to
db4bef2
Compare
4e8a975 to
c5575e4
Compare
db4bef2 to
eb1a9dd
Compare
dafnamatsry
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dafnamatsry reviewed 1 file and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @asmaastarkware).
eb1a9dd to
16c30b1
Compare
c5575e4 to
fc7d85b
Compare
9f35e4b

No description provided.