From 0f4d5929a2b28eb82b3a1ab9e87a8933449bb3a4 Mon Sep 17 00:00:00 2001 From: Lldenaurois Date: Mon, 6 Sep 2021 17:10:33 +0200 Subject: [PATCH] IssueLocalStatement on malicious approval vote --- node/core/approval-voting/src/lib.rs | 79 +++++++++++++++---- node/core/dispute-coordinator/src/real/mod.rs | 8 +- 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/node/core/approval-voting/src/lib.rs b/node/core/approval-voting/src/lib.rs index ebad6e353daf..972f03c342e4 100644 --- a/node/core/approval-voting/src/lib.rs +++ b/node/core/approval-voting/src/lib.rs @@ -483,8 +483,9 @@ struct ApprovalStatus { block_tick: Tick, } -#[derive(Copy, Clone)] +#[derive(Clone)] enum ApprovalOutcome { + Malicious((CandidateReceipt, SessionIndex)), Approved, Failed, TimedOut, @@ -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 { @@ -731,20 +744,37 @@ where } ) = approval_state; - if matches!(approval_outcome, ApprovalOutcome::Approved) { - let mut approvals: Vec = 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 = 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 @@ -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. diff --git a/node/core/dispute-coordinator/src/real/mod.rs b/node/core/dispute-coordinator/src/real/mod.rs index 121e663896d7..2db0e8435d7e 100644 --- a/node/core/dispute-coordinator/src/real/mod.rs +++ b/node/core/dispute-coordinator/src/real/mod.rs @@ -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,