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

Malus: improvements in dispute ancestor and suggest garbage candidate implementation #5011

Merged
merged 46 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
93656e2
Implement fake validation results
sandreim Feb 14, 2022
f216579
Merge branch 'master' of github.com:paritytech/polkadot into sandreim…
sandreim Feb 28, 2022
2744e75
refactor
sandreim Mar 1, 2022
9941f03
Merge branch 'master' of github.com:paritytech/polkadot into sandreim…
sandreim Mar 1, 2022
a3172b0
cargo lock
sandreim Mar 1, 2022
9100866
spell check
sandreim Mar 1, 2022
efd37ad
spellcheck
sandreim Mar 2, 2022
d4da58d
typos
sandreim Mar 2, 2022
b4719b4
Merge branch 'master' of github.com:paritytech/polkadot into sandreim…
sandreim Mar 4, 2022
b70512b
Review feedback
sandreim Mar 10, 2022
050bab4
Merge branch 'master' of github.com:paritytech/polkadot into sandreim…
sandreim Mar 10, 2022
f786866
move stuff around
sandreim Mar 10, 2022
9e72a42
Merge branch 'master' of github.com:paritytech/polkadot into sandreim…
sandreim Mar 23, 2022
c4a4560
chores
sandreim Mar 23, 2022
e90ab09
Impl valid - still wip
sandreim Mar 24, 2022
8226f4e
fixes
sandreim Mar 26, 2022
35c8c8e
fmt
sandreim Mar 26, 2022
1c279dc
Pull Ladi's implementation:
sandreim Mar 28, 2022
8932494
Fix build
sandreim Mar 28, 2022
fb75de4
Logs and comments
sandreim Mar 28, 2022
9408f45
WIP: suggest garbage candidate + implement validation result caching
sandreim Mar 28, 2022
78ed119
fix
sandreim Mar 28, 2022
efe4e50
Do commitment hash checks in candidate validation
sandreim Mar 30, 2022
1d02b2a
Minor refactor in approval, backing, dispute-coord
sandreim Mar 30, 2022
4719ad3
Working version of suggest garbage candidate
sandreim Mar 30, 2022
519d693
Dedup
sandreim Mar 30, 2022
6724b4a
cleanup #1
sandreim Mar 31, 2022
b6e1bbd
Fix tests
sandreim Apr 1, 2022
1980661
Merge branch 'master' of github.com:paritytech/polkadot into sandreim…
sandreim Apr 1, 2022
5f29b6c
remove debug leftovers
sandreim Apr 1, 2022
ea2b1e5
fmt
sandreim Apr 1, 2022
fca095f
Accidentally commited some local test
sandreim Apr 1, 2022
7d6b472
spellcheck
sandreim Apr 1, 2022
3103ce7
some more fixes
sandreim Apr 4, 2022
bde2403
Refactor and fix it
sandreim Apr 8, 2022
3784972
review feedback
sandreim Apr 8, 2022
991d77f
typo
sandreim Apr 8, 2022
0fa5890
tests review feedback
sandreim Apr 8, 2022
71c35a9
refactor disputer
sandreim Apr 8, 2022
fee4722
fix tests
sandreim Apr 8, 2022
6fb63d2
Fix zombienet disputes test
sandreim Apr 11, 2022
e29433e
Merge branch 'master' of github.com:paritytech/polkadot into sandreim…
sandreim Apr 11, 2022
ab22c59
spellcheck
sandreim Apr 11, 2022
f67b522
fix
sandreim Apr 11, 2022
6181157
Fix ui tests
sandreim Apr 11, 2022
155524c
fix typo
sandreim Apr 11, 2022
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub struct ValidationWorkerCommand {

#[allow(missing_docs)]
#[derive(Debug, Parser)]
#[cfg_attr(feature = "malus", derive(Clone))]
pub struct RunCmd {
#[allow(missing_docs)]
#[clap(flatten)]
Expand Down
1 change: 1 addition & 0 deletions node/core/approval-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,7 @@ async fn launch_approval(
available_data.pov,
APPROVAL_EXECUTION_TIMEOUT,
val_tx,
candidate.commitments_hash,
sandreim marked this conversation as resolved.
Show resolved Hide resolved
)
.into(),
)
Expand Down
2 changes: 1 addition & 1 deletion node/core/approval-voting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2403,7 +2403,7 @@ pub async fn handle_double_assignment_import(
assert_eq!(candidate_index, c_index);
},
AllMessages::CandidateValidation(
CandidateValidationMessage::ValidateFromExhaustive(_, _, _, _, timeout, tx),
CandidateValidationMessage::ValidateFromExhaustive(_, _, _, _, timeout, tx, _),
) if timeout == APPROVAL_EXECUTION_TIMEOUT => {
tx.send(Ok(ValidationResult::Valid(Default::default(), Default::default())))
.unwrap();
Expand Down
80 changes: 43 additions & 37 deletions node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use futures::{
};

use polkadot_node_primitives::{
AvailableData, PoV, SignedDisputeStatement, SignedFullStatement, Statement, ValidationResult,
BACKING_EXECUTION_TIMEOUT,
AvailableData, InvalidCandidate, PoV, SignedDisputeStatement, SignedFullStatement, Statement,
ValidationResult, BACKING_EXECUTION_TIMEOUT,
};
use polkadot_node_subsystem_util::{
self as util,
Expand Down Expand Up @@ -380,6 +380,7 @@ async fn request_candidate_validation(
sender: &mut JobSender<impl SubsystemSender>,
candidate: CandidateDescriptor,
pov: Arc<PoV>,
commitments_hash: Hash,
) -> Result<ValidationResult, Error> {
let (tx, rx) = oneshot::channel();

Expand All @@ -389,6 +390,7 @@ async fn request_candidate_validation(
pov,
BACKING_EXECUTION_TIMEOUT,
tx,
commitments_hash,
))
.await;

Expand Down Expand Up @@ -450,17 +452,23 @@ async fn validate_and_make_available(
},
};

let expected_commitments_hash = candidate.commitments_hash;

let v = {
let _span = span.as_ref().map(|s| {
s.child("request-validation")
.with_pov(&pov)
.with_para_id(candidate.descriptor().para_id)
});
request_candidate_validation(&mut sender, candidate.descriptor.clone(), pov.clone()).await?
request_candidate_validation(
&mut sender,
candidate.descriptor.clone(),
pov.clone(),
expected_commitments_hash,
)
.await?
};

let expected_commitments_hash = candidate.commitments_hash;

let res = match v {
ValidationResult::Valid(commitments, validation_data) => {
gum::debug!(
Expand All @@ -469,41 +477,39 @@ async fn validate_and_make_available(
"Validation successful",
);

// If validation produces a new set of commitments, we vote the candidate as invalid.
if commitments.hash() != expected_commitments_hash {
sandreim marked this conversation as resolved.
Show resolved Hide resolved
gum::debug!(
target: LOG_TARGET,
candidate_hash = ?candidate.hash(),
actual_commitments = ?commitments,
"Commitments obtained with validation don't match the announced by the candidate receipt",
);
Err(candidate)
} else {
let erasure_valid = make_pov_available(
&mut sender,
n_validators,
pov.clone(),
candidate.hash(),
validation_data,
candidate.descriptor.erasure_root,
span.as_ref(),
)
.await?;
let erasure_valid = make_pov_available(
&mut sender,
n_validators,
pov.clone(),
candidate.hash(),
validation_data,
candidate.descriptor.erasure_root,
span.as_ref(),
)
.await?;

match erasure_valid {
Ok(()) => Ok((candidate, commitments, pov.clone())),
Err(InvalidErasureRoot) => {
gum::debug!(
target: LOG_TARGET,
candidate_hash = ?candidate.hash(),
actual_commitments = ?commitments,
"Erasure root doesn't match the announced by the candidate receipt",
);
Err(candidate)
},
}
match erasure_valid {
Ok(()) => Ok((candidate, commitments, pov.clone())),
Err(InvalidErasureRoot) => {
gum::debug!(
target: LOG_TARGET,
candidate_hash = ?candidate.hash(),
actual_commitments = ?commitments,
"Erasure root doesn't match the announced by the candidate receipt",
);
Err(candidate)
},
}
},
ValidationResult::Invalid(InvalidCandidate::ComittmentsHashMismatch) => {
sandreim marked this conversation as resolved.
Show resolved Hide resolved
// If validation produces a new set of commitments, we vote the candidate as invalid.
gum::warn!(
target: LOG_TARGET,
candidate_hash = ?candidate.hash(),
"Validation yielded different commitments",
);
Err(candidate)
},
ValidationResult::Invalid(reason) => {
gum::debug!(
target: LOG_TARGET,
Expand Down
30 changes: 23 additions & 7 deletions node/core/backing/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ fn backing_second_works() {
pov,
timeout,
tx,
commitments_hash
)
) if pov == pov && &c == candidate.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT => {
) if pov == pov && &c == candidate.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT && commitments_hash == candidate.commitments.hash() => {
tx.send(Ok(
ValidationResult::Valid(CandidateCommitments {
head_data: expected_head_data.clone(),
Expand Down Expand Up @@ -419,6 +420,8 @@ fn backing_works() {
.build();

let candidate_a_hash = candidate_a.hash();
let candidate_a_commitments_hash = candidate_a.commitments.hash();

let public1 = CryptoStore::sr25519_generate_new(
&*test_state.keystore,
ValidatorId::ID,
Expand Down Expand Up @@ -496,8 +499,9 @@ fn backing_works() {
pov,
timeout,
tx,
hash
)
) if pov == pov && &c == candidate_a.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT => {
) if pov == pov && &c == candidate_a.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT && hash == candidate_a_commitments_hash=> {
tx.send(Ok(
ValidationResult::Valid(CandidateCommitments {
head_data: expected_head_data.clone(),
Expand Down Expand Up @@ -594,6 +598,8 @@ fn backing_works_while_validation_ongoing() {
.build();

let candidate_a_hash = candidate_a.hash();
let candidate_a_commitments_hash = candidate_a.commitments.hash();

let public1 = CryptoStore::sr25519_generate_new(
&*test_state.keystore,
ValidatorId::ID,
Expand Down Expand Up @@ -690,8 +696,9 @@ fn backing_works_while_validation_ongoing() {
pov,
timeout,
tx,
hash
)
) if pov == pov && &c == candidate_a.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT => {
) if pov == pov && &c == candidate_a.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT && candidate_a_commitments_hash == hash => {
// we never validate the candidate. our local node
// shouldn't issue any statements.
std::mem::forget(tx);
Expand Down Expand Up @@ -799,6 +806,8 @@ fn backing_misbehavior_works() {
.build();

let candidate_a_hash = candidate_a.hash();
let candidate_a_commitments_hash = candidate_a.commitments.hash();

let public2 = CryptoStore::sr25519_generate_new(
&*test_state.keystore,
ValidatorId::ID,
Expand Down Expand Up @@ -864,8 +873,9 @@ fn backing_misbehavior_works() {
pov,
timeout,
tx,
hash
)
) if pov == pov && &c == candidate_a.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT => {
) if pov == pov && &c == candidate_a.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT && candidate_a_commitments_hash == hash => {
tx.send(Ok(
ValidationResult::Valid(CandidateCommitments {
head_data: expected_head_data.clone(),
Expand Down Expand Up @@ -1024,6 +1034,7 @@ fn backing_dont_second_invalid() {
pov,
timeout,
tx,
_
)
) if pov == pov && &c == candidate_a.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT => {
tx.send(Ok(ValidationResult::Invalid(InvalidCandidate::BadReturn))).unwrap();
Expand Down Expand Up @@ -1053,6 +1064,7 @@ fn backing_dont_second_invalid() {
pov,
timeout,
tx,
_
)
) if pov == pov && &c == candidate_b.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT => {
tx.send(Ok(
Expand Down Expand Up @@ -1184,8 +1196,9 @@ fn backing_second_after_first_fails_works() {
pov,
timeout,
tx,
hash
)
) if pov == pov && &c == candidate.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT => {
) if pov == pov && &c == candidate.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT && hash == candidate.commitments.hash() => {
tx.send(Ok(ValidationResult::Invalid(InvalidCandidate::BadReturn))).unwrap();
}
);
Expand Down Expand Up @@ -1232,6 +1245,7 @@ fn backing_second_after_first_fails_works() {
pov,
_,
_,
_,
)
) => {
assert_eq!(&*pov, &pov_to_second);
Expand Down Expand Up @@ -1318,8 +1332,9 @@ fn backing_works_after_failed_validation() {
pov,
timeout,
tx,
hash
)
) if pov == pov && &c == candidate.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT => {
) if pov == pov && &c == candidate.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT && hash == candidate.commitments.hash() => {
tx.send(Err(ValidationFailed("Internal test error".into()))).unwrap();
}
);
Expand Down Expand Up @@ -1696,8 +1711,9 @@ fn retry_works() {
pov,
timeout,
_tx,
hash,
)
) if pov == pov && &c == candidate.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT
) if pov == pov && &c == candidate.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT && hash == candidate.commitments.hash()
);
virtual_overseer
});
Expand Down
Loading