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

Executor Environment parameterization #6161

Merged
merged 171 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
171 commits
Select commit Hold shift + click to select a range
6222398
Re-apply changes without Diener, rebase to the lastest master
s0me0ne-unkn0wn Sep 28, 2022
a370fbd
Cache pruning
s0me0ne-unkn0wn Oct 4, 2022
7066c67
Bit-pack InstantiationStrategy
s0me0ne-unkn0wn Oct 4, 2022
0dce199
Move ExecutorParams version inside the structure itself
s0me0ne-unkn0wn Oct 4, 2022
10c8320
Rework runtime API and executor parameters storage
s0me0ne-unkn0wn Oct 7, 2022
7f103c6
Pass executor parameters through backing subsystem
s0me0ne-unkn0wn Oct 7, 2022
143c483
Update Cargo.lock
s0me0ne-unkn0wn Oct 7, 2022
ba4eb37
Introduce `ExecutorParams` to approval voting subsys
s0me0ne-unkn0wn Oct 9, 2022
1c75f37
Introduce `ExecutorParams` to dispute coordinator
s0me0ne-unkn0wn Oct 9, 2022
003d345
`cargo fmt`
s0me0ne-unkn0wn Oct 9, 2022
631c50a
Simplify requests from backing subsys
s0me0ne-unkn0wn Oct 10, 2022
acc62b1
Fix tests
s0me0ne-unkn0wn Oct 10, 2022
8c10587
Replace manual config cloning with `.clone()`
s0me0ne-unkn0wn Oct 10, 2022
ddd1224
Move constants to module
s0me0ne-unkn0wn Oct 12, 2022
02a0e79
Parametrize executor performing PVF pre-check
s0me0ne-unkn0wn Oct 15, 2022
834c409
Fix Malus
s0me0ne-unkn0wn Oct 15, 2022
f229866
Fix test runtime
s0me0ne-unkn0wn Oct 15, 2022
49ee795
Introduce session executor params as a constant defined by session info
s0me0ne-unkn0wn Oct 15, 2022
48241ad
Use Parity SCALE codec instead of hand-crafted binary encoding
s0me0ne-unkn0wn Oct 15, 2022
a6107d9
Get rid of constants; Add docs
s0me0ne-unkn0wn Oct 16, 2022
ee2df7c
Get rid of constants
s0me0ne-unkn0wn Oct 16, 2022
719ea9b
Minor typo
s0me0ne-unkn0wn Oct 16, 2022
59325fb
Fix Malus after rebase
s0me0ne-unkn0wn Oct 16, 2022
27abf65
`cargo fmt`
s0me0ne-unkn0wn Oct 16, 2022
a3ab251
Use transparent SCALE encoding instead of explicit
s0me0ne-unkn0wn Oct 16, 2022
9ff7b52
Clean up
s0me0ne-unkn0wn Oct 18, 2022
f25f326
Get rid of relay parent to session index mapping
s0me0ne-unkn0wn Oct 26, 2022
b6348ae
Join environment type and version in a single enum element
s0me0ne-unkn0wn Oct 27, 2022
67ef6df
Use default execution parameters if running an old runtime
s0me0ne-unkn0wn Oct 27, 2022
6f2b58d
`unwrap()` -> `expect()`
s0me0ne-unkn0wn Oct 28, 2022
3908bf6
Correct API version
s0me0ne-unkn0wn Oct 28, 2022
a1c37dc
Constants are back in town
s0me0ne-unkn0wn Nov 1, 2022
5431da5
Use constants for execution environment types
s0me0ne-unkn0wn Nov 1, 2022
267ae8b
Artifact separation, first try
s0me0ne-unkn0wn Nov 3, 2022
81fa27d
Get rid of explicit version
s0me0ne-unkn0wn Nov 3, 2022
830f729
PVF execution queue worker separation
s0me0ne-unkn0wn Nov 11, 2022
3d77649
Worker handshake
s0me0ne-unkn0wn Nov 12, 2022
9f3c1c1
Global renaming
s0me0ne-unkn0wn Nov 13, 2022
37f2e5b
Minor fixes resolving discussions
s0me0ne-unkn0wn Nov 14, 2022
d52bb93
Two-stage requesting of executor params to make use of runtime API cache
s0me0ne-unkn0wn Nov 15, 2022
6249955
Proper error handling in pvf-checker
s0me0ne-unkn0wn Nov 17, 2022
d294768
Executor params storage bootstrapping
s0me0ne-unkn0wn Nov 17, 2022
b7347e9
Propagate migration to v3 network runtimes
s0me0ne-unkn0wn Nov 17, 2022
3f80564
Fix storage versioning
s0me0ne-unkn0wn Nov 18, 2022
2dc734e
Ensure `ExecutorParams` serialization determinism; Add comments
s0me0ne-unkn0wn Nov 18, 2022
241b5fc
Rename constants to make things a bit more deterministic
s0me0ne-unkn0wn Nov 18, 2022
0d3a8cc
Tidy up a structure of active PVFs
s0me0ne-unkn0wn Nov 18, 2022
929501b
Minor formatting
s0me0ne-unkn0wn Nov 18, 2022
c3475f4
Fix comment
s0me0ne-unkn0wn Nov 18, 2022
d989a99
Merge remote-tracking branch 'origin/master' into s0me0ne/executor-pa…
s0me0ne-unkn0wn Nov 18, 2022
45293b5
Add try-runtime hooks
s0me0ne-unkn0wn Nov 18, 2022
2ba2102
Add storage version write on upgrade
s0me0ne-unkn0wn Nov 19, 2022
04b1b10
Add pre- and post-upgrade assertions
s0me0ne-unkn0wn Nov 19, 2022
049b414
Require to specify environment type; Remove redundant `impl`s
s0me0ne-unkn0wn Nov 21, 2022
22d7875
Add `ExecutorParamHash` creation from `H256`
s0me0ne-unkn0wn Nov 25, 2022
0d06cd3
Fix candidate validation subsys tests
s0me0ne-unkn0wn Nov 25, 2022
a85038d
Return splittable error from executor params request fn
s0me0ne-unkn0wn Nov 25, 2022
d0cc192
Revert "Return splittable error from executor params request fn"
s0me0ne-unkn0wn Nov 25, 2022
1f3d9ac
Decompose approval voting metrics
s0me0ne-unkn0wn Nov 25, 2022
e924ebf
Use more relevant errors
s0me0ne-unkn0wn Nov 25, 2022
48a6616
Minor formatting fix
s0me0ne-unkn0wn Nov 25, 2022
60676aa
Assert a valid environment type instead of checking
s0me0ne-unkn0wn Nov 25, 2022
f25326b
Fix `try-runtime` hooks
s0me0ne-unkn0wn Nov 29, 2022
aa703a6
Merge remote-tracking branch 'origin/master' into s0me0ne/executor-pa…
s0me0ne-unkn0wn Nov 29, 2022
9dc79ec
After-merge fixes
s0me0ne-unkn0wn Nov 29, 2022
16f77e7
Add migration logs
s0me0ne-unkn0wn Nov 30, 2022
f1ec476
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Nov 30, 2022
a51e57e
Remove dead code
s0me0ne-unkn0wn Nov 30, 2022
af45aea
Fix tests
s0me0ne-unkn0wn Nov 30, 2022
76170d8
Fix tests
s0me0ne-unkn0wn Nov 30, 2022
5ae6164
Back to the strongly typed implementation
s0me0ne-unkn0wn Dec 1, 2022
d1aac61
Promote strong types to executor interface
s0me0ne-unkn0wn Dec 1, 2022
2439ae6
Remove stale comment
s0me0ne-unkn0wn Dec 1, 2022
1988355
Move executor params to `SessionInfo`: primitives and runtime
s0me0ne-unkn0wn Dec 4, 2022
a2dc782
Move executor params to `SessionInfo`: node
s0me0ne-unkn0wn Dec 4, 2022
ce042c8
Try to bump primitives and API version
s0me0ne-unkn0wn Dec 11, 2022
674038d
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Dec 11, 2022
52d7049
Get rid of `MallocSizeOf`
s0me0ne-unkn0wn Dec 12, 2022
84d53a1
Bump target API version to v4
s0me0ne-unkn0wn Dec 12, 2022
5c26c5e
Make use of session index already in place
s0me0ne-unkn0wn Dec 13, 2022
a89dff9
Merge branch 's0me0ne/executor-params-v3' into s0me0ne/executor-params
s0me0ne-unkn0wn Dec 13, 2022
03c4886
Back to v3
s0me0ne-unkn0wn Dec 15, 2022
c161ed6
Fix all the tests
s0me0ne-unkn0wn Dec 15, 2022
af35b7b
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Dec 15, 2022
cdd62e7
Add migrations to all the runtimes
s0me0ne-unkn0wn Dec 16, 2022
a51f955
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Dec 19, 2022
d3ef27b
Make use of existing `SessionInfo` in approval voting subsys
s0me0ne-unkn0wn Dec 21, 2022
3431c20
Rename `TARGET` -> `LOG_TARGET`
s0me0ne-unkn0wn Dec 21, 2022
96b921b
Bump all the primitives to v3
s0me0ne-unkn0wn Dec 21, 2022
883208a
Fix Rococo ParachainHost API version
s0me0ne-unkn0wn Dec 21, 2022
1229596
Use `RollingSessionWindow` to acquire `ExecutorParams` in disputes
s0me0ne-unkn0wn Dec 23, 2022
6d1e1b9
Fix nits from discussions; add comments
s0me0ne-unkn0wn Dec 24, 2022
32e6f1f
Re-evaluate queue logic
s0me0ne-unkn0wn Dec 25, 2022
39aae8f
Rework job assignment in execution queue
s0me0ne-unkn0wn Dec 25, 2022
b6195e9
Add documentation
s0me0ne-unkn0wn Dec 27, 2022
bb369ed
Use `RuntimeInfo` to obtain `SessionInfo` (with blackjack and caching)
s0me0ne-unkn0wn Dec 27, 2022
3be2229
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Dec 28, 2022
cc97fb1
Couple `Pvf` with `ExecutorParams` wherever possible
s0me0ne-unkn0wn Dec 30, 2022
8a7d9d6
Put members of `PvfWithExecutorParams` under `Arc` for cheap cloning
s0me0ne-unkn0wn Jan 2, 2023
ca08d65
Fix comment
s0me0ne-unkn0wn Jan 2, 2023
877a0e4
Fix CI tests
s0me0ne-unkn0wn Jan 2, 2023
5e5d9c0
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 2, 2023
996538f
Fix clippy warnings
s0me0ne-unkn0wn Jan 2, 2023
029b82b
Address nits from discussions
s0me0ne-unkn0wn Jan 3, 2023
74ccff8
Add a placeholder for raw data
s0me0ne-unkn0wn Jan 3, 2023
ad61bd2
Fix non exhaustive match
s0me0ne-unkn0wn Jan 4, 2023
abd0fc1
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 4, 2023
924fd97
Remove redundant reexports and fix imports
s0me0ne-unkn0wn Jan 4, 2023
553be9d
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 4, 2023
0dbc3fb
Keep only necessary semantic features, as discussed
s0me0ne-unkn0wn Jan 5, 2023
eb43480
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 5, 2023
3dee590
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 5, 2023
535f494
Rework `RuntimeInfo` to support mock implementation for tests
s0me0ne-unkn0wn Jan 6, 2023
3bdfc68
Remove unneeded bound
s0me0ne-unkn0wn Jan 6, 2023
28e3614
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 7, 2023
1ee2697
`cargo fmt`
s0me0ne-unkn0wn Jan 7, 2023
17a84f2
Revert "Remove unneeded bound"
s0me0ne-unkn0wn Jan 9, 2023
3728a41
Merge branch 's0me0ne/executor-params-runtime-info' into s0me0ne/exec…
s0me0ne-unkn0wn Jan 9, 2023
31c3fa9
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 9, 2023
7527152
Fix PVF host tests
s0me0ne-unkn0wn Jan 10, 2023
b099dda
Fix PVF checker tests
s0me0ne-unkn0wn Jan 10, 2023
a594a19
Fix overseer declarations
s0me0ne-unkn0wn Jan 10, 2023
a8834c1
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 10, 2023
9b03239
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 11, 2023
f965783
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 12, 2023
7496dca
Simplify tests
s0me0ne-unkn0wn Jan 13, 2023
056c055
`MAX_KEEP_WAITING` timeout based on `BACKGING_EXECUTION_TIMEOUT`
s0me0ne-unkn0wn Jan 15, 2023
a8ab836
Add a unit test for varying executor parameters
s0me0ne-unkn0wn Jan 15, 2023
c9b7dde
Minor fixes from discussions
s0me0ne-unkn0wn Jan 16, 2023
1e12da2
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 16, 2023
8b6f478
Add prechecking max. memory parameter (see paritytech/srlabs_findings…
s0me0ne-unkn0wn Jan 16, 2023
e4b5909
Fix and improve a test
s0me0ne-unkn0wn Jan 16, 2023
e39b991
Remove `ExecutionEnvironment` and `RawData`
s0me0ne-unkn0wn Jan 17, 2023
f092002
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 17, 2023
d4e8db8
New primitives versioning in parachain host API
s0me0ne-unkn0wn Jan 17, 2023
7776b73
`disputes()` implementation for Kusama and Polkadot
s0me0ne-unkn0wn Jan 18, 2023
29bec0e
Move `ExecutorParams` from `vstaging` to stable primitives
s0me0ne-unkn0wn Jan 18, 2023
7930340
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 18, 2023
c258bd4
Move disputes from `vstaging` to stable implementation
s0me0ne-unkn0wn Jan 18, 2023
95d790c
Fix `try-runtime`
s0me0ne-unkn0wn Jan 18, 2023
c79a404
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 19, 2023
6aa31c4
Fixes after merge
s0me0ne-unkn0wn Jan 19, 2023
ba19715
Move `ExecutorParams` to the bottom of `SessionInfo`
s0me0ne-unkn0wn Jan 19, 2023
630edbd
Revert "Move executor params to `SessionInfo`: primitives and runtime"
s0me0ne-unkn0wn Jan 19, 2023
c559bd9
Always use fresh activated live hash in pvf precheck
s0me0ne-unkn0wn Jan 19, 2023
f157395
Fixing tests (broken commit)
s0me0ne-unkn0wn Jan 20, 2023
f155042
Fix candidate validation tests
s0me0ne-unkn0wn Jan 20, 2023
7f10d92
Fix PVF host test
s0me0ne-unkn0wn Jan 20, 2023
8e7d31d
Minor fixes
s0me0ne-unkn0wn Jan 20, 2023
7d2305b
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 30, 2023
5a04b6a
Address discussions
s0me0ne-unkn0wn Jan 30, 2023
8877933
Restore migration
s0me0ne-unkn0wn Jan 30, 2023
4315ff7
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Jan 30, 2023
a182847
Fix `use` to only include what is needed instead of `*`
s0me0ne-unkn0wn Jan 31, 2023
7e16619
Add comment to never touch `DEFAULT_CONFIG`
s0me0ne-unkn0wn Jan 31, 2023
106ddbf
Update migration to set default `ExecutorParams` for `dispute_period`
s0me0ne-unkn0wn Jan 31, 2023
3879459
Use `earliest_stored_session` instead of calculations
s0me0ne-unkn0wn Feb 1, 2023
d5e064a
Nit
s0me0ne-unkn0wn Feb 1, 2023
7ba4a98
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Feb 7, 2023
d67c3cf
Add logs
s0me0ne-unkn0wn Feb 7, 2023
38687d2
Treat any runtime error as `NotSupported` again
s0me0ne-unkn0wn Feb 8, 2023
277efe5
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Feb 8, 2023
b58ac44
Always return default executor params if not available
s0me0ne-unkn0wn Feb 10, 2023
c32c93c
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Feb 10, 2023
5c1e9e4
Revert "Always return default executor params if not available"
s0me0ne-unkn0wn Feb 10, 2023
6f2c0c9
Add paritytech/substrate#9997 workaround
s0me0ne-unkn0wn Feb 13, 2023
17a66e1
`cargo fmt`
s0me0ne-unkn0wn Feb 13, 2023
83e8fe4
Remove migration (again!)
s0me0ne-unkn0wn Feb 13, 2023
96f7a45
Bump executor params to API v4 (backport from #6698)
s0me0ne-unkn0wn Feb 14, 2023
69d4ae6
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Feb 14, 2023
5e0dbfd
Merge branch 'master' into s0me0ne/executor-params
s0me0ne-unkn0wn Feb 15, 2023
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
3 changes: 3 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion erasure-coding/benches/scaling_with_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use polkadot_primitives::v2::Hash;
use polkadot_primitives::Hash;
use std::time::Duration;

fn chunks(n_validators: usize, pov: &Vec<u8>) -> Vec<Vec<u8>> {
Expand Down
2 changes: 1 addition & 1 deletion node/core/candidate-validation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ polkadot-primitives = { path = "../../../primitives" }
polkadot-parachain = { path = "../../../parachain" }
polkadot-node-primitives = { path = "../../primitives" }
polkadot-node-subsystem = { path = "../../subsystem" }
polkadot-node-subsystem-util = { path = "../../subsystem-util" }
polkadot-node-metrics = { path = "../../metrics" }

[target.'cfg(not(any(target_os = "android", target_os = "unknown")))'.dependencies]
Expand All @@ -27,6 +28,5 @@ sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master
futures = { version = "0.3.21", features = ["thread-pool"] }
assert_matches = "1.4.0"
polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" }
polkadot-node-subsystem-util = { path = "../../subsystem-util" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../../primitives/test-helpers" }
105 changes: 85 additions & 20 deletions node/core/candidate-validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#![warn(missing_docs)]

use polkadot_node_core_pvf::{
InvalidCandidate as WasmInvalidCandidate, PrepareError, PrepareStats, Pvf, ValidationError,
ValidationHost,
InvalidCandidate as WasmInvalidCandidate, PrepareError, PrepareStats, Pvf,
PvfWithExecutorParams, ValidationError, ValidationHost,
};
use polkadot_node_primitives::{
BlockData, InvalidCandidate, PoV, ValidationResult, POV_BOMB_LIMIT, VALIDATION_CODE_BOMB_LIMIT,
Expand All @@ -39,10 +39,11 @@ use polkadot_node_subsystem::{
overseer, FromOrchestra, OverseerSignal, SpawnedSubsystem, SubsystemError, SubsystemResult,
SubsystemSender,
};
use polkadot_node_subsystem_util::executor_params_at_relay_parent;
use polkadot_parachain::primitives::{ValidationParams, ValidationResult as WasmValidationResult};
use polkadot_primitives::{
CandidateCommitments, CandidateDescriptor, CandidateReceipt, Hash, OccupiedCoreAssumption,
PersistedValidationData, ValidationCode, ValidationCodeHash,
vstaging::ExecutorParams, CandidateCommitments, CandidateDescriptor, CandidateReceipt, Hash,
OccupiedCoreAssumption, PersistedValidationData, ValidationCode, ValidationCodeHash,
};

use parity_scale_codec::Encode;
Expand Down Expand Up @@ -175,12 +176,14 @@ async fn run<Context>(
response_sender,
) => {
let bg = {
let mut sender = ctx.sender().clone();
let metrics = metrics.clone();
let validation_host = validation_host.clone();

async move {
let _timer = metrics.time_validate_from_exhaustive();
let res = validate_candidate_exhaustive(
&mut sender,
validation_host,
persisted_validation_data,
validation_code,
Expand Down Expand Up @@ -307,18 +310,38 @@ where
},
};

let validation_code = match sp_maybe_compressed_blob::decompress(
let executor_params =
if let Ok(executor_params) = executor_params_at_relay_parent(relay_parent, sender).await {
gum::debug!(
target: LOG_TARGET,
?relay_parent,
?validation_code_hash,
"precheck: acquired executor params for the session: {:?}",
executor_params,
);
executor_params
} else {
gum::warn!(
target: LOG_TARGET,
?relay_parent,
?validation_code_hash,
"precheck: failed to acquire executor params for the session, thus voting against.",
);
return PreCheckOutcome::Invalid
ordian marked this conversation as resolved.
Show resolved Hide resolved
};

let pvf_with_params = match sp_maybe_compressed_blob::decompress(
&validation_code.0,
VALIDATION_CODE_BOMB_LIMIT,
) {
Ok(code) => Pvf::from_code(code.into_owned()),
Ok(code) => PvfWithExecutorParams::new(Pvf::from_code(code.into_owned()), executor_params),
Err(e) => {
gum::debug!(target: LOG_TARGET, err=?e, "precheck: cannot decompress validation code");
return PreCheckOutcome::Invalid
},
};

match validation_backend.precheck_pvf(validation_code).await {
match validation_backend.precheck_pvf(pvf_with_params).await {
Ok(_) => PreCheckOutcome::Valid,
Err(prepare_err) =>
if prepare_err.is_deterministic() {
Expand Down Expand Up @@ -456,6 +479,7 @@ where
};

let validation_result = validate_candidate_exhaustive(
sender,
validation_host,
validation_data,
validation_code,
Expand Down Expand Up @@ -490,15 +514,19 @@ where
validation_result
}

async fn validate_candidate_exhaustive(
async fn validate_candidate_exhaustive<Sender>(
sender: &mut Sender,
mut validation_backend: impl ValidationBackend + Send,
persisted_validation_data: PersistedValidationData,
validation_code: ValidationCode,
candidate_receipt: CandidateReceipt,
pov: Arc<PoV>,
timeout: Duration,
metrics: &Metrics,
) -> Result<ValidationResult, ValidationFailed> {
) -> Result<ValidationResult, ValidationFailed>
where
Sender: SubsystemSender<RuntimeApiMessage>,
{
let _timer = metrics.time_validate_candidate_exhaustive();

let validation_code_hash = validation_code.hash();
Expand Down Expand Up @@ -554,8 +582,34 @@ async fn validate_candidate_exhaustive(
relay_parent_storage_root: persisted_validation_data.relay_parent_storage_root,
};

let executor_params = if let Ok(executor_params) =
executor_params_at_relay_parent(candidate_receipt.descriptor.relay_parent, sender).await
{
gum::debug!(
target: LOG_TARGET,
?validation_code_hash,
?para_id,
"Acquired executor params for the session: {:?}",
executor_params,
);
executor_params
} else {
gum::warn!(
target: LOG_TARGET,
?validation_code_hash,
?para_id,
"Failed to acquire executor params for the session",
);
return Ok(ValidationResult::Invalid(InvalidCandidate::BadParent))
};

let result = validation_backend
.validate_candidate_with_retry(raw_validation_code.to_vec(), timeout, params)
.validate_candidate_with_retry(
raw_validation_code.to_vec(),
timeout,
params,
executor_params,
)
.await;

if let Err(ref error) = result {
Expand Down Expand Up @@ -613,7 +667,7 @@ trait ValidationBackend {
/// Tries executing a PVF a single time (no retries).
async fn validate_candidate(
&mut self,
pvf: Pvf,
pvf_with_params: PvfWithExecutorParams,
timeout: Duration,
encoded_params: Vec<u8>,
) -> Result<WasmValidationResult, ValidationError>;
Expand All @@ -625,12 +679,14 @@ trait ValidationBackend {
raw_validation_code: Vec<u8>,
timeout: Duration,
params: ValidationParams,
executor_params: ExecutorParams,
) -> Result<WasmValidationResult, ValidationError> {
// Construct the PVF a single time, since it is an expensive operation. Cloning it is cheap.
s0me0ne-unkn0wn marked this conversation as resolved.
Show resolved Hide resolved
let pvf = Pvf::from_code(raw_validation_code);
let pvf_with_params =
PvfWithExecutorParams::new(Pvf::from_code(raw_validation_code), executor_params);

let mut validation_result =
self.validate_candidate(pvf.clone(), timeout, params.encode()).await;
self.validate_candidate(pvf_with_params.clone(), timeout, params.encode()).await;

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

gum::warn!(
target: LOG_TARGET,
?pvf,
?pvf_with_params,
"Re-trying failed candidate validation due to AmbiguousWorkerDeath."
);

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

validation_result
}

async fn precheck_pvf(&mut self, pvf: Pvf) -> Result<PrepareStats, PrepareError>;
async fn precheck_pvf(
&mut self,
pvf_with_params: PvfWithExecutorParams,
) -> Result<PrepareStats, PrepareError>;
}

#[async_trait]
impl ValidationBackend for ValidationHost {
/// Tries executing a PVF a single time (no retries).
async fn validate_candidate(
&mut self,
pvf: Pvf,
pvf_with_params: PvfWithExecutorParams,
timeout: Duration,
encoded_params: Vec<u8>,
) -> Result<WasmValidationResult, ValidationError> {
let priority = polkadot_node_core_pvf::Priority::Normal;

let (tx, rx) = oneshot::channel();
if let Err(err) = self.execute_pvf(pvf, timeout, encoded_params, priority, tx).await {
if let Err(err) =
self.execute_pvf(pvf_with_params, timeout, encoded_params, priority, tx).await
{
return Err(ValidationError::InternalError(format!(
"cannot send pvf to the validation host: {:?}",
err
Expand All @@ -681,9 +743,12 @@ impl ValidationBackend for ValidationHost {
.map_err(|_| ValidationError::InternalError("validation was cancelled".into()))?
}

async fn precheck_pvf(&mut self, pvf: Pvf) -> Result<PrepareStats, PrepareError> {
async fn precheck_pvf(
&mut self,
pvf_with_params: PvfWithExecutorParams,
) -> Result<PrepareStats, PrepareError> {
let (tx, rx) = oneshot::channel();
if let Err(err) = self.precheck_pvf(pvf, tx).await {
if let Err(err) = self.precheck_pvf(pvf_with_params, tx).await {
// Return an IO error if there was an error communicating with the host.
return Err(PrepareError::IoErr(err))
}
Expand Down
Loading