mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 12:11:02 +00:00
Use higher priority for PVF preparation in dispute/approval context (#4172)
Related to https://github.com/paritytech/polkadot-sdk/issues/4126 discussion Currently all preparations have same priority and this is not ideal in all cases. This change should improve the finality time in the context of on-demand parachains and when `ExecutorParams` are updated on-chain and a rebuild of all artifacts is required. The desired effect is to speed up approval and dispute PVF executions which require preparation and delay backing executions which require preparation. --------- Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
This commit is contained in:
@@ -657,7 +657,14 @@ async fn validate_candidate_exhaustive(
|
|||||||
PrepareJobKind::Compilation,
|
PrepareJobKind::Compilation,
|
||||||
);
|
);
|
||||||
|
|
||||||
validation_backend.validate_candidate(pvf, exec_timeout, params.encode()).await
|
validation_backend
|
||||||
|
.validate_candidate(
|
||||||
|
pvf,
|
||||||
|
exec_timeout,
|
||||||
|
params.encode(),
|
||||||
|
polkadot_node_core_pvf::Priority::Normal,
|
||||||
|
)
|
||||||
|
.await
|
||||||
},
|
},
|
||||||
PvfExecKind::Approval =>
|
PvfExecKind::Approval =>
|
||||||
validation_backend
|
validation_backend
|
||||||
@@ -667,6 +674,7 @@ async fn validate_candidate_exhaustive(
|
|||||||
params,
|
params,
|
||||||
executor_params,
|
executor_params,
|
||||||
PVF_APPROVAL_EXECUTION_RETRY_DELAY,
|
PVF_APPROVAL_EXECUTION_RETRY_DELAY,
|
||||||
|
polkadot_node_core_pvf::Priority::Critical,
|
||||||
)
|
)
|
||||||
.await,
|
.await,
|
||||||
};
|
};
|
||||||
@@ -749,10 +757,15 @@ trait ValidationBackend {
|
|||||||
pvf: PvfPrepData,
|
pvf: PvfPrepData,
|
||||||
exec_timeout: Duration,
|
exec_timeout: Duration,
|
||||||
encoded_params: Vec<u8>,
|
encoded_params: Vec<u8>,
|
||||||
|
// The priority for the preparation job.
|
||||||
|
prepare_priority: polkadot_node_core_pvf::Priority,
|
||||||
) -> Result<WasmValidationResult, ValidationError>;
|
) -> Result<WasmValidationResult, ValidationError>;
|
||||||
|
|
||||||
/// Tries executing a PVF for the approval subsystem. Will retry once if an error is encountered
|
/// Tries executing a PVF. Will retry once if an error is encountered that may have
|
||||||
/// that may have been transient.
|
/// been transient.
|
||||||
|
///
|
||||||
|
/// The `prepare_priority` is relevant in the context of the caller. Currently we expect
|
||||||
|
/// that `approval` context has priority over `backing` context.
|
||||||
///
|
///
|
||||||
/// NOTE: Should retry only on errors that are a result of execution itself, and not of
|
/// NOTE: Should retry only on errors that are a result of execution itself, and not of
|
||||||
/// preparation.
|
/// preparation.
|
||||||
@@ -763,6 +776,8 @@ trait ValidationBackend {
|
|||||||
params: ValidationParams,
|
params: ValidationParams,
|
||||||
executor_params: ExecutorParams,
|
executor_params: ExecutorParams,
|
||||||
retry_delay: Duration,
|
retry_delay: Duration,
|
||||||
|
// The priority for the preparation job.
|
||||||
|
prepare_priority: polkadot_node_core_pvf::Priority,
|
||||||
) -> Result<WasmValidationResult, ValidationError> {
|
) -> Result<WasmValidationResult, ValidationError> {
|
||||||
let prep_timeout = pvf_prep_timeout(&executor_params, PvfPrepKind::Prepare);
|
let prep_timeout = pvf_prep_timeout(&executor_params, PvfPrepKind::Prepare);
|
||||||
// Construct the PVF a single time, since it is an expensive operation. Cloning it is cheap.
|
// Construct the PVF a single time, since it is an expensive operation. Cloning it is cheap.
|
||||||
@@ -776,8 +791,10 @@ trait ValidationBackend {
|
|||||||
// long.
|
// long.
|
||||||
let total_time_start = Instant::now();
|
let total_time_start = Instant::now();
|
||||||
|
|
||||||
let mut validation_result =
|
// Use `Priority::Critical` as finality trumps parachain liveliness.
|
||||||
self.validate_candidate(pvf.clone(), exec_timeout, params.encode()).await;
|
let mut validation_result = self
|
||||||
|
.validate_candidate(pvf.clone(), exec_timeout, params.encode(), prepare_priority)
|
||||||
|
.await;
|
||||||
if validation_result.is_ok() {
|
if validation_result.is_ok() {
|
||||||
return validation_result
|
return validation_result
|
||||||
}
|
}
|
||||||
@@ -851,8 +868,9 @@ trait ValidationBackend {
|
|||||||
|
|
||||||
// Encode the params again when re-trying. We expect the retry case to be relatively
|
// Encode the params again when re-trying. We expect the retry case to be relatively
|
||||||
// rare, and we want to avoid unconditionally cloning data.
|
// rare, and we want to avoid unconditionally cloning data.
|
||||||
validation_result =
|
validation_result = self
|
||||||
self.validate_candidate(pvf.clone(), new_timeout, params.encode()).await;
|
.validate_candidate(pvf.clone(), new_timeout, params.encode(), prepare_priority)
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -870,11 +888,13 @@ impl ValidationBackend for ValidationHost {
|
|||||||
pvf: PvfPrepData,
|
pvf: PvfPrepData,
|
||||||
exec_timeout: Duration,
|
exec_timeout: Duration,
|
||||||
encoded_params: Vec<u8>,
|
encoded_params: Vec<u8>,
|
||||||
|
// The priority for the preparation job.
|
||||||
|
prepare_priority: polkadot_node_core_pvf::Priority,
|
||||||
) -> Result<WasmValidationResult, ValidationError> {
|
) -> Result<WasmValidationResult, ValidationError> {
|
||||||
let priority = polkadot_node_core_pvf::Priority::Normal;
|
|
||||||
|
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
if let Err(err) = self.execute_pvf(pvf, exec_timeout, encoded_params, priority, tx).await {
|
if let Err(err) =
|
||||||
|
self.execute_pvf(pvf, exec_timeout, encoded_params, prepare_priority, tx).await
|
||||||
|
{
|
||||||
return Err(InternalValidationError::HostCommunication(format!(
|
return Err(InternalValidationError::HostCommunication(format!(
|
||||||
"cannot send pvf to the validation host, it might have shut down: {:?}",
|
"cannot send pvf to the validation host, it might have shut down: {:?}",
|
||||||
err
|
err
|
||||||
|
|||||||
@@ -368,6 +368,7 @@ impl ValidationBackend for MockValidateCandidateBackend {
|
|||||||
_pvf: PvfPrepData,
|
_pvf: PvfPrepData,
|
||||||
_timeout: Duration,
|
_timeout: Duration,
|
||||||
_encoded_params: Vec<u8>,
|
_encoded_params: Vec<u8>,
|
||||||
|
_prepare_priority: polkadot_node_core_pvf::Priority,
|
||||||
) -> Result<WasmValidationResult, ValidationError> {
|
) -> Result<WasmValidationResult, ValidationError> {
|
||||||
// This is expected to panic if called more times than expected, indicating an error in the
|
// This is expected to panic if called more times than expected, indicating an error in the
|
||||||
// test.
|
// test.
|
||||||
@@ -1044,6 +1045,7 @@ impl ValidationBackend for MockPreCheckBackend {
|
|||||||
_pvf: PvfPrepData,
|
_pvf: PvfPrepData,
|
||||||
_timeout: Duration,
|
_timeout: Duration,
|
||||||
_encoded_params: Vec<u8>,
|
_encoded_params: Vec<u8>,
|
||||||
|
_prepare_priority: polkadot_node_core_pvf::Priority,
|
||||||
) -> Result<WasmValidationResult, ValidationError> {
|
) -> Result<WasmValidationResult, ValidationError> {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ impl Config {
|
|||||||
prepare_worker_program_path,
|
prepare_worker_program_path,
|
||||||
prepare_worker_spawn_timeout: Duration::from_secs(3),
|
prepare_worker_spawn_timeout: Duration::from_secs(3),
|
||||||
prepare_workers_soft_max_num: 1,
|
prepare_workers_soft_max_num: 1,
|
||||||
prepare_workers_hard_max_num: 1,
|
prepare_workers_hard_max_num: 2,
|
||||||
|
|
||||||
execute_worker_program_path,
|
execute_worker_program_path,
|
||||||
execute_worker_spawn_timeout: Duration::from_secs(3),
|
execute_worker_spawn_timeout: Duration::from_secs(3),
|
||||||
|
|||||||
@@ -14,17 +14,18 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/// A priority assigned to execution of a PVF.
|
/// A priority assigned to preparation of a PVF.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum Priority {
|
pub enum Priority {
|
||||||
/// Normal priority for things that do not require immediate response, but still need to be
|
/// Normal priority for things that do not require immediate response, but still need to be
|
||||||
/// done pretty quick.
|
/// done pretty quick.
|
||||||
///
|
///
|
||||||
/// Approvals and disputes fall into this category.
|
/// Backing falls into this category.
|
||||||
Normal,
|
Normal,
|
||||||
/// This priority is used for requests that are required to be processed as soon as possible.
|
/// This priority is used for requests that are required to be processed as soon as possible.
|
||||||
///
|
///
|
||||||
/// For example, backing is on a critical path and requires execution as soon as possible.
|
/// Disputes and approvals are on a critical path and require execution as soon as
|
||||||
|
/// possible to not delay finality.
|
||||||
Critical,
|
Critical,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user