This repository has been 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
Implement PVF pre-checking using pending ExecutorParams #7139
Open
s0me0ne-unkn0wn
wants to merge
5
commits into
master
Choose a base branch
from
s0me0ne/precheck-with-pending-config
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9ea4f3c
Implement PVF pre-checking using pending ExecutorParams
s0me0ne-unkn0wn 672ea6c
Add documentations
s0me0ne-unkn0wn 51cf479
Add backward compatibility layer
s0me0ne-unkn0wn 2752d6d
Fix tests
s0me0ne-unkn0wn d17b555
Merge remote-tracking branch 'origin/master' into s0me0ne/precheck-wi…
s0me0ne-unkn0wn 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
This file contains 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 |
---|---|---|
|
@@ -238,7 +238,11 @@ async fn run<Context>( | |
} | ||
} | ||
|
||
struct RuntimeRequestFailed; | ||
enum RuntimeRequestFailed { | ||
Dropped, | ||
InternalError, | ||
NotSupported, | ||
} | ||
|
||
async fn runtime_api_request<T, Sender>( | ||
sender: &mut Sender, | ||
|
@@ -258,7 +262,7 @@ where | |
.map_err(|_| { | ||
gum::debug!(target: LOG_TARGET, ?relay_parent, "Runtime API request dropped"); | ||
|
||
RuntimeRequestFailed | ||
RuntimeRequestFailed::Dropped | ||
}) | ||
.and_then(|res| { | ||
res.map_err(|e| { | ||
|
@@ -269,7 +273,7 @@ where | |
"Runtime API request internal error" | ||
); | ||
|
||
RuntimeRequestFailed | ||
RuntimeRequestFailed::InternalError | ||
}) | ||
}) | ||
} | ||
|
@@ -292,6 +296,43 @@ where | |
.await | ||
} | ||
|
||
async fn request_pending_executor_params<Sender>( | ||
sender: &mut Sender, | ||
relay_parent: Hash, | ||
) -> Result<ExecutorParams, RuntimeRequestFailed> | ||
where | ||
Sender: SubsystemSender<RuntimeApiMessage>, | ||
{ | ||
let (tx, rx) = oneshot::channel(); | ||
sender | ||
.send_message( | ||
RuntimeApiMessage::Request(relay_parent, RuntimeApiRequest::PendingExecutorParams(tx)) | ||
.into(), | ||
) | ||
.await; | ||
|
||
rx.await | ||
.map_err(|_| { | ||
gum::debug!(target: LOG_TARGET, ?relay_parent, "Runtime API request dropped"); | ||
|
||
RuntimeRequestFailed::Dropped | ||
}) | ||
.and_then(|res| { | ||
res.map_err(|e| { | ||
gum::debug!( | ||
target: LOG_TARGET, | ||
?relay_parent, | ||
err = ?e, | ||
"Runtime API request internal error" | ||
); | ||
match e { | ||
RuntimeApiError::Execution { .. } => RuntimeRequestFailed::InternalError, | ||
RuntimeApiError::NotSupported { .. } => RuntimeRequestFailed::NotSupported, | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
async fn precheck_pvf<Sender>( | ||
sender: &mut Sender, | ||
mut validation_backend: impl ValidationBackend, | ||
|
@@ -318,25 +359,52 @@ where | |
}, | ||
}; | ||
|
||
let executor_params = | ||
if let Ok(executor_params) = executor_params_at_relay_parent(relay_parent, sender).await { | ||
let executor_params = match request_pending_executor_params(sender, relay_parent).await { | ||
Ok(executor_params) => { | ||
gum::debug!( | ||
target: LOG_TARGET, | ||
?relay_parent, | ||
?validation_code_hash, | ||
"precheck: acquired executor params for the session: {:?}", | ||
"precheck: acquired pending executor params: {:?}", | ||
executor_params, | ||
); | ||
executor_params | ||
} else { | ||
}, | ||
Err(RuntimeRequestFailed::NotSupported) => { | ||
// Old runtime that doesn't support retrieving pending configuration. Use the | ||
// current configuration as a backward compatibility measure. | ||
// TODO: Remove this after all the networks are upgraded to runtimes supporting | ||
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. Todos should reference a ticket. |
||
// pending_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 current executor params: {:?}", | ||
executor_params, | ||
); | ||
executor_params | ||
} else { | ||
eskimor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
gum::warn!( | ||
target: LOG_TARGET, | ||
?relay_parent, | ||
?validation_code_hash, | ||
"precheck: failed to acquire current executor params, thus voting against.", | ||
); | ||
return PreCheckOutcome::Invalid | ||
} | ||
}, | ||
Err(_) => { | ||
gum::warn!( | ||
target: LOG_TARGET, | ||
?relay_parent, | ||
?validation_code_hash, | ||
"precheck: failed to acquire executor params for the session, thus voting against.", | ||
"precheck: failed to acquire pending executor params, thus voting against.", | ||
); | ||
return PreCheckOutcome::Invalid | ||
}; | ||
}, | ||
}; | ||
|
||
let timeout = pvf_prep_timeout(&executor_params, PvfPrepTimeoutKind::Precheck); | ||
|
||
|
@@ -388,7 +456,7 @@ where | |
.await; | ||
|
||
match d { | ||
Ok(None) | Err(RuntimeRequestFailed) => return AssumptionCheckOutcome::BadRequest, | ||
Ok(None) | Err(_) => return AssumptionCheckOutcome::BadRequest, | ||
Ok(Some(d)) => d, | ||
} | ||
}; | ||
|
@@ -406,7 +474,7 @@ where | |
.await; | ||
|
||
match validation_code { | ||
Ok(None) | Err(RuntimeRequestFailed) => AssumptionCheckOutcome::BadRequest, | ||
Ok(None) | Err(_) => AssumptionCheckOutcome::BadRequest, | ||
Ok(Some(v)) => AssumptionCheckOutcome::Matches(validation_data, v), | ||
} | ||
} else { | ||
|
@@ -516,8 +584,7 @@ where | |
{ | ||
Ok(true) => {}, | ||
Ok(false) => return Ok(ValidationResult::Invalid(InvalidCandidate::InvalidOutputs)), | ||
Err(RuntimeRequestFailed) => | ||
return Err(ValidationFailed("Check Validation Outputs: Bad request".into())), | ||
Err(_) => return Err(ValidationFailed("Check Validation Outputs: Bad request".into())), | ||
} | ||
} | ||
|
||
|
This file contains 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 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 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 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 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 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 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 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we document this in the impl guide?
Also, will we eventually have some mechanism to re-do pre-checking when pending exec params are queued? Because say some params are queued one session after we do pre-checking for the first time - that only gives us a window of one session to do any re-checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some docs to the implementer's guide. Regarding the situation you're describing, I hope that's not a valid concern. Say we pre-check PVF in session N and configuration changes are scheduled in session N+1. So, the PVF will be enacted in session N+2, and the configuration will change in session N+3. That means we still need to check the PVF against the session N+2 configuration as we want it to be active during that session. Could the configuration changes in session N+3 render it unusable? I hope not. As @bkchr mentioned, we should carefully evaluate any executor parameters change against every PVF which is on-chain before applying them, and I believe we'll have some tooling for that in the near future. And the PVF in question is already on-chain at session N, although it's not enacted yet, and we still have to check the configuration changes against it, too.
Something that bothers me more than that is the race condition inside a single session. Say, PVF is submitted to upgrade at block 10, and validators start pre-check voting at block 11, and the configuration change is scheduled at block 15, everything is inside a single session. In that case, we really can end up with a PVF which is enacted in session N+2 but cannot be executed due to configuration changes. It's a super corner case, but nothing is impossible. That risk should be evaluated, and if proved to be a valid vector of attack we should do something to mitigate it, but I didn't think much about it yet. Purely intuitively, I don't like the idea of re-pre-checking. It seems to me the solution could be too heavyweight for such a corner case. Probably there are some simpler ways like prohibiting configuration changes in the session where any PVF upgrades are submitted or something like that (I'm just thinking aloud, not saying it's a valid solution).