sp-api: Remove invalid unsafe trait bounds (#12502)

The runtime api implementation contained invalid unsafe trait bounds. `Sync` was never correct there
and `Send` should have not been "force implemented".
This commit is contained in:
Bastian Köcher
2022-10-17 10:20:51 +02:00
committed by GitHub
parent ce4cad8b8b
commit 37538f0429
3 changed files with 4 additions and 15 deletions
@@ -535,7 +535,7 @@ impl<'a> Fold for ToClientSideDecl<'a> {
if is_core_trait {
// Add all the supertraits we want to have for `Core`.
input.supertraits = parse_quote!('static + Send + Sync);
input.supertraits = parse_quote!('static + Send);
} else {
// Add the `Core` runtime api as super trait.
let crate_ = &self.crate_;
@@ -211,19 +211,6 @@ fn generate_runtime_api_base_structures() -> Result<TokenStream> {
recorder: std::option::Option<#crate_::ProofRecorder<Block>>,
}
// `RuntimeApi` itself is not threadsafe. However, an instance is only available in a
// `ApiRef` object and `ApiRef` also has an associated lifetime. This lifetimes makes it
// impossible to move `RuntimeApi` into another thread.
#[cfg(any(feature = "std", test))]
unsafe impl<Block: #crate_::BlockT, C: #crate_::CallApiAt<Block>> Send
for RuntimeApiImpl<Block, C>
{}
#[cfg(any(feature = "std", test))]
unsafe impl<Block: #crate_::BlockT, C: #crate_::CallApiAt<Block>> Sync
for RuntimeApiImpl<Block, C>
{}
#[cfg(any(feature = "std", test))]
impl<Block: #crate_::BlockT, C: #crate_::CallApiAt<Block>> #crate_::ApiExt<Block> for
RuntimeApiImpl<Block, C>
@@ -515,6 +502,8 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> {
#crate_::StateBackend<#crate_::HashFor<__SR_API_BLOCK__>>
});
where_clause.predicates.push(parse_quote! { &'static RuntimeApiImplCall: Send });
// Require that all types used in the function signatures are unwind safe.
extract_all_signature_types(&input.items).iter().for_each(|i| {
where_clause.predicates.push(parse_quote! {