Skip to content

Commit 9b29794

Browse files
committed
Merge branch 'release/0.6.0'
2 parents 8e13858 + 14aa858 commit 9b29794

File tree

12 files changed

+622
-62
lines changed

12 files changed

+622
-62
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@
1313
.local
1414

1515
release
16-
wasm
16+
wasm
17+
alice
18+
bob
19+
cic

Cargo.lock

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ homepage = 'https://mathwallet.net/mathchain'
77
license = 'Unlicense'
88
name = 'mathchain'
99
repository = 'https://github.com/mathwallet/MathChain/'
10-
version = '0.5.4'
10+
version = '0.6.0'
1111

1212
[package.metadata.docs.rs]
1313
targets = ['x86_64-unknown-linux-gnu']
@@ -24,6 +24,7 @@ log = "0.4.8"
2424
jsonrpc-core = '15.0.0'
2525
jsonrpc-pubsub = "15.0.0"
2626
structopt = '0.3.8'
27+
array-bytes = { version = "0.3.0" }
2728

2829
# local dependencies
2930
mathchain-runtime = { path = '../runtime', version = '0.1.0' }

node/res/galois.json

Lines changed: 93 additions & 48 deletions
Large diffs are not rendered by default.

node/src/chain_spec.rs

Lines changed: 156 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use sp_core::{Pair, Public, sr25519, U256, H160};
1+
use sp_core::{Pair, Public, sr25519, U256, H160, crypto::UncheckedInto,};
22
use mathchain_runtime::{
33
AccountId, AuraConfig, BalancesConfig, EVMConfig, EthereumConfig, GenesisConfig, GrandpaConfig,
4-
SudoConfig, SystemConfig, WASM_BINARY, Signature
4+
SudoConfig, SystemConfig, WASM_BINARY, Signature, ValidatorSetConfig, opaque::SessionKeys, SessionConfig
55
};
66
use mathchain_runtime::constants::currency::MATHS as MATH;
77

@@ -11,6 +11,7 @@ use sp_runtime::traits::{Verify, IdentifyAccount};
1111
use sc_service::{ChainType, Properties};
1212
use std::collections::BTreeMap;
1313
use std::str::FromStr;
14+
use sc_telemetry::TelemetryEndpoints;
1415

1516
const DEFAULT_PROTOCOL_ID: &str = "math";
1617

@@ -79,6 +80,145 @@ pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
7980
)
8081
}
8182

