This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Retry failed PVF execution (AmbiguousWorkerDeath) #6235
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2e39830
Fix a couple of typos
mrcnski 2e91ff3
Retry failed PVF execution
mrcnski e2a15ee
Address a couple of nits
mrcnski e477572
Write tests; refactor (add `validate_candidate_with_retry`)
mrcnski 705adc7
Update node/core/candidate-validation/src/lib.rs
eskimor 6e7f57a
Merge branch 'master' into m-cat/pvf-execute-retry
mrcnski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,12 @@ mod tests; | |
|
|
||
| const LOG_TARGET: &'static str = "parachain::candidate-validation"; | ||
|
|
||
| /// The amount of time to wait before retrying after an AmbiguousWorkerDeath validation error. | ||
| #[cfg(not(test))] | ||
| const PVF_EXECUTION_RETRY_DELAY: Duration = Duration::from_secs(1); | ||
eskimor marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #[cfg(test)] | ||
| const PVF_EXECUTION_RETRY_DELAY: Duration = Duration::from_millis(200); | ||
|
|
||
| /// Configuration for the candidate validation subsystem | ||
| #[derive(Clone)] | ||
| pub struct Config { | ||
|
|
@@ -490,7 +496,7 @@ where | |
| } | ||
|
|
||
| async fn validate_candidate_exhaustive( | ||
| mut validation_backend: impl ValidationBackend, | ||
| mut validation_backend: impl ValidationBackend + Send, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suddenly needed this due to the new default implementation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure it's helpful here, but there's a |
||
| persisted_validation_data: PersistedValidationData, | ||
| validation_code: ValidationCode, | ||
| candidate_receipt: CandidateReceipt, | ||
|
|
@@ -551,7 +557,7 @@ async fn validate_candidate_exhaustive( | |
| }; | ||
|
|
||
| let result = validation_backend | ||
| .validate_candidate(raw_validation_code.to_vec(), timeout, params) | ||
| .validate_candidate_with_retry(raw_validation_code.to_vec(), timeout, params) | ||
| .await; | ||
|
|
||
| if let Err(ref error) = result { | ||
|
|
@@ -604,45 +610,63 @@ async fn validate_candidate_exhaustive( | |
| #[async_trait] | ||
| trait ValidationBackend { | ||
| async fn validate_candidate( | ||
| &mut self, | ||
| pvf: Pvf, | ||
| timeout: Duration, | ||
| encoded_params: Vec<u8>, | ||
| ) -> Result<WasmValidationResult, ValidationError>; | ||
|
|
||
| async fn validate_candidate_with_retry( | ||
| &mut self, | ||
| raw_validation_code: Vec<u8>, | ||
| timeout: Duration, | ||
| params: ValidationParams, | ||
| ) -> Result<WasmValidationResult, ValidationError>; | ||
| ) -> Result<WasmValidationResult, ValidationError> { | ||
| // Construct the PVF a single time, since it is an expensive operation. Cloning it is cheap. | ||
| let pvf = Pvf::from_code(raw_validation_code); | ||
|
|
||
| let validation_result = | ||
| self.validate_candidate(pvf.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. | ||
| if let Err(ValidationError::InvalidCandidate(WasmInvalidCandidate::AmbiguousWorkerDeath)) = | ||
| validation_result | ||
| { | ||
| // Wait a brief delay before retrying. | ||
| futures_timer::Delay::new(PVF_EXECUTION_RETRY_DELAY).await; | ||
| // Encode the params again when re-trying. We expect the retry case to be relatively | ||
| // rare, and we want to avoid unconditionally cloning data. | ||
| self.validate_candidate(pvf, timeout, params.encode()).await | ||
| } else { | ||
| validation_result | ||
| } | ||
| } | ||
|
|
||
| async fn precheck_pvf(&mut self, pvf: Pvf) -> Result<(), PrepareError>; | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl ValidationBackend for ValidationHost { | ||
| /// Tries executing a PVF a single time (no retries). | ||
| async fn validate_candidate( | ||
| &mut self, | ||
| raw_validation_code: Vec<u8>, | ||
| pvf: Pvf, | ||
| timeout: Duration, | ||
| params: ValidationParams, | ||
| 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::from_code(raw_validation_code), | ||
| timeout, | ||
| params.encode(), | ||
| polkadot_node_core_pvf::Priority::Normal, | ||
| tx, | ||
| ) | ||
| .await | ||
| { | ||
| if let Err(err) = self.execute_pvf(pvf, timeout, encoded_params, priority, tx).await { | ||
| return Err(ValidationError::InternalError(format!( | ||
| "cannot send pvf to the validation host: {:?}", | ||
| err | ||
| ))) | ||
| } | ||
|
|
||
| let validation_result = rx | ||
| .await | ||
| .map_err(|_| ValidationError::InternalError("validation was cancelled".into()))?; | ||
|
|
||
| validation_result | ||
| rx.await | ||
| .map_err(|_| ValidationError::InternalError("validation was cancelled".into()))? | ||
| } | ||
|
|
||
| async fn precheck_pvf(&mut self, pvf: Pvf) -> Result<(), PrepareError> { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.