pvf-precheck: teach runtime-api to work with versions (#4510)

As part of #3211 we will need to add a couple of runtime APIs. That
change is coming in a following PR.

The runtime API for pre-checking will be introduced with a version bump
for `ParachainHost`. This commit prepares the ground for that change,
by introducing a error condition that signals that the given API is not
supported.
This commit is contained in:
Sergei Shulepov
2021-12-14 13:06:58 +01:00
committed by GitHub
parent c328d1e63b
commit 2ccbf38b85
3 changed files with 115 additions and 38 deletions
+18 -14
View File
@@ -19,23 +19,27 @@
use crate::JaegerError;
/// A description of an error causing the runtime API request to be unservable.
#[derive(Debug, Clone)]
pub struct RuntimeApiError(String);
#[derive(thiserror::Error, Debug, Clone)]
pub enum RuntimeApiError {
/// The runtime API cannot be executed due to a
#[error("The runtime API '{runtime_api_name}' cannot be executed")]
Execution {
/// The runtime API being called
runtime_api_name: &'static str,
/// The wrapped error. Marked as source for tracking the error chain.
#[source]
source: std::sync::Arc<dyn 'static + std::error::Error + Send + Sync>,
},
impl From<String> for RuntimeApiError {
fn from(s: String) -> Self {
RuntimeApiError(s)
}
/// The runtime API request in question cannot be executed because the runtime at the requested
/// relay-parent is an old version.
#[error("The API is not supported by the runtime at the relay-parent")]
NotSupported {
/// The runtime API being called
runtime_api_name: &'static str,
},
}
impl core::fmt::Display for RuntimeApiError {
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
write!(f, "{}", self.0)
}
}
impl std::error::Error for RuntimeApiError {}
/// A description of an error causing the chain API request to be unservable.
#[derive(Debug, Clone)]
pub struct ChainApiError {