0

I have a test-suite that is based on sub-xt. This is also pulled in the suite as a dependency in cargo.toml as follows.

[dependencies]
subxt = { version = "0.37.0", git = "https://github.com/paritytech/subxt" }

I have installed subxt using the following command.

cargo install --version 0.37.0 subxt-cli

I have my node running and then I generate the encoded metadata and the compact.compressed.wasm. I run the test-suite using the command

cargo run

I get the following error during compilation.

error[E0308]: mismatched types
   --> /home/rrr/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sp-core-7.0.0/src/sr25519.rs:591:33
    |
591 |           let mini_key: MiniSecretKey = mini_secret_from_entropy(entropy, password.unwrap_or(""))
    |  _______________________-------------___^
    | |                       |
    | |                       expected due to this
592 | |             .expect("32 bytes can always build a key; qed");
    | |___________________________________________________________^ expected `MiniSecretKey`, found `schnorrkel::keys::MiniSecretKey`
    |
    = note: `schnorrkel::keys::MiniSecretKey` and `MiniSecretKey` have similar names, but are actually distinct types
note: `schnorrkel::keys::MiniSecretKey` is defined in crate `schnorrkel`
   --> /home/rrr/.cargo/registry/src/index.crates.io-6f17d22bba15001f/schnorrkel-0.11.4/src/keys.rs:99:1
    |
99  | pub struct MiniSecretKey(pub (crate) [u8; MINI_SECRET_KEY_LENGTH]);
    | ^^^^^^^^^^^^^^^^^^^^^^^^
note: `MiniSecretKey` is defined in crate `schnorrkel`
   --> /home/rrr/.cargo/registry/src/index.crates.io-6f17d22bba15001f/schnorrkel-0.9.1/src/keys.rs:99:1
    |
99  | pub struct MiniSecretKey(pub (crate) [u8; MINI_SECRET_KEY_LENGTH]);
    | ^^^^^^^^^^^^^^^^^^^^^^^^
    = note: perhaps two different versions of crate `schnorrkel` are being used?

My current active-tool chain is as follows.

nightly-2024-05-02-x86_64-unknown-linux-gnu (default)
rustc 1.80.0-nightly (c987ad527 2024-05-01)

while my node is using an older nightly toolchain

nightly-2022-10-09-x86_64-unknown-linux-gnu
rustc 1.66.0-nightly (8796e7a9c 2022-10-08)

How do I fix this to run the test-suite?

1 Answer 1

0

Your error message mostly explains the issue here:

note: perhaps two different versions of crate schnorrkel are being used?

The error you're having is that something is expecting the MiniSecretKey from schnorrkel 0.9.1, but is being given a MiniSecretKey from schnorrkel 0.11.4.

subxt-signer is using schnorrkel 0.11.4, and sp-core 7.0.0 (which is quite old now and was published Nov 16th 2022) asks for schnorrkel 0.9.1 (well 0.9.1 <= n < 0.10.0).

If possible, one solution is to update sp-core to a more recent version (34.0.0 is the latest at the time of writing and asks for 0.11.4, so that would work).

If you're passing a MiniSecretKey from sp-core to subxt-signer, another solution is to manually import the newer version of schnorrkel and manually convert form the old MiniSecretKey to the new one.

16
  • I think sp-core is not a direct dependency. I updated other dependencies to their latest versions. I am getting a different error now. Like follows ------------------------------------------- error: Failed to fetch metadata, make sure that you're pointing at a node that is providing substrate-based metadata: Cannot scale encode/decode value: Cannot try_into() to Metadata. --> src/main.rs:21:1 | 21 | #[subxt::subxt(runtime_metadata_path = "./data/metadata.scale")] -----------------------------------------------------
    – RRR
    Commented Jul 15 at 19:11
  • One reason might be that my node points to an older substrate release branch. I was trying older subtxt version 0.25.0 but whenever I run the test suite I just get the following error. --------------------------------------------------------------------- Updating crates.io index Updating git repository https://github.com/paritytech/subxt error: failed to select a version for the requirement subxt = "^0.25.0" candidate versions found which didn't match: 0.37.0 location searched: Git repository github.com/paritytech/subxt -----------------------------------------------
    – RRR
    Commented Jul 15 at 19:23
  • RE "failed to select a version for the requirement subxt": if you point to a git dependency like that, you'd need to use tag = "v0.25.0" to point at the relevant git commit to get an older version. RE "Failed to fetch metadata", it sounds like the "./data/metadata.scale" isn't the expected format. Have a go at using the subxt binary to fetch metadata again from a node and try that (ie docs.rs/subxt/latest/subxt/book/setup/codegen/index.html)
    – jsdw
    Commented Jul 22 at 10:05
  • [dependencies] subxt = {git = "github.com/paritytech/subxt", tag = "v0.25.0"} tokio = { version = "1.8", features = ["rt-multi-thread", "macros", "time"] } serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0.64" sp-core = { version = "34.0.0", default-features = false } sp-keyring = "34.0.0" sp-runtime = "34.0.0" futures = "0.3.13" codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full", "bit-vec"] } hex = "0.4.3" tracing-subscriber = "0.3.18" rand = "0.8.5" - These are my dependencies
    – RRR
    Commented Jul 22 at 20:32
  • If I use the tag= "v0.25.0" I get the MiniSecretKey error again even if I bump sp-core to v34.0.0. I am not sure if manually import the newer version of Schnorrkel and manually convert form the old MiniSecretKey would work as the MiniSecretkey error does not originate in my code. I feel that just using the latest version of subxt does not lead to this error but then I have to handle the next error which is the metadata error I mentioned earlier.
    – RRR
    Commented Jul 22 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.