JoshOrndorff / recipes

A Hands-On Cookbook for Aspiring Blockchain Chefs
GNU General Public License v3.0
379 stars 187 forks source link

Super Genesis doesn't compile #89

Closed JoshOrndorff closed 4 years ago

JoshOrndorff commented 4 years ago

To reproduce the issue, clone this repo, then

cd kitchen/runtimes/super-genesis
cargo check
    Checking super-genesis v2.0.0 (/home/joshy/ProgrammingProjects/recipes/kitchen/runtimes/super-genesis)
error[E0277]: a collection of type `std::vec::Vec<(substrate_consensus_babe_primitives::app::Public, u64)>` cannot be built from an iterator over elements of type `(substrate_consensus_babe_primitives::app::Public, u64)`
  --> runtimes/super-genesis/src/lib.rs:28:73
   |
28 |             authorities: initial_authorities.iter().map(|x| (x.3.clone(), 1u64)).collect(),
   |                                                                                  ^^^^^^^ a collection of type `std::vec::Vec<(substrate_consensus_babe_primitives::app::Public, u64)>` cannot be built from `std::iter::Iterator<Item=(substrate_consensus_babe_primitives::app::Public, u64)>`
   |
   = help: the trait `std::iter::FromIterator<(substrate_consensus_babe_primitives::app::Public, u64)>` is not implemented for `std::vec::Vec<(substrate_consensus_babe_primitives::app::Public, u64)>`

error[E0277]: a collection of type `std::vec::Vec<(substrate_finality_grandpa_primitives::app::Public, u64)>` cannot be built from an iterator over elements of type `(substrate_finality_grandpa_primitives::app::Public, u64)`
  --> runtimes/super-genesis/src/lib.rs:31:73
   |
31 |             authorities: initial_authorities.iter().map(|x| (x.2.clone(), 1u64)).collect(),
   |                                                                                  ^^^^^^^ a collection of type `std::vec::Vec<(substrate_finality_grandpa_primitives::app::Public, u64)>` cannot be built from `std::iter::Iterator<Item=(substrate_finality_grandpa_primitives::app::Public, u64)>`
   |
   = help: the trait `std::iter::FromIterator<(substrate_finality_grandpa_primitives::app::Public, u64)>` is not implemented for `std::vec::Vec<(substrate_finality_grandpa_primitives::app::Public, u64)>`

error: aborting due to 2 previous errors

I can't figure out what's wrong with these lines. They are almost identical to the lines in the node template which compile just fine. https://github.com/paritytech/substrate/blob/master/bin/node-template/src/chain_spec.rs#L140

JoshOrndorff commented 4 years ago

Same problem for the weight-fee-genesis.

4meta5 commented 4 years ago

when I add a .into() as seen below and mark the integer as u64,

authorities: initial_authorities.iter().map(|x| (x.2.clone().into(), 1u64)).collect(),

The error message changes, claiming that there does not exist From implemented for the same type. I can't add a trivial From implementation from the type to the same type because it is private.

error[E0277]: the trait bound `substrate_consensus_babe_primitives::app::Public: std::convert::From<substrate_consensus_babe_primitives::app::Public>` is not satisfied
  --> runtimes/super-genesis/src/lib.rs:28:65
   |
28 |             authorities: initial_authorities.iter().map(|x| (x.3.clone().into(), 1u64)).collect(),
   |                                                                          ^^^^ the trait `std::convert::From<substrate_consensus_babe_primitives::app::Public>` is not implemented for `substrate_consensus_babe_primitives::app::Public`
   |
   = help: the following implementations were found:
             <substrate_consensus_babe_primitives::app::Public as std::convert::From<substrate_primitives::sr25519::Public>>
   = note: required because of the requirements on the impl of `std::convert::Into<substrate_consensus_babe_primitives::app::Public>` for `substrate_consensus_babe_primitives::app::Public`

error[E0277]: the trait bound `substrate_finality_grandpa_primitives::app::Public: std::convert::From<substrate_finality_grandpa_primitives::app::Public>` is not satisfied
  --> runtimes/super-genesis/src/lib.rs:31:65
   |
31 |             authorities: initial_authorities.iter().map(|x| (x.2.clone().into(), 1u64)).collect(),
   |                                                                          ^^^^ the trait `std::convert::From<substrate_finality_grandpa_primitives::app::Public>` is not implemented for `substrate_finality_grandpa_primitives::app::Public`
   |
   = help: the following implementations were found:
             <substrate_finality_grandpa_primitives::app::Public as std::convert::From<substrate_primitives::ed25519::Public>>
   = note: required because of the requirements on the impl of `std::convert::Into<substrate_finality_grandpa_primitives::app::Public>` for `substrate_finality_grandpa_primitives::app::Public`

error: aborting due to 2 previous errors
JoshOrndorff commented 4 years ago

Here's the explanation of that error code. https://doc.rust-lang.org/error-index.html#E0277

Here's a stripped down example that seems to do the same thing but actually works. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=181862e824b8245446f16bedfa2246fc

JoshOrndorff commented 4 years ago

Aha, the primitives in the genesis modules were still pulling in Substrate master.

JoshOrndorff commented 4 years ago

Fixed in https://github.com/substrate-developer-hub/recipes/pull/88