83+
fn session_keys(
84+
aura: AuraId,
85+
grandpa: GrandpaId,
86+
) -> SessionKeys {
87+
SessionKeys { aura, grandpa }
88+
}
89+
90+
pub fn get_authority_keys_from_seed(seed: &str) -> (
91+
AccountId,
92+
AuraId,
93+
GrandpaId
94+
) {
95+
(
96+
get_account_id_from_seed::<sr25519::Public>(seed),
97+
get_from_seed::<AuraId>(seed),
98+
get_from_seed::<GrandpaId>(seed)
99+
)
100+
}
101+
102+
pub fn galois_for_genesis() -> Result<ChainSpec, String> {
103+
let wasm_binary = WASM_BINARY.ok_or_else(|| "Galois wasm not available".to_string())?;
104+
105+
const ROOT: &'static str = "0x24a80b84d2d5130beafcb2b1a3b1a0e0e1cee122ef0e508d6b1eb862b802fe1d";
106+
let root: AccountId = array_bytes::hex_str_array_unchecked!(ROOT, 32).into();
107+
108+
const GENESIS_VALIDATOR_SR1: &'static str =
109+
"0xf88768150c3a86509384e744132b5323390c6c24ddccbe39468865db7c07d842";
110+
const GENESIS_VALIDATOR_ED1: &'static str =
111+
"0x490c6732f48ae1ce0e0208d53776e7b0153713fce99e5a0c36731fd4da761450";
112+
113+
const GENESIS_VALIDATOR_SR2: &'static str =
114+
"0xa2e1437ba4d59fc44ee774fab33a06d952527e909e35ef64dc91859bbb60fe65";
115+
const GENESIS_VALIDATOR_ED2: &'static str =
116+
"0xa2e1437ba4d59fc44ee774fab33a06d952527e909e35ef64dc91859bbb60fe65";
117+
118+
const GENESIS_VALIDATOR_SR3: &'static str =
119+
"0xbca164498a1bc44c91e20a64c83431592a9caa7aa509e0ba5d1fc5710b524557";
120+
const GENESIS_VALIDATOR_ED3: &'static str =
121+
"0xf350c893e43dafe5d0e1c572673666b3d414057c0d117b476fcac5f777e627f2";
122+
123+
let genesis_validator1: (
124+
AccountId,
125+
AuraId,
126+
GrandpaId,
127+
) = {
128+
let stash = array_bytes::hex_str_array_unchecked!(GENESIS_VALIDATOR_SR1, 32);
129+
let session = array_bytes::hex_str_array_unchecked!(GENESIS_VALIDATOR_SR1, 32);
130+
let grandpa = array_bytes::hex_str_array_unchecked!(GENESIS_VALIDATOR_ED1, 32);
131+
132+
(
133+
stash.into(),
134+
session.unchecked_into(),
135+
grandpa.unchecked_into(),
136+
)
137+
};
138+
139+
let genesis_validator2: (
140+
AccountId,
141+
AuraId,
142+
GrandpaId,
143+
) = {
144+
let stash = array_bytes::hex_str_array_unchecked!(GENESIS_VALIDATOR_SR2, 32);
145+
let session = array_bytes::hex_str_array_unchecked!(GENESIS_VALIDATOR_SR2, 32);
146+
let grandpa = array_bytes::hex_str_array_unchecked!(GENESIS_VALIDATOR_ED2, 32);
147+
148+
(
149+
stash.into(),
150+
session.unchecked_into(),
151+
grandpa.unchecked_into(),
152+
)
153+
};
154+
155+
let genesis_validator3: (
156+
AccountId,
157+
AuraId,
158+
GrandpaId,
159+
) = {
160+
let stash = array_bytes::hex_str_array_unchecked!(GENESIS_VALIDATOR_SR3, 32);
161+
let session = array_bytes::hex_str_array_unchecked!(GENESIS_VALIDATOR_SR3, 32);
162+
let grandpa = array_bytes::hex_str_array_unchecked!(GENESIS_VALIDATOR_ED3, 32);
163+
164+
(
165+
stash.into(),
166+
session.unchecked_into(),
167+
grandpa.unchecked_into(),
168+
)
169+
};
170+
171+
let endowed_accounts = [
172+
// Sudo
173+
"0x24a80b84d2d5130beafcb2b1a3b1a0e0e1cee122ef0e508d6b1eb862b802fe1d",
174+
// node1
175+
"0xf88768150c3a86509384e744132b5323390c6c24ddccbe39468865db7c07d842",
176+
// node2
177+
"0xa2e1437ba4d59fc44ee774fab33a06d952527e909e35ef64dc91859bbb60fe65",
178+
// node3
179+
"0xbca164498a1bc44c91e20a64c83431592a9caa7aa509e0ba5d1fc5710b524557"
180+
]
181+
.iter()
182+
.map(|s| array_bytes::hex_str_array_unchecked!(s, 32).into())
183+
.collect::<Vec<_>>();
184+
185+
Ok(ChainSpec::from_genesis(
186+
// Name
187+
"Galois",
188+
"galois",
189+
ChainType::Live,
190+
move || testnet_genesis(
191+
wasm_binary,
192+
// Initial Poa authorities
193+
vec![
194+
genesis_validator1.clone(),
195+
genesis_validator2.clone(),
196+
genesis_validator3.clone(),
197+
],
198+
root.clone(),
199+
endowed_accounts.clone(),
200+
true
201+
),
202+
vec![
203+
"/ip4/47.111.168.132/tcp/3031/p2p/12D3KooWNMtGp5TQGApApAoPj37QHXSCv1Yi4mkZvVnse2A5wQZK".parse().unwrap(),
204+
"/ip4/8.209.214.249/tcp/3033/p2p/12D3KooWG2QSh8hKp1Bm4XuidjFijKZcHY9Q7my4fBJfJTqWj4Xd".parse().unwrap()
205+
],
206+
Some(
207+
TelemetryEndpoints::new(vec![
208+
("/dns4/telemetry.polkadot.io/tcp/443/x-parity-wss/%2Fsubmit%2F".parse().unwrap(), 0),
209+
("/dns4/telemetry.maiziqianbao.net/tcp/443/x-parity-wss/%2Fsubmit%2F".parse().unwrap(), 0),
210+
("/dns4/telemetry.maiziqianbao.vip/tcp/443/x-parity-wss/%2Fsubmit%2F".parse().unwrap(), 0),
211+
]).expect("Galois telemetry url is valid; qed")
212+
),
213+
// Protocol ID
214+
Some(DEFAULT_PROTOCOL_ID),
215+
// Properties
216+
Some(math_testnet_properties()),
217+
// Extensions
218+
None
219+
))
220+
}
221+
82222
pub fn development_config() -> Result<ChainSpec, String> {
83223
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
84224

@@ -92,7 +232,7 @@ pub fn development_config() -> Result<ChainSpec, String> {
92232
wasm_binary,
93233
// Initial PoA authorities
94234
vec![
95-
authority_keys_from_seed("Alice"),
235+
get_authority_keys_from_seed("Alice"),
96236
],
97237
// Sudo account
98238
get_account_id_from_seed::<sr25519::Public>("Alice"),
@@ -131,8 +271,8 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
131271
wasm_binary,
132272
// Initial PoA authorities
133273
vec![
134-
authority_keys_from_seed("Alice"),
135-
authority_keys_from_seed("Bob"),
274+
get_authority_keys_from_seed("Alice"),
275+
get_authority_keys_from_seed("Bob"),
136276
],
137277
// Sudo account
138278
get_account_id_from_seed::<sr25519::Public>("Alice"),
@@ -169,7 +309,7 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
169309
/// Configure initial storage state for FRAME modules.
170310
fn testnet_genesis(
171311
wasm_binary: &[u8],
172-
initial_authorities: Vec<(AuraId, GrandpaId)>,
312+
initial_authorities: Vec<(AccountId, AuraId, GrandpaId)>,
173313
root_key: AccountId,
174314
endowed_accounts: Vec<AccountId>,
175315
_enable_println: bool,
@@ -197,10 +337,10 @@ fn testnet_genesis(
197337
balances: endowed_accounts.iter().cloned().map(|k|(k, 10000 * MATH)).collect(),
198338
},
199339
pallet_aura: AuraConfig {
200-
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
340+
authorities: vec![],
201341
},
202342
pallet_grandpa: GrandpaConfig {
203-
authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),
343+
authorities: vec![],
204344
},
205345
pallet_sudo: SudoConfig {
206346
// Assign network admin rights.
@@ -210,5 +350,13 @@ fn testnet_genesis(
210350
accounts: evm_accounts,
211351
},
212352
pallet_ethereum: EthereumConfig {},
353+
pallet_validator_set: ValidatorSetConfig {
354+
validators: initial_authorities.iter().map(|x| x.0.clone()).collect::<Vec<_>>(),
355+
},
356+
pallet_session: SessionConfig {
357+
keys: initial_authorities.iter().map(|x| {
358+
(x.0.clone(), x.0.clone(), session_keys(x.1.clone(), x.2.clone()))
359+
}).collect::<Vec<_>>(),
360+
},
213361
}
214362
}

node/src/cli.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,7 @@ pub enum Subcommand {
6262
/// The custom benchmark subcommmand benchmarking runtime pallets.
6363
#[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]
6464
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
65+
66+
/// Key management cli utilities
67+
Key(sc_cli::KeySubcommand),
6568
}

node/src/command.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ impl SubstrateCli for Cli {
5858
// "galois_genesis" => Box::new(chain_spec::galois_build_spec_genesis()?),
5959
"" | "local" => Box::new(chain_spec::local_testnet_config()?),
6060
"galois" => Box::new(chain_spec::galois_config()?),
61+
"galois_for_genesis" => Box::new(chain_spec::galois_for_genesis()?),
6162
path => Box::new(chain_spec::ChainSpec::from_json_file(
6263
std::path::PathBuf::from(path),
6364
)?),
@@ -134,6 +135,7 @@ pub fn run() -> sc_cli::Result<()> {
134135
Ok((cmd.run(client, backend), task_manager))
135136
})
136137
},
138+
Some(Subcommand::Key(cmd)) => Ok(cmd.run(&cli)?),
137139
Some(Subcommand::Benchmark(cmd)) => {
138140
if cfg!(feature = "runtime-benchmarks") {
139141
let runner = cli.create_runner(cmd)?;

pallets/validator-set/Cargo.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[package]
2+
name = "pallet-validator-set"
3+
version = "0.2.0"
4+
authors = ["gautamdhameja"]
5+
edition = "2018"
6+
7+
[features]
8+
default = ['std']
9+
std = [
10+
'codec/std',
11+
'sp-std/std',
12+
'sp-runtime/std',
13+
'frame-support/std',
14+
'sp-core/std',
15+
'sp-io/std',
16+
'serde',
17+
'frame-system/std',
18+
'pallet-session/std'
19+
]
20+
21+
[dependencies.codec]
22+
default-features = false
23+
features = ['derive']
24+
package = 'parity-scale-codec'
25+
version = '2.0.1'
26+
27+
[dependencies]
28+
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
29+
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
30+
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
31+
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
32+
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
33+
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
34+
pallet-session = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
35+
serde = { features = ['derive'], optional = true, version = '1.0.101'}

0 commit comments

Comments
 (0)