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

Commit dddbbb4

Browse files
author
parity-processbot
committed
Merge remote-tracking branch 'origin/master' into na-companion-13555
2 parents 2e956d5 + 395e45f commit dddbbb4

File tree

86 files changed

+1204
-5727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1204
-5727
lines changed

Cargo.lock

Lines changed: 325 additions & 322 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ version.workspace = true
1616
authors = ["Parity Technologies <[email protected]>"]
1717
edition = "2021"
1818
repository = "https://github.com/paritytech/polkadot.git"
19-
version = "0.9.37"
19+
version = "0.9.39"
2020

2121
[dependencies]
2222
color-eyre = { version = "0.6.1", default-features = false }

node/core/approval-voting/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use polkadot_node_primitives::{
2626
approval::{
2727
BlockApprovalMeta, DelayTranche, IndirectAssignmentCert, IndirectSignedApprovalVote,
2828
},
29-
ValidationResult, APPROVAL_EXECUTION_TIMEOUT,
29+
ValidationResult,
3030
};
3131
use polkadot_node_subsystem::{
3232
errors::RecoveryError,
@@ -50,8 +50,8 @@ use polkadot_node_subsystem_util::{
5050
};
5151
use polkadot_primitives::{
5252
ApprovalVote, BlockNumber, CandidateHash, CandidateIndex, CandidateReceipt, DisputeStatement,
53-
GroupIndex, Hash, SessionIndex, SessionInfo, ValidDisputeStatementKind, ValidatorId,
54-
ValidatorIndex, ValidatorPair, ValidatorSignature,
53+
GroupIndex, Hash, PvfExecTimeoutKind, SessionIndex, SessionInfo, ValidDisputeStatementKind,
54+
ValidatorId, ValidatorIndex, ValidatorPair, ValidatorSignature,
5555
};
5656
use sc_keystore::LocalKeystore;
5757
use sp_application_crypto::Pair;
@@ -2399,7 +2399,7 @@ async fn launch_approval<Context>(
23992399
validation_code,
24002400
candidate.clone(),
24012401
available_data.pov,
2402-
APPROVAL_EXECUTION_TIMEOUT,
2402+
PvfExecTimeoutKind::Approval,
24032403
val_tx,
24042404
))
24052405
.await;

node/core/approval-voting/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2427,7 +2427,7 @@ pub async fn handle_double_assignment_import(
24272427
},
24282428
AllMessages::CandidateValidation(
24292429
CandidateValidationMessage::ValidateFromExhaustive(_, _, _, _, timeout, tx),
2430-
) if timeout == APPROVAL_EXECUTION_TIMEOUT => {
2430+
) if timeout == PvfExecTimeoutKind::Approval => {
24312431
tx.send(Ok(ValidationResult::Valid(Default::default(), Default::default())))
24322432
.unwrap();
24332433
},

