Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: runtime API implementations not exported #809

Merged
merged 2 commits into from
Nov 27, 2024
Merged
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ sp-core = { git = "https://github.com/parityt
sp-genesis-builder = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-crates-io-v1.7.0" }
sp-inherents = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-crates-io-v1.7.0" }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-crates-io-v1.7.0" }
sp-metadata-ir = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-crates-io-v1.7.0" }
sp-offchain = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-crates-io-v1.7.0" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-crates-io-v1.7.0" }
sp-session = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-crates-io-v1.7.0" }
Expand Down
2 changes: 2 additions & 0 deletions runtimes/peregrine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ sp-block-builder = { workspace = true }
sp-consensus-aura = { workspace = true }
sp-core = { workspace = true }
sp-inherents = { workspace = true }
sp-metadata-ir = { workspace = true }
sp-offchain = { workspace = true }
sp-runtime = { workspace = true }
sp-session = { workspace = true }
Expand Down Expand Up @@ -241,6 +242,7 @@ std = [
"sp-core/std",
"sp-genesis-builder/std",
"sp-inherents/std",
"sp-metadata-ir/std",
"sp-offchain/std",
"sp-runtime/std",
"sp-session/std",
Expand Down
1 change: 1 addition & 0 deletions runtimes/peregrine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ mod migrations;
pub use migrations::RuntimeMigrations;
mod parachain;
mod runtime_apis;
use runtime_apis::_InternalImplRuntimeApis;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We basically need to import the runtime_metadata function, and since the real trait (InternalImplRuntimeApis) is private, we declare a second trait in the runtime_apis module which we then import here to import the runtime_metadata function.

pub use runtime_apis::{api, RuntimeApi};
mod system;
use sp_version::RuntimeVersion;
Expand Down
17 changes: 17 additions & 0 deletions runtimes/peregrine/src/runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
use sp_api::impl_runtime_apis;
use sp_core::OpaqueMetadata;
use sp_inherents::{CheckInherentsResult, InherentData};
use sp_metadata_ir::RuntimeApiMetadataIR;
use sp_runtime::{
traits::{Block as BlockT, TryConvert},
ApplyExtrinsicResult, KeyTypeId,
Expand Down Expand Up @@ -53,6 +54,22 @@ use crate::{
// `impl_runtime_apis` is private.
pub(crate) const RUNTIME_API_VERSION: ApisVec = RUNTIME_API_VERSIONS;

// Workaround for runtime API impls not exposed in metadata if implemented in a
// different file than the runtime's `lib.rs`. Related issue (subxt) -> https://github.com/paritytech/subxt/issues/1873.
pub(crate) trait _InternalImplRuntimeApis {
fn runtime_metadata(&self) -> Vec<RuntimeApiMetadataIR>;
}

impl<T> _InternalImplRuntimeApis for T
where
T: InternalImplRuntimeApis,
{
#[inline(always)]
fn runtime_metadata(&self) -> Vec<RuntimeApiMetadataIR> {
<T as InternalImplRuntimeApis>::runtime_metadata(self)
}
}

impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
Expand Down
2 changes: 2 additions & 0 deletions runtimes/spiritnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ sp-block-builder = { workspace = true }
sp-consensus-aura = { workspace = true }
sp-core = { workspace = true }
sp-inherents = { workspace = true }
sp-metadata-ir = { workspace = true }
sp-offchain = { workspace = true }
sp-runtime = { workspace = true }
sp-session = { workspace = true }
Expand Down Expand Up @@ -240,6 +241,7 @@ std = [
"sp-core/std",
"sp-genesis-builder/std",
"sp-inherents/std",
"sp-metadata-ir/std",
"sp-offchain/std",
"sp-runtime/std",
"sp-session/std",
Expand Down
1 change: 1 addition & 0 deletions runtimes/spiritnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ mod migrations;
pub use migrations::RuntimeMigrations;
mod parachain;
mod runtime_apis;
use runtime_apis::_InternalImplRuntimeApis;
pub use runtime_apis::{api, RuntimeApi};
mod system;
use sp_version::RuntimeVersion;
Expand Down
17 changes: 17 additions & 0 deletions runtimes/spiritnet/src/runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
use sp_api::impl_runtime_apis;
use sp_core::OpaqueMetadata;
use sp_inherents::{CheckInherentsResult, InherentData};
use sp_metadata_ir::RuntimeApiMetadataIR;
use sp_runtime::{
traits::{Block as BlockT, TryConvert},
ApplyExtrinsicResult, KeyTypeId,
Expand Down Expand Up @@ -53,6 +54,22 @@ use crate::{
// `impl_runtime_apis` is private.
pub(crate) const RUNTIME_API_VERSION: ApisVec = RUNTIME_API_VERSIONS;

// Workaround for runtime API impls not exposed in metadata if implemented in a
// different file than the runtime's `lib.rs`. Related issue (subxt) -> https://github.com/paritytech/subxt/issues/1873.
pub(crate) trait _InternalImplRuntimeApis {
fn runtime_metadata(&self) -> Vec<RuntimeApiMetadataIR>;
}

impl<T> _InternalImplRuntimeApis for T
where
T: InternalImplRuntimeApis,
{
#[inline(always)]
fn runtime_metadata(&self) -> Vec<RuntimeApiMetadataIR> {
<T as InternalImplRuntimeApis>::runtime_metadata(self)
}
}

impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
Expand Down
Loading