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

Log UnknownBlock errors from runtime #6288

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions node/collation-generation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ async fn obtain_current_validation_code_hash(
}
},
Err(e @ RuntimeApiError::Execution { .. }) => Err(e.into()),
Err(e @ RuntimeApiError::UnknownBlock { .. }) => Err(e.into()),
}
}

Expand Down
11 changes: 11 additions & 0 deletions node/core/provisioner/src/disputes/prioritized_selection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ where
);
HashMap::new()
},
Err(GetOnchainDisputesError::UnknownBlock(runtime_api_err, parent_hash)) => {
gum::warn!(
target: LOG_TARGET,
?runtime_api_err,
?parent_hash,
"Trying to fetch onchain disputes for unknown block.",
);
HashMap::new()
},
};

let recent_disputes = request_disputes(sender).await;
Expand Down Expand Up @@ -477,6 +486,8 @@ where
GetOnchainDisputesError::Execution(e, relay_parent),
RuntimeApiError::NotSupported { .. } =>
GetOnchainDisputesError::NotSupported(e, relay_parent),
RuntimeApiError::UnknownBlock { .. } =>
GetOnchainDisputesError::UnknownBlock(e, relay_parent),
})
})
.map(|v| v.into_iter().map(|e| ((e.0, e.1), e.2)).collect())
Expand Down
3 changes: 3 additions & 0 deletions node/core/provisioner/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ pub enum GetOnchainDisputesError {

#[error("runtime doesn't support RuntimeApiRequest::Disputes for parent {1}")]
NotSupported(#[source] RuntimeApiError, Hash),

#[error("runtime api is called on unknown block {1}")]
UnknownBlock(#[source] RuntimeApiError, Hash),
}

pub fn log_error(result: Result<()>) -> std::result::Result<(), FatalError> {
Expand Down
8 changes: 8 additions & 0 deletions node/core/provisioner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,14 @@ async fn has_required_runtime(
);
false
},
Result::Ok(Err(RuntimeApiError::UnknownBlock { .. })) => {
gum::trace!(
target: LOG_TARGET,
?relay_parent,
"UnknownBlock error while fetching ParachainHost runtime api version"
);
false
},
Result::Err(_) => {
gum::trace!(
target: LOG_TARGET,
Expand Down
2 changes: 1 addition & 1 deletion node/core/pvf-checker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ async fn sign_and_submit_pvf_check_statement(
target: LOG_TARGET,
?relay_parent,
?validation_code_hash,
"error occured during submitting a vote: {:?}",
"error occurred during submitting a vote: {:?}",
e,
);
},
Expand Down
2 changes: 2 additions & 0 deletions node/core/pvf-checker/src/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub(crate) enum RuntimeRequestError {
NotSupported,
ApiError,
CommunicationError,
UnknownBlock,
}

pub(crate) async fn runtime_api_request<T>(
Expand Down Expand Up @@ -102,6 +103,7 @@ pub(crate) async fn runtime_api_request<T>(
RuntimeRequestError::ApiError
},
NotSupported { .. } => RuntimeRequestError::NotSupported,
UnknownBlock { .. } => RuntimeRequestError::UnknownBlock,
}
})
})
Expand Down
62 changes: 42 additions & 20 deletions node/core/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use polkadot_node_subsystem::{
messages::{RuntimeApiMessage, RuntimeApiRequest as Request},
overseer, FromOrchestra, OverseerSignal, SpawnedSubsystem, SubsystemError, SubsystemResult,
};
use polkadot_node_subsystem_types::RuntimeApiSubsystemClient;
use polkadot_node_subsystem_types::{ApiError, RuntimeApiSubsystemClient};
use polkadot_primitives::Hash;

use cache::{RequestResult, RequestResultCache};
Expand Down Expand Up @@ -355,33 +355,55 @@ where
let sender = $sender;
let version: u32 = $version; // enforce type for the version expression
let runtime_version = client.api_version_parachain_host(relay_parent).await
.unwrap_or_else(|e| {
gum::warn!(
target: LOG_TARGET,
"cannot query the runtime API version: {}",
e,
);
Some(0)
.map_err(|e| {
if let ApiError::UnknownBlock(s) = e {
// We want a specific indication for this error. It generally indicates that the runtime api is
// called for a block which is already pruned. Legitimate reasons for this may be block restart.
// Separate value in `RuntimeApiError` enum allows the caller to handle it properly.
gum::warn!(
target: LOG_TARGET,
"cannot query the runtime API version due to UnknownBlock error: {}",
s,
);
RuntimeApiError::UnknownBlock{runtime_api_name: stringify!($api_name)}
} else {
gum::warn!(
target: LOG_TARGET,
"cannot query the runtime API version due to error: {}",
e,
);
RuntimeApiError::Execution{runtime_api_name: stringify!($api_name), source: std::sync::Arc::new(e)}
}
})
.unwrap_or_else(|| {
gum::warn!(
target: LOG_TARGET,
"no runtime version is reported"
);
0
.map(|v| {
match v {
Some(v) => v,
None => {
gum::warn!(
target: LOG_TARGET,
"no runtime version is reported"
);
0
}
}
});

let res = if runtime_version >= version {
client.$api_name(relay_parent $(, $param.clone() )*).await
let res = match runtime_version {
Ok(runtime_version) if runtime_version >= version => {
client.$api_name(relay_parent $(, $param.clone() )*).await
tdimitrov marked this conversation as resolved.
Show resolved Hide resolved
.map_err(|e| RuntimeApiError::Execution {
runtime_api_name: stringify!($api_name),
source: std::sync::Arc::new(e),
})
} else {
Err(RuntimeApiError::NotSupported {
runtime_api_name: stringify!($api_name),
})
},
Ok(_) => {
Err(RuntimeApiError::NotSupported {
runtime_api_name: stringify!($api_name),
})
}
Err(e) => Err(e)
};

metrics.on_request(res.is_ok());
let _ = sender.send(res.clone());

Expand Down
10 changes: 10 additions & 0 deletions node/subsystem-types/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ pub enum RuntimeApiError {
/// The runtime API being called
runtime_api_name: &'static str,
},

/// The runtime API request can't be executed because the block at which the execution must
/// happen doesn't exist. This usually happens when the block is already pruned.
#[error(
"The runtime API {runtime_api_name} was called for an unknown (already pruned?) block"
)]
UnknownBlock {
/// The runtime API being called
runtime_api_name: &'static str,
},
}

/// A description of an error causing the chain API request to be unservable.
Expand Down
2 changes: 1 addition & 1 deletion node/subsystem-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub mod errors;
pub mod messages;

mod runtime_client;
pub use runtime_client::RuntimeApiSubsystemClient;
pub use runtime_client::{ApiError, RuntimeApiSubsystemClient};

pub use jaeger::*;
pub use polkadot_node_jaeger as jaeger;
Expand Down
3 changes: 2 additions & 1 deletion node/subsystem-types/src/runtime_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ use polkadot_primitives::{
PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode,
ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
};
use sp_api::{ApiError, ApiExt, ProvideRuntimeApi};
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_authority_discovery::AuthorityDiscoveryApi;
use sp_consensus_babe::{BabeApi, Epoch};
use std::collections::BTreeMap;

pub use sp_api::ApiError;
/// Exposes all runtime calls that are used by the runtime API subsystem.
#[async_trait]
pub trait RuntimeApiSubsystemClient {
Expand Down