Skip to content

Commit

Permalink
sp-api: Remove invalid unsafe trait bounds (paritytech#12502)
Browse files Browse the repository at this point in the history
The runtime api implementation contained invalid unsafe trait bounds. `Sync` was never correct there
and `Send` should have not been "force implemented".
  • Loading branch information
bkchr authored and ark0f committed Feb 27, 2023
1 parent 67ab221 commit a774746
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
2 changes: 1 addition & 1 deletion client/beefy/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ where
Block: BlockT,
BE: Backend<Block>,
Runtime: ProvideRuntimeApi<Block>,
Runtime::Api: BeefyApi<Block> + Send + Sync,
Runtime::Api: BeefyApi<Block> + Send,
{
fn decode_and_verify(
&self,
Expand Down
2 changes: 1 addition & 1 deletion primitives/api/proc-macro/src/decl_runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
15 changes: 2 additions & 13 deletions primitives/api/proc-macro/src/impl_runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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! {
Expand Down

0 comments on commit a774746

Please sign in to comment.