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

Commit 6537f8b

Browse files
xlcgavofyork
authored andcommitted
Fix node-template (#3924)
* fix node-template Use MultiSignature to maintain compatibility with substrate-node Reset version to 1 Remove unused const * fix chain_spec * line width
1 parent 857b951 commit 6537f8b

File tree

6 files changed

+47
-40
lines changed

6 files changed

+47
-40
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node-template/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ grandpa-primitives = { package = "substrate-finality-grandpa-primitives", path =
3434
substrate-client = { path = "../core/client" }
3535
basic-authorship = { package = "substrate-basic-authorship", path = "../core/basic-authorship" }
3636
runtime = { package = "node-template-runtime", path = "runtime" }
37+
sr-primitives = { path = "../core/sr-primitives" }
3738

3839
[build-dependencies]
3940
vergen = "3.0.4"

node-template/runtime/src/lib.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ use rstd::prelude::*;
1212
use primitives::{OpaqueMetadata, crypto::key_types};
1313
use sr_primitives::{
1414
ApplyResult, transaction_validity::TransactionValidity, generic, create_runtime_str,
15-
impl_opaque_keys, AnySignature
15+
impl_opaque_keys, MultiSignature
16+
};
17+
use sr_primitives::traits::{
18+
NumberFor, BlakeTwo256, Block as BlockT, StaticLookup, Verify, ConvertInto, IdentifyAccount
1619
};
17-
use sr_primitives::traits::{NumberFor, BlakeTwo256, Block as BlockT, StaticLookup, Verify, ConvertInto};
1820
use sr_primitives::weights::Weight;
1921
use client::{
2022
block_builder::api::{CheckInherentsResult, InherentData, self as block_builder_api},
@@ -39,11 +41,11 @@ pub use support::{StorageValue, construct_runtime, parameter_types, traits::Rand
3941
pub type BlockNumber = u32;
4042

4143
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
42-
pub type Signature = AnySignature;
44+
pub type Signature = MultiSignature;
4345

4446
/// Some way of identifying an account on the chain. We intentionally make it equivalent
4547
/// to the public key of our transaction signing scheme.
46-
pub type AccountId = <Signature as Verify>::Signer;
48+
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
4749

4850
/// The type for looking up accounts. We don't expect more than 4 billion of them, but you
4951
/// never know...
@@ -94,26 +96,21 @@ pub mod opaque {
9496
pub const VERSION: RuntimeVersion = RuntimeVersion {
9597
spec_name: create_runtime_str!("node-template"),
9698
impl_name: create_runtime_str!("node-template"),
97-
authoring_version: 3,
98-
spec_version: 4,
99-
impl_version: 4,
99+
authoring_version: 1,
100+
spec_version: 1,
101+
impl_version: 1,
100102
apis: RUNTIME_API_VERSIONS,
101103
};
102104

103105
pub const MILLISECS_PER_BLOCK: u64 = 6000;
104106

105107
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
106108

107-
pub const EPOCH_DURATION_IN_BLOCKS: u32 = 10 * MINUTES;
108-
109109
// These time units are defined in number of blocks.
110110
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
111111
pub const HOURS: BlockNumber = MINUTES * 60;
112112
pub const DAYS: BlockNumber = HOURS * 24;
113113

114-
// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
115-
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
116-
117114
/// The version infromation used to identify this runtime when compiled natively.
118115
#[cfg(feature = "std")]
119116
pub fn native_version() -> NativeVersion {
@@ -175,7 +172,7 @@ impl grandpa::Trait for Runtime {
175172
impl indices::Trait for Runtime {
176173
/// The type for recording indexing into the account enumeration. If this ever overflows, there
177174
/// will be problems!
178-
type AccountIndex = u32;
175+
type AccountIndex = AccountIndex;
179176
/// Use the standard means of resolving an index hint from an id.
180177
type ResolveHint = indices::SimpleResolveHint<Self::AccountId, Self::AccountIndex>;
181178
/// Determine whether an account is dead.
@@ -346,7 +343,7 @@ impl_runtime_apis! {
346343
fn slot_duration() -> u64 {
347344
Aura::slot_duration()
348345
}
349-
346+
350347
fn authorities() -> Vec<AuraId> {
351348
Aura::authorities()
352349
}

node-template/src/chain_spec.rs

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use primitives::{Pair, Public};
1+
use primitives::{Pair, Public, sr25519};
22
use runtime::{
33
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig,
4-
SudoConfig, IndicesConfig, SystemConfig, WASM_BINARY,
4+
SudoConfig, IndicesConfig, SystemConfig, WASM_BINARY, Signature
55
};
66
use aura_primitives::sr25519::{AuthorityId as AuraId};
77
use grandpa_primitives::{AuthorityId as GrandpaId};
88
use substrate_service;
9+
use sr_primitives::traits::{Verify, IdentifyAccount};
910

1011
// Note this is the URL for the telemetry server
1112
//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
@@ -31,8 +32,17 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu
3132
.public()
3233
}
3334

35+
type AccountPublic = <Signature as Verify>::Signer;
36+
37+
/// Helper function to generate an account ID from seed
38+
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId where
39+
AccountPublic: From<<TPublic::Pair as Pair>::Public>
40+
{
41+
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
42+
}
43+
3444
/// Helper function to generate an authority key for Aura
35-
pub fn get_authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
45+
pub fn get_authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
3646
(
3747
get_from_seed::<AuraId>(s),
3848
get_from_seed::<GrandpaId>(s),
@@ -49,12 +59,12 @@ impl Alternative {
4959
|| testnet_genesis(vec![
5060
get_authority_keys_from_seed("Alice"),
5161
],
52-
get_from_seed::<AccountId>("Alice"),
62+
get_account_id_from_seed::<sr25519::Public>("Alice"),
5363
vec![
54-
get_from_seed::<AccountId>("Alice"),
55-
get_from_seed::<AccountId>("Bob"),
56-
get_from_seed::<AccountId>("Alice//stash"),
57-
get_from_seed::<AccountId>("Bob//stash"),
64+
get_account_id_from_seed::<sr25519::Public>("Alice"),
65+
get_account_id_from_seed::<sr25519::Public>("Bob"),
66+
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
67+
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
5868
],
5969
true),
6070
vec![],
@@ -69,21 +79,21 @@ impl Alternative {
6979
|| testnet_genesis(vec![
7080
get_authority_keys_from_seed("Alice"),
7181
get_authority_keys_from_seed("Bob"),
72-
],
73-
get_from_seed::<AccountId>("Alice"),
82+
],
83+
get_account_id_from_seed::<sr25519::Public>("Alice"),
7484
vec![
75-
get_from_seed::<AccountId>("Alice"),
76-
get_from_seed::<AccountId>("Bob"),
77-
get_from_seed::<AccountId>("Charlie"),
78-
get_from_seed::<AccountId>("Dave"),
79-
get_from_seed::<AccountId>("Eve"),
80-
get_from_seed::<AccountId>("Ferdie"),
81-
get_from_seed::<AccountId>("Alice//stash"),
82-
get_from_seed::<AccountId>("Bob//stash"),
83-
get_from_seed::<AccountId>("Charlie//stash"),
84-
get_from_seed::<AccountId>("Dave//stash"),
85-
get_from_seed::<AccountId>("Eve//stash"),
86-
get_from_seed::<AccountId>("Ferdie//stash"),
85+
get_account_id_from_seed::<sr25519::Public>("Alice"),
86+
get_account_id_from_seed::<sr25519::Public>("Bob"),
87+
get_account_id_from_seed::<sr25519::Public>("Charlie"),
88+
get_account_id_from_seed::<sr25519::Public>("Dave"),
89+
get_account_id_from_seed::<sr25519::Public>("Eve"),
90+
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
91+
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
92+
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
93+
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
94+
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
95+
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
96+
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
8797
],
8898
true),
8999
vec![],
@@ -105,7 +115,7 @@ impl Alternative {
105115
}
106116

107117
fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,
108-
root_key: AccountId,
118+
root_key: AccountId,
109119
endowed_accounts: Vec<AccountId>,
110120
_enable_println: bool) -> GenesisConfig {
111121
GenesisConfig {

node-template/src/service.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use std::sync::Arc;
44
use std::time::Duration;
55
use substrate_client::LongestChain;
6-
use futures::prelude::*;
76
use runtime::{self, GenesisConfig, opaque::Block, RuntimeApi};
87
use substrate_service::{error::{Error as ServiceError}, AbstractService, Configuration, ServiceBuilder};
98
use transaction_pool::{self, txpool::{Pool as TransactionPool}};

node/cli/src/chain_spec.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ use substrate_telemetry::TelemetryEndpoints;
3232
use grandpa_primitives::{AuthorityId as GrandpaId};
3333
use babe_primitives::{AuthorityId as BabeId};
3434
use im_online::sr25519::{AuthorityId as ImOnlineId};
35-
use sr_primitives::{traits::Verify, Perbill};
35+
use sr_primitives::{Perbill, traits::{Verify, IdentifyAccount}};
3636

3737
pub use node_primitives::{AccountId, Balance, Signature};
3838
pub use node_runtime::GenesisConfig;
39-
use sr_primitives::traits::IdentifyAccount;
4039

4140
type AccountPublic = <Signature as Verify>::Signer;
4241

0 commit comments

Comments
 (0)