node/core/backing/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use futures::{
3232
use error::{Error, FatalResult};
3333
use polkadot_node_primitives::{
3434
AvailableData, InvalidCandidate, PoV, SignedFullStatement, Statement, ValidationResult,
35-
BACKING_EXECUTION_TIMEOUT,
3635
};
3736
use polkadot_node_subsystem::{
3837
jaeger,
@@ -50,8 +49,8 @@ use polkadot_node_subsystem_util::{
5049
};
5150
use polkadot_primitives::{
5251
BackedCandidate, CandidateCommitments, CandidateHash, CandidateReceipt, CollatorId,
53-
CommittedCandidateReceipt, CoreIndex, CoreState, Hash, Id as ParaId, SigningContext,
54-
ValidatorId, ValidatorIndex, ValidatorSignature, ValidityAttestation,
52+
CommittedCandidateReceipt, CoreIndex, CoreState, Hash, Id as ParaId, PvfExecTimeoutKind,
53+
SigningContext, ValidatorId, ValidatorIndex, ValidatorSignature, ValidityAttestation,
5554
};
5655
use sp_keystore::SyncCryptoStorePtr;
5756
use statement_table::{
@@ -650,7 +649,7 @@ async fn request_candidate_validation(
650649
.send_message(CandidateValidationMessage::ValidateFromChainState(
651650
candidate_receipt,
652651
pov,
653-
BACKING_EXECUTION_TIMEOUT,
652+
PvfExecTimeoutKind::Backing,
654653
tx,
655654
))
656655
.await;

node/core/backing/src/tests.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use polkadot_node_subsystem::{
3232
use polkadot_node_subsystem_test_helpers as test_helpers;
3333
use polkadot_primitives::{
3434
CandidateDescriptor, CollatorId, GroupRotationInfo, HeadData, PersistedValidationData,
35-
ScheduledCore,
35+
PvfExecTimeoutKind, ScheduledCore,
3636
};
3737
use sp_application_crypto::AppKey;
3838
use sp_keyring::Sr25519Keyring;
@@ -307,7 +307,7 @@ fn backing_second_works() {
307307
timeout,
308308
tx,
309309
)
310-
) if pov == pov && &candidate_receipt.descriptor == candidate.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT && candidate.commitments.hash() == candidate_receipt.commitments_hash => {
310+
) if pov == pov && &candidate_receipt.descriptor == candidate.descriptor() && timeout == PvfExecTimeoutKind::Backing && candidate.commitments.hash() == candidate_receipt.commitments_hash => {
311311
tx.send(Ok(
312312
ValidationResult::Valid(CandidateCommitments {
313313
head_data: expected_head_data.clone(),
@@ -453,7 +453,7 @@ fn backing_works() {
453453
timeout,
454454
tx,
455455
)
456-
) if pov == pov && c.descriptor() == candidate_a.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT && c.commitments_hash == candidate_a_commitments_hash=> {
456+
) if pov == pov && c.descriptor() == candidate_a.descriptor() && timeout == PvfExecTimeoutKind::Backing && c.commitments_hash == candidate_a_commitments_hash=> {
457457
tx.send(Ok(
458458
ValidationResult::Valid(CandidateCommitments {
459459
head_data: expected_head_data.clone(),
@@ -625,7 +625,7 @@ fn backing_works_while_validation_ongoing() {
625625
timeout,
626626
tx,
627627
)
628-
) if pov == pov && c.descriptor() == candidate_a.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT && candidate_a_commitments_hash == c.commitments_hash => {
628+
) if pov == pov && c.descriptor() == candidate_a.descriptor() && timeout == PvfExecTimeoutKind::Backing && candidate_a_commitments_hash == c.commitments_hash => {
629629
// we never validate the candidate. our local node
630630
// shouldn't issue any statements.
631631
std::mem::forget(tx);
@@ -777,7 +777,7 @@ fn backing_misbehavior_works() {
777777
timeout,
778778
tx,
779779
)
780-
) if pov == pov && c.descriptor() == candidate_a.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT && candidate_a_commitments_hash == c.commitments_hash => {
780+
) if pov == pov && c.descriptor() == candidate_a.descriptor() && timeout == PvfExecTimeoutKind::Backing && candidate_a_commitments_hash == c.commitments_hash => {
781781
tx.send(Ok(
782782
ValidationResult::Valid(CandidateCommitments {
783783
head_data: expected_head_data.clone(),
@@ -921,7 +921,7 @@ fn backing_dont_second_invalid() {
921921
timeout,
922922
tx,
923923
)
924-
) if pov == pov && c.descriptor() == candidate_a.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT => {
924+
) if pov == pov && c.descriptor() == candidate_a.descriptor() && timeout == PvfExecTimeoutKind::Backing => {
925925
tx.send(Ok(ValidationResult::Invalid(InvalidCandidate::BadReturn))).unwrap();
926926
}
927927
);
@@ -950,7 +950,7 @@ fn backing_dont_second_invalid() {
950950
timeout,
951951
tx,
952952
)
953-
) if pov == pov && c.descriptor() == candidate_b.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT => {
953+
) if pov == pov && c.descriptor() == candidate_b.descriptor() && timeout == PvfExecTimeoutKind::Backing => {
954954
tx.send(Ok(
955955
ValidationResult::Valid(CandidateCommitments {
956956
head_data: expected_head_data.clone(),
@@ -1065,7 +1065,7 @@ fn backing_second_after_first_fails_works() {
10651065
timeout,
10661066
tx,
10671067
)
1068-
) if pov == pov && c.descriptor() == candidate.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT && c.commitments_hash == candidate.commitments.hash() => {
1068+
) if pov == pov && c.descriptor() == candidate.descriptor() && timeout == PvfExecTimeoutKind::Backing && c.commitments_hash == candidate.commitments.hash() => {
10691069
tx.send(Ok(ValidationResult::Invalid(InvalidCandidate::BadReturn))).unwrap();
10701070
}
10711071
);
@@ -1191,7 +1191,7 @@ fn backing_works_after_failed_validation() {
11911191
timeout,
11921192
tx,
11931193
)
1194-
) if pov == pov && c.descriptor() == candidate.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT && c.commitments_hash == candidate.commitments.hash() => {
1194+
) if pov == pov && c.descriptor() == candidate.descriptor() && timeout == PvfExecTimeoutKind::Backing && c.commitments_hash == candidate.commitments.hash() => {
11951195
tx.send(Err(ValidationFailed("Internal test error".into()))).unwrap();
11961196
}
11971197
);
@@ -1544,7 +1544,7 @@ fn retry_works() {
15441544
timeout,
15451545
_tx,
15461546
)
1547-
) if pov == pov && c.descriptor() == candidate.descriptor() && timeout == BACKING_EXECUTION_TIMEOUT && c.commitments_hash == candidate.commitments.hash()
1547+
) if pov == pov && c.descriptor() == candidate.descriptor() && timeout == PvfExecTimeoutKind::Backing && c.commitments_hash == candidate.commitments.hash()
15481548
);
15491549
virtual_overseer
15501550
});

node/core/candidate-validation/src/lib.rs

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#![warn(missing_docs)]
2525

2626
use polkadot_node_core_pvf::{
27-
InvalidCandidate as WasmInvalidCandidate, PrepareError, PrepareStats, PvfWithExecutorParams,
27+
InvalidCandidate as WasmInvalidCandidate, PrepareError, PrepareStats, PvfPrepData,
2828
ValidationError, ValidationHost,
2929
};
3030
use polkadot_node_primitives::{
@@ -43,7 +43,8 @@ use polkadot_node_subsystem_util::executor_params_at_relay_parent;
4343
use polkadot_parachain::primitives::{ValidationParams, ValidationResult as WasmValidationResult};
4444
use polkadot_primitives::{
4545
vstaging::ExecutorParams, CandidateCommitments, CandidateDescriptor, CandidateReceipt, Hash,
46-
OccupiedCoreAssumption, PersistedValidationData, ValidationCode, ValidationCodeHash,
46+
OccupiedCoreAssumption, PersistedValidationData, PvfExecTimeoutKind, PvfPrepTimeoutKind,
47+
ValidationCode, ValidationCodeHash,
4748
};
4849

4950
use parity_scale_codec::Encode;
@@ -68,6 +69,13 @@ const PVF_EXECUTION_RETRY_DELAY: Duration = Duration::from_secs(3);
6869
#[cfg(test)]
6970
const PVF_EXECUTION_RETRY_DELAY: Duration = Duration::from_millis(200);
7071

72+
// Default PVF timeouts. Must never be changed! Use executor environment parameters in
73+
// `session_info` pallet to adjust them. See also `PvfTimeoutKind` docs.
74+
const DEFAULT_PRECHECK_PREPARATION_TIMEOUT: Duration = Duration::from_secs(60);
75+
const DEFAULT_LENIENT_PREPARATION_TIMEOUT: Duration = Duration::from_secs(360);
76+
const DEFAULT_BACKING_EXECUTION_TIMEOUT: Duration = Duration::from_secs(2);
77+
const DEFAULT_APPROVAL_EXECUTION_TIMEOUT: Duration = Duration::from_secs(12);
78+
7179
/// Configuration for the candidate validation subsystem
7280
#[derive(Clone)]
7381
pub struct Config {
@@ -330,18 +338,20 @@ where
330338
return PreCheckOutcome::Invalid
331339
};
332340

333-
let pvf_with_params = match sp_maybe_compressed_blob::decompress(
341+
let timeout = pvf_prep_timeout(&executor_params, PvfPrepTimeoutKind::Precheck);
342+
343+
let pvf = match sp_maybe_compressed_blob::decompress(
334344
&validation_code.0,
335345
VALIDATION_CODE_BOMB_LIMIT,
336346
) {
337-
Ok(code) => PvfWithExecutorParams::from_code(code.into_owned(), executor_params),
347+
Ok(code) => PvfPrepData::from_code(code.into_owned(), executor_params, timeout),
338348
Err(e) => {
339349
gum::debug!(target: LOG_TARGET, err=?e, "precheck: cannot decompress validation code");
340350
return PreCheckOutcome::Invalid
341351
},
342352
};
343353

344-
match validation_backend.precheck_pvf(pvf_with_params).await {
354+
match validation_backend.precheck_pvf(pvf).await {
345355
Ok(_) => PreCheckOutcome::Valid,
346356
Err(prepare_err) =>
347357
if prepare_err.is_deterministic() {
@@ -465,7 +475,7 @@ async fn validate_from_chain_state<Sender>(
465475
validation_host: ValidationHost,
466476
candidate_receipt: CandidateReceipt,
467477
pov: Arc<PoV>,
468-
timeout: Duration,
478+
exec_timeout_kind: PvfExecTimeoutKind,
469479
metrics: &Metrics,
470480
) -> Result<ValidationResult, ValidationFailed>
471481
where
@@ -485,7 +495,7 @@ where
485495
validation_code,
486496
candidate_receipt.clone(),
487497
pov,
488-
timeout,
498+
exec_timeout_kind,
489499
metrics,
490500
)
491501
.await;
@@ -521,7 +531,7 @@ async fn validate_candidate_exhaustive<Sender>(
521531
validation_code: ValidationCode,
522532
candidate_receipt: CandidateReceipt,
523533
pov: Arc<PoV>,
524-
timeout: Duration,
534+
exec_timeout_kind: PvfExecTimeoutKind,
525535
metrics: &Metrics,
526536
) -> Result<ValidationResult, ValidationFailed>
527537
where
@@ -606,7 +616,7 @@ where
606616
let result = validation_backend
607617
.validate_candidate_with_retry(
608618
raw_validation_code.to_vec(),
609-
timeout,
619+
pvf_exec_timeout(&executor_params, exec_timeout_kind),
610620
params,
611621
executor_params,
612622
)
@@ -667,8 +677,8 @@ trait ValidationBackend {
667677
/// Tries executing a PVF a single time (no retries).
668678
async fn validate_candidate(
669679
&mut self,
670-
pvf_with_params: PvfWithExecutorParams,
671-
timeout: Duration,
680+
pvf: PvfPrepData,
681+
exec_timeout: Duration,
672682
encoded_params: Vec<u8>,
673683
) -> Result<WasmValidationResult, ValidationError>;
674684

@@ -677,16 +687,16 @@ trait ValidationBackend {
677687
async fn validate_candidate_with_retry(
678688
&mut self,
679689
raw_validation_code: Vec<u8>,
680-
timeout: Duration,
690+
exec_timeout: Duration,
681691
params: ValidationParams,
682692
executor_params: ExecutorParams,
683693
) -> Result<WasmValidationResult, ValidationError> {
684694
// Construct the PVF a single time, since it is an expensive operation. Cloning it is cheap.
685-
let pvf_with_params =
686-
PvfWithExecutorParams::from_code(raw_validation_code, executor_params);
695+
let prep_timeout = pvf_prep_timeout(&executor_params, PvfPrepTimeoutKind::Lenient);
696+
let pvf = PvfPrepData::from_code(raw_validation_code, executor_params, prep_timeout);
687697

688698
let mut validation_result =
689-
self.validate_candidate(pvf_with_params.clone(), timeout, params.encode()).await;
699+
self.validate_candidate(pvf.clone(), exec_timeout, params.encode()).await;
690700

691701
// If we get an AmbiguousWorkerDeath error, retry once after a brief delay, on the
692702
// assumption that the conditions that caused this error may have been transient. Note that
@@ -699,40 +709,34 @@ trait ValidationBackend {
699709

700710
gum::warn!(
701711
target: LOG_TARGET,
702-
?pvf_with_params,
712+
?pvf,
703713
"Re-trying failed candidate validation due to AmbiguousWorkerDeath."
704714
);
705715

706716
// Encode the params again when re-trying. We expect the retry case to be relatively
707717
// rare, and we want to avoid unconditionally cloning data.
708-
validation_result =
709-
self.validate_candidate(pvf_with_params, timeout, params.encode()).await;
718+
validation_result = self.validate_candidate(pvf, exec_timeout, params.encode()).await;
710719
}
711720

712721
validation_result
713722
}
714723

715-
async fn precheck_pvf(
716-
&mut self,
717-
pvf_with_params: PvfWithExecutorParams,
718-
) -> Result<PrepareStats, PrepareError>;
724+
async fn precheck_pvf(&mut self, pvf: PvfPrepData) -> Result<PrepareStats, PrepareError>;
719725
}
720726

721727
#[async_trait]
722728
impl ValidationBackend for ValidationHost {
723729
/// Tries executing a PVF a single time (no retries).
724730
async fn validate_candidate(
725731
&mut self,
726-
pvf_with_params: PvfWithExecutorParams,
727-
timeout: Duration,
732+
pvf: PvfPrepData,
733+
exec_timeout: Duration,
728734
encoded_params: Vec<u8>,
729735
) -> Result<WasmValidationResult, ValidationError> {
730736
let priority = polkadot_node_core_pvf::Priority::Normal;
731737

732738
let (tx, rx) = oneshot::channel();
733-
if let Err(err) =
734-
self.execute_pvf(pvf_with_params, timeout, encoded_params, priority, tx).await
735-
{
739+
if let Err(err) = self.execute_pvf(pvf, exec_timeout, encoded_params, priority, tx).await {
736740
return Err(ValidationError::InternalError(format!(
737741
"cannot send pvf to the validation host: {:?}",
738742
err
@@ -743,12 +747,9 @@ impl ValidationBackend for ValidationHost {
743747
.map_err(|_| ValidationError::InternalError("validation was cancelled".into()))?
744748
}
745749

746-
async fn precheck_pvf(
747-
&mut self,
748-
pvf_with_params: PvfWithExecutorParams,
749-
) -> Result<PrepareStats, PrepareError> {
750+
async fn precheck_pvf(&mut self, pvf: PvfPrepData) -> Result<PrepareStats, PrepareError> {
750751
let (tx, rx) = oneshot::channel();
751-
if let Err(err) = self.precheck_pvf(pvf_with_params, tx).await {
752+
if let Err(err) = self.precheck_pvf(pvf, tx).await {
752753
// Return an IO error if there was an error communicating with the host.
753754
return Err(PrepareError::IoErr(err))
754755
}
@@ -788,3 +789,23 @@ fn perform_basic_checks(
788789

789790
Ok(())
790791
}
792+
793+
fn pvf_prep_timeout(executor_params: &ExecutorParams, kind: PvfPrepTimeoutKind) -> Duration {
794+
if let Some(timeout) = executor_params.pvf_prep_timeout(kind) {
795+
return timeout
796+
}
797+
match kind {
798+
PvfPrepTimeoutKind::Precheck => DEFAULT_PRECHECK_PREPARATION_TIMEOUT,
799+
PvfPrepTimeoutKind::Lenient => DEFAULT_LENIENT_PREPARATION_TIMEOUT,
800+
}
801+
}
802+
803+
fn pvf_exec_timeout(executor_params: &ExecutorParams, kind: PvfExecTimeoutKind) -> Duration {
804+
if let Some(timeout) = executor_params.pvf_exec_timeout(kind) {
805+
return timeout
806+
}
807+
match kind {
808+
PvfExecTimeoutKind::Backing => DEFAULT_BACKING_EXECUTION_TIMEOUT,
809+
PvfExecTimeoutKind::Approval => DEFAULT_APPROVAL_EXECUTION_TIMEOUT,
810+
}
811+
}

0 commit comments

Comments
 (0)