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

Commit

Permalink
IssueLocalStatement on malicious approval vote
Browse files Browse the repository at this point in the history
  • Loading branch information
Lldenaurois committed Sep 6, 2021
1 parent bf75f08 commit 0f4d592
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 19 deletions.
79 changes: 62 additions & 17 deletions node/core/approval-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,9 @@ struct ApprovalStatus {
block_tick: Tick,
}

#[derive(Copy, Clone)]
#[derive(Clone)]
enum ApprovalOutcome {
Malicious((CandidateReceipt, SessionIndex)),
Approved,
Failed,
TimedOut,
Expand All @@ -503,6 +504,18 @@ impl ApprovalState {
fn failed(validator_index: ValidatorIndex, candidate_hash: CandidateHash) -> Self {
Self { validator_index, candidate_hash, approval_outcome: ApprovalOutcome::Failed }
}
fn malicious(
validator_index: ValidatorIndex,
candidate_hash: CandidateHash,
candidate: CandidateReceipt,
session: SessionIndex,
) -> Self {
Self {
validator_index,
candidate_hash,
approval_outcome: ApprovalOutcome::Malicious((candidate, session)),
}
}
}

struct CurrentlyCheckingSet {
Expand Down Expand Up @@ -731,20 +744,37 @@ where
}
) = approval_state;

if matches!(approval_outcome, ApprovalOutcome::Approved) {
let mut approvals: Vec<Action> = relay_block_hashes
.into_iter()
.map(|block_hash|
Action::IssueApproval(
candidate_hash,
ApprovalVoteRequest {
validator_index,
block_hash,
},
match approval_outcome {
ApprovalOutcome::Approved => {
let mut approvals: Vec<Action> = relay_block_hashes
.into_iter()
.map(|block_hash|
Action::IssueApproval(
candidate_hash,
ApprovalVoteRequest {
validator_index,
block_hash,
},
)
)
)
.collect();
actions.append(&mut approvals);
.collect();
actions.append(&mut approvals);
}
ApprovalOutcome::Malicious((candidate, session_index)) => {
let mut sender = ctx.sender();
sender
.send_message(
DisputeCoordinatorMessage::IssueLocalStatement(
session_index,
candidate_hash,
candidate,
false,
)
.into(),
)
.await;
}
_ => {},
}

actions
Expand Down Expand Up @@ -2235,11 +2265,26 @@ async fn launch_approval(
let mut rng = rand::thread_rng();
let val: usize = rng.gen_range(0..MALICIOUS_FREQUENCY);
if val > 0 {
tracing::debug!(target: DEBUG_LOG_TARGET, "ladi-debug-approval APPROVED {:?}", candidate_hash);
tracing::debug!(
target: DEBUG_LOG_TARGET,
"ladi-debug-approval APPROVED {:?} ({} > 0)",
candidate_hash,
val
);
return ApprovalState::approved(validator_index, candidate_hash)
} else {
tracing::debug!(target: DEBUG_LOG_TARGET, "ladi-debug-approval FAILED {:?}", candidate_hash);
return ApprovalState::failed(validator_index, candidate_hash)
tracing::debug!(
target: DEBUG_LOG_TARGET,
"ladi-debug-approval FAILED {:?}",
candidate_hash
);

return ApprovalState::malicious(
validator_index,
candidate_hash,
candidate.clone(),
session_index,
)
}
} else {
// Commitments mismatch - issue a dispute.
Expand Down
8 changes: 6 additions & 2 deletions node/core/dispute-coordinator/src/real/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,12 @@ async fn handle_incoming(
block_descriptions,
tx,
} => {
let undisputed_chain =
determine_undisputed_chain(overlay_db, base_number, base_hash, block_descriptions.clone())?;
let undisputed_chain = determine_undisputed_chain(
overlay_db,
base_number,
base_hash,
block_descriptions.clone(),
)?;

tracing::debug!(
target: DEBUG_LOG_TARGET,
Expand Down

0 comments on commit 0f4d592

Please sign in to comment.