mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 08:41:07 +00:00
Malus: improvements in dispute ancestor and suggest garbage candidate implementation (#5011)
* Implement fake validation results Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * refactor Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * cargo lock Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * spell check Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * spellcheck Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * typos Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Review feedback Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * move stuff around Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * chores Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Impl valid - still wip Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fixes Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fmt Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Pull Ladi's implementation: https://github.com/paritytech/polkadot/pull/4711 Co-authored-by: Lldenaurois <Ljdenaurois@gmail.com> Co-authored-by: Andrei Sandu <andrei-mihail@parity.io> Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Fix build Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Logs and comments Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * WIP: suggest garbage candidate + implement validation result caching Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fix Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Do commitment hash checks in candidate validation Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Minor refactor in approval, backing, dispute-coord Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Working version of suggest garbage candidate Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Dedup Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * cleanup #1 Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Fix tests Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * remove debug leftovers Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fmt Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Accidentally commited some local test Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * spellcheck Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * some more fixes Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Refactor and fix it Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * review feedback Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * typo Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * tests review feedback Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * refactor disputer Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fix tests Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Fix zombienet disputes test Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * spellcheck Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fix Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Fix ui tests Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fix typo Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> Co-authored-by: Lldenaurois <Ljdenaurois@gmail.com>
This commit is contained in:
@@ -41,7 +41,7 @@ use polkadot_node_subsystem::{
|
||||
use polkadot_node_subsystem_util::metrics::{self, prometheus};
|
||||
use polkadot_parachain::primitives::{ValidationParams, ValidationResult as WasmValidationResult};
|
||||
use polkadot_primitives::v2::{
|
||||
CandidateCommitments, CandidateDescriptor, Hash, OccupiedCoreAssumption,
|
||||
CandidateCommitments, CandidateDescriptor, CandidateReceipt, Hash, OccupiedCoreAssumption,
|
||||
PersistedValidationData, ValidationCode, ValidationCodeHash,
|
||||
};
|
||||
|
||||
@@ -134,7 +134,7 @@ where
|
||||
FromOverseer::Signal(OverseerSignal::Conclude) => return Ok(()),
|
||||
FromOverseer::Communication { msg } => match msg {
|
||||
CandidateValidationMessage::ValidateFromChainState(
|
||||
descriptor,
|
||||
candidate_receipt,
|
||||
pov,
|
||||
timeout,
|
||||
response_sender,
|
||||
@@ -149,7 +149,7 @@ where
|
||||
let res = validate_from_chain_state(
|
||||
&mut sender,
|
||||
validation_host,
|
||||
descriptor,
|
||||
candidate_receipt,
|
||||
pov,
|
||||
timeout,
|
||||
&metrics,
|
||||
@@ -166,7 +166,7 @@ where
|
||||
CandidateValidationMessage::ValidateFromExhaustive(
|
||||
persisted_validation_data,
|
||||
validation_code,
|
||||
descriptor,
|
||||
candidate_receipt,
|
||||
pov,
|
||||
timeout,
|
||||
response_sender,
|
||||
@@ -181,7 +181,7 @@ where
|
||||
validation_host,
|
||||
persisted_validation_data,
|
||||
validation_code,
|
||||
descriptor,
|
||||
candidate_receipt,
|
||||
pov,
|
||||
timeout,
|
||||
&metrics,
|
||||
@@ -413,10 +413,32 @@ where
|
||||
AssumptionCheckOutcome::DoesNotMatch
|
||||
}
|
||||
|
||||
/// Returns validation data for a given candidate.
|
||||
pub async fn find_validation_data<Sender>(
|
||||
sender: &mut Sender,
|
||||
descriptor: &CandidateDescriptor,
|
||||
) -> Result<Option<(PersistedValidationData, ValidationCode)>, ValidationFailed>
|
||||
where
|
||||
Sender: SubsystemSender,
|
||||
{
|
||||
match find_assumed_validation_data(sender, &descriptor).await {
|
||||
AssumptionCheckOutcome::Matches(validation_data, validation_code) =>
|
||||
Ok(Some((validation_data, validation_code))),
|
||||
AssumptionCheckOutcome::DoesNotMatch => {
|
||||
// If neither the assumption of the occupied core having the para included or the assumption
|
||||
// of the occupied core timing out are valid, then the persisted_validation_data_hash in the descriptor
|
||||
// is not based on the relay parent and is thus invalid.
|
||||
Ok(None)
|
||||
},
|
||||
AssumptionCheckOutcome::BadRequest =>
|
||||
Err(ValidationFailed("Assumption Check: Bad request".into())),
|
||||
}
|
||||
}
|
||||
|
||||
async fn validate_from_chain_state<Sender>(
|
||||
sender: &mut Sender,
|
||||
validation_host: ValidationHost,
|
||||
descriptor: CandidateDescriptor,
|
||||
candidate_receipt: CandidateReceipt,
|
||||
pov: Arc<PoV>,
|
||||
timeout: Duration,
|
||||
metrics: &Metrics,
|
||||
@@ -424,25 +446,18 @@ async fn validate_from_chain_state<Sender>(
|
||||
where
|
||||
Sender: SubsystemSender,
|
||||
{
|
||||
let mut new_sender = sender.clone();
|
||||
let (validation_data, validation_code) =
|
||||
match find_assumed_validation_data(sender, &descriptor).await {
|
||||
AssumptionCheckOutcome::Matches(validation_data, validation_code) =>
|
||||
(validation_data, validation_code),
|
||||
AssumptionCheckOutcome::DoesNotMatch => {
|
||||
// If neither the assumption of the occupied core having the para included or the assumption
|
||||
// of the occupied core timing out are valid, then the persisted_validation_data_hash in the descriptor
|
||||
// is not based on the relay parent and is thus invalid.
|
||||
return Ok(ValidationResult::Invalid(InvalidCandidate::BadParent))
|
||||
},
|
||||
AssumptionCheckOutcome::BadRequest =>
|
||||
return Err(ValidationFailed("Assumption Check: Bad request".into())),
|
||||
match find_validation_data(&mut new_sender, &candidate_receipt.descriptor).await? {
|
||||
Some((validation_data, validation_code)) => (validation_data, validation_code),
|
||||
None => return Ok(ValidationResult::Invalid(InvalidCandidate::BadParent)),
|
||||
};
|
||||
|
||||
let validation_result = validate_candidate_exhaustive(
|
||||
validation_host,
|
||||
validation_data,
|
||||
validation_code,
|
||||
descriptor.clone(),
|
||||
candidate_receipt.clone(),
|
||||
pov,
|
||||
timeout,
|
||||
metrics,
|
||||
@@ -450,11 +465,20 @@ where
|
||||
.await;
|
||||
|
||||
if let Ok(ValidationResult::Valid(ref outputs, _)) = validation_result {
|
||||
// If validation produces new commitments we consider the candidate invalid.
|
||||
if candidate_receipt.commitments_hash != outputs.hash() {
|
||||
return Ok(ValidationResult::Invalid(InvalidCandidate::CommitmentsHashMismatch))
|
||||
}
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
match runtime_api_request(
|
||||
sender,
|
||||
descriptor.relay_parent,
|
||||
RuntimeApiRequest::CheckValidationOutputs(descriptor.para_id, outputs.clone(), tx),
|
||||
candidate_receipt.descriptor.relay_parent,
|
||||
RuntimeApiRequest::CheckValidationOutputs(
|
||||
candidate_receipt.descriptor.para_id,
|
||||
outputs.clone(),
|
||||
tx,
|
||||
),
|
||||
rx,
|
||||
)
|
||||
.await
|
||||
@@ -473,7 +497,7 @@ async fn validate_candidate_exhaustive(
|
||||
mut validation_backend: impl ValidationBackend,
|
||||
persisted_validation_data: PersistedValidationData,
|
||||
validation_code: ValidationCode,
|
||||
descriptor: CandidateDescriptor,
|
||||
candidate_receipt: CandidateReceipt,
|
||||
pov: Arc<PoV>,
|
||||
timeout: Duration,
|
||||
metrics: &Metrics,
|
||||
@@ -484,12 +508,12 @@ async fn validate_candidate_exhaustive(
|
||||
gum::debug!(
|
||||
target: LOG_TARGET,
|
||||
?validation_code_hash,
|
||||
para_id = ?descriptor.para_id,
|
||||
para_id = ?candidate_receipt.descriptor.para_id,
|
||||
"About to validate a candidate.",
|
||||
);
|
||||
|
||||
if let Err(e) = perform_basic_checks(
|
||||
&descriptor,
|
||||
&candidate_receipt.descriptor,
|
||||
persisted_validation_data.max_pov_size,
|
||||
&*pov,
|
||||
&validation_code_hash,
|
||||
@@ -555,7 +579,7 @@ async fn validate_candidate_exhaustive(
|
||||
Ok(ValidationResult::Invalid(InvalidCandidate::ExecutionError(e))),
|
||||
|
||||
Ok(res) =>
|
||||
if res.head_data.hash() != descriptor.para_head {
|
||||
if res.head_data.hash() != candidate_receipt.descriptor.para_head {
|
||||
Ok(ValidationResult::Invalid(InvalidCandidate::ParaHeadHashMismatch))
|
||||
} else {
|
||||
let outputs = CandidateCommitments {
|
||||
@@ -566,7 +590,12 @@ async fn validate_candidate_exhaustive(
|
||||
processed_downward_messages: res.processed_downward_messages,
|
||||
hrmp_watermark: res.hrmp_watermark,
|
||||
};
|
||||
Ok(ValidationResult::Valid(outputs, persisted_validation_data))
|
||||
if candidate_receipt.commitments_hash != outputs.hash() {
|
||||
// If validation produced a new set of commitments, we treat the candidate as invalid.
|
||||
Ok(ValidationResult::Invalid(InvalidCandidate::CommitmentsHashMismatch))
|
||||
} else {
|
||||
Ok(ValidationResult::Valid(outputs, persisted_validation_data))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user