2

I'm trying to implement simple PoW for my node. After debugging all other stuff I've encountered the problem where finality-grandpa and storage do not get compiled because standard library macros are (for some reason) out of scope.

I've checked that std features and enabled for all dependencies where they need to be enabled. Also I found this information about one of the dependencies. But as it's a non-local (pulled from github) I can't change that functionality.

Please note that I did not modify any of these two pallets (just imported my own, implementing PoW). Before that (on clear substrate-node-template which I use as a base for my project) those built without any problem.

The question is: How do I fix this? Should I enable std for these crates somehow? As far as I know, the node is built into native Rust and WASM, and for WASM it's built in no-std. By why did it build before in this case?

Here is a part of the error message I get:

cargo build --release 
    Updating crates.io index
    Updating git repository `https://github.com/paritytech/substrate.git`
    Updating git repository `https://github.com/paritytech/substrate`
   Compiling node-template-runtime v4.0.0-dev (/home/creestl/programming/blockchain/crain/runtime)
error: failed to run custom build command for `node-template-runtime v4.0.0-dev (/home/creestl/programming/blockchain/crain/runtime)`
 
Caused by:
  process didn't exit successfully: `/home/creestl/programming/blockchain/crain/target/release/build/node-template-runtime-d1d0301f1ce42478/build-script-build` (exit status: 1)
  --- stdout
  Information that should be included in a bug report.
  Executing build command: "rustup" "run" "nightly" "cargo" "rustc" "--target=wasm32-unknown-unknown" "--manifest-path=/home/creestl/programming/blockchain/crain/target/release/wbuild/node-template-runtime/Cargo.toml" "--color=always" "--profile" "release"
  Using rustc version: rustc 1.62.0-nightly (de1bc0008 2022-04-21)
 
 
  --- stderr
     Compiling frame-support v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.18#fc3fd073)
     Compiling sp-finality-grandpa v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.18#fc3fd073)
  error: cannot find macro `format` in this scope
    --> /home/creestl/.cargo/git/checkouts/substrate-7e08433d4c370a21/fc3fd07/primitives/finality-grandpa/src/lib.rs:43:2
     |
  43 |     app_crypto!(ed25519, GRANDPA);
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: consider importing one of these items:
             alloc::format
             scale_info::prelude::format
     = note: this error originates in the macro `$crate::app_crypto_public_common_if_std` (in Nightly builds, run with -Z macro-backtrace for more info)
 
  error[E0433]: failed to resolve: use of undeclared crate or module `std`
    --> /home/creestl/.cargo/git/checkouts/substrate-7e08433d4c370a21/fc3fd07/primitives/finality-grandpa/src/lib.rs:43:2
     |
  43 |     app_crypto!(ed25519, GRANDPA);
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `std`
     |
     = note: this error originates in the macro `$crate::app_crypto_public_common_if_std` (in Nightly builds, run with -Z macro-backtrace for more info)
 
  error[E0433]: failed to resolve: use of undeclared type `String`
    --> /home/creestl/.cargo/git/checkouts/substrate-7e08433d4c370a21/fc3fd07/primitives/finality-grandpa/src/lib.rs:43:2
     |
  43 |     app_crypto!(ed25519, GRANDPA);
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
     |
     = note: this error originates in the macro `$crate::app_crypto_public_common_if_std` (in Nightly builds, run with -Z macro-backtrace for more info)
  help: consider importing one of these items
     |
  42 |     use alloc::string::String;
     |
  42 |     use codec::alloc::string::String;
     |
  42 |     use scale_info::prelude::string::String;
     |

And here is a link to the repo with my last changes

2 Answers 2

3

standard library macros are (for some reason) out of scope.

TL;DR: you cannont use std in runtime development

As you see on the node template all runtime files must not use std because they target Wasm, and thus cannot generally use the full std, and include:

#![cfg_attr(not(feature = "std"), no_std)]

Instead of the full library, the general subset of std types and traits you likely need are in sp_std. This includes primitives like str and vec modules. Of note, it's likely for runtime development frame_support::storage::BoundedVec should be used though, as boundedness is typically critical in runtimes).

6
  • Yes, I know that runtime compiles to WASM in no-std. But here is a short list of operations that caused a bug described in the question: 1) Clone Node Template. Builds successfully 2) Import sp-consensus-pow. Change some stuff in it. 3) Build again. Build fails. And the error occurs somewhere in finalty-grandpa and storage crates because of std feature. Once again, I did not change anything in those crates (they are the same as in step 1), but they fail to build. Why so?
    – CREESTL
    Commented Apr 25, 2022 at 17:58
  • An error similar to mine was described here
    – CREESTL
    Commented Apr 25, 2022 at 18:01
  • Are you using the recent rust stable version? Commented Apr 25, 2022 at 18:08
  • Yes. I've updated to stable 1.60 and nightly 1.62. Also added wasm32-unknown-unknown as a new target
    – CREESTL
    Commented Apr 25, 2022 at 21:31
  • Sounds silly, but perhaps its as simple as missing feature flags substrate.stackexchange.com/a/2088/34 but I have not reviewed your node linked in the OP to determine for sure
    – Nuke
    Commented Apr 26, 2022 at 0:13
0

I've fixed it. The reason for the bug was that I've included

getrandom = {version = "0.2", features= ["js"] }  

in Cargo.toml of one of my crates. And that caused some inner conflicts. After I removed that dependency - everything was OK

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented May 8, 2022 at 0:38

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.