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

Runtime API compilation error after adding Runtime API metadata. #14250

Closed
2 tasks done
koushiro opened this issue May 29, 2023 · 2 comments · Fixed by #14252
Closed
2 tasks done

Runtime API compilation error after adding Runtime API metadata. #14250

koushiro opened this issue May 29, 2023 · 2 comments · Fixed by #14252
Assignees

Comments

@koushiro
Copy link
Contributor

koushiro commented May 29, 2023

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Description of bug

When I upgrade substrate version of my project ( polkadot-v0.9.39 ==> polkadot-v0.9.42 ), the runtime API I originally defined will compile with an error:

➜  api-demo git:(master) cargo build --release
    Updating git repository `https:/paritytech/substrate`
    Updating crates.io index
   Compiling api-demo v0.1.0 (/Users/koushiro/api-demo)
error[E0277]: the trait bound `C: ProposalConfig` is not satisfied
  --> src/lib.rs:22:1
   |
22 | / sp_api::decl_runtime_apis! {
23 | |     pub trait DemoApi<C>
24 | |     where
25 | |         C: ProposalConfig,
...  |
28 | |     }
29 | | }
   | |_^ the trait `ProposalConfig` is not implemented for `C`
   |
   = note: this error originates in the macro `sp_api::decl_runtime_apis` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting type parameter `C`
   |
29 | }, C: ProposalConfig
   |  +++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `api-demo` due to previous error

I think it should be caused by #13302 .

Steps to reproduce

The simple repo to reproduce the issue.

stable-aarch64-apple-darwin (default)
rustc 1.69.0 (84c898d65 2023-04-16)
[package]
name = "api-demo"
version = "0.1.0"
edition = "2021"

[dependencies]
scale-codec = { package = "parity-scale-codec", version = "3.5.0", default-features = false }
scale-info = { version = "2.7.0", default-features = false }

sp-api = { git = "https:/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
sp-runtime = { git = "https:/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
sp-std = { git = "https:/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }

[features]
default = ["std"]
std = [
    "scale-codec/std",
    "scale-info/std",
    "sp-api/std",
    "sp-runtime/std",
    "sp-std/std",
]
#![cfg_attr(not(feature = "std"), no_std)]

use scale_codec::{Codec, Decode, Encode};
use scale_info::TypeInfo;
// Substrate
use sp_runtime::{traits::Member, RuntimeDebug};
use sp_std::hash::Hash;

pub trait ProposalConfig {
    type ProposalNumber: Member + Codec + Into<u64> + From<u32> + Copy + Hash + Ord;
}

pub type ProposalNumberOf<T> = <T as ProposalConfig>::ProposalNumber;

pub type VotingStatusOf<C> = VotingStatus<ProposalNumberOf<C>>;

#[derive(Clone, PartialEq, RuntimeDebug, Encode, Decode, TypeInfo)]
pub struct VotingStatus<PNumber> {
    pub last_processed_number: Option<PNumber>,
}

sp_api::decl_runtime_apis! {
    pub trait DemoApi<C>
    where
        C: ProposalConfig,
    {
        fn voting_status() -> VotingStatusOf<C>;
    }
}
@koushiro
Copy link
Contributor Author

@lexnv PTAL

@bkchr
Copy link
Member

bkchr commented May 29, 2023

Found the issue, we don't forward the where bound properly. Let me quickly fix this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants