-
Notifications
You must be signed in to change notification settings - Fork 2.6k
chain-spec
: support for json
config/patch (and GenesisBuilder
API)
#14562
base: master
Are you sure you want to change the base?
Changes from 47 commits
52d6a4f
e333e16
ea2e252
b4f5267
baacd30
b40193f
dc6c927
ae9b2a8
e166fec
c200e26
e64b7d1
5d450a4
b945d4d
ae9415f
98a9a58
f49362e
f62284d
12dac2c
ab4ae6b
fc55a8d
dbe0c8b
01f10b9
7015549
86ab3d3
1418558
2faefc1
ef29d30
fc1c393
4e9732c
bbfabb5
ce2b20a
b214805
1fd42a0
b77b45e
a445c68
f869b0e
e41a161
991f9fa
0258f52
0215340
20bee68
0bf081e
67a77ad
da79f96
2bd3fab
d788003
298305b
97e5b1b
5f60a4b
0f58273
1096d36
e1c7e11
fc33dfb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
use node_template_runtime::{ | ||
AccountId, AuraConfig, BalancesConfig, GrandpaConfig, RuntimeGenesisConfig, Signature, | ||
SudoConfig, SystemConfig, WASM_BINARY, | ||
}; | ||
use node_template_runtime::{AccountId, RuntimeGenesisConfig, Signature, WASM_BINARY}; | ||
use sc_service::ChainType; | ||
use sp_consensus_aura::sr25519::AuthorityId as AuraId; | ||
use sp_consensus_grandpa::AuthorityId as GrandpaId; | ||
|
@@ -37,122 +34,82 @@ pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) { | |
} | ||
|
||
pub fn development_config() -> Result<ChainSpec, String> { | ||
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; | ||
|
||
Ok(ChainSpec::from_genesis( | ||
// Name | ||
"Development", | ||
// ID | ||
"dev", | ||
ChainType::Development, | ||
move || { | ||
testnet_genesis( | ||
wasm_binary, | ||
// Initial PoA authorities | ||
vec![authority_keys_from_seed("Alice")], | ||
// Sudo account | ||
Ok(ChainSpec::builder() | ||
.with_name("Development") | ||
.with_id("dev") | ||
.with_chain_type(ChainType::Development) | ||
.with_extensions(None) | ||
.with_code(WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?) | ||
.with_genesis_config_patch(testnet_genesis( | ||
// Initial PoA authorities | ||
vec![authority_keys_from_seed("Alice")], | ||
// Sudo account | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
// Pre-funded accounts | ||
vec![ | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
// Pre-funded accounts | ||
vec![ | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
get_account_id_from_seed::<sr25519::Public>("Bob"), | ||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"), | ||
], | ||
true, | ||
) | ||
}, | ||
// Bootnodes | ||
vec![], | ||
// Telemetry | ||
None, | ||
// Protocol ID | ||
None, | ||
None, | ||
// Properties | ||
None, | ||
// Extensions | ||
None, | ||
)) | ||
get_account_id_from_seed::<sr25519::Public>("Bob"), | ||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"), | ||
], | ||
true, | ||
)) | ||
.build()) | ||
} | ||
|
||
pub fn local_testnet_config() -> Result<ChainSpec, String> { | ||
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; | ||
|
||
Ok(ChainSpec::from_genesis( | ||
// Name | ||
"Local Testnet", | ||
// ID | ||
"local_testnet", | ||
ChainType::Local, | ||
move || { | ||
testnet_genesis( | ||
wasm_binary, | ||
// Initial PoA authorities | ||
vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], | ||
// Sudo account | ||
Ok(ChainSpec::builder() | ||
.with_name("Local Testnet") | ||
.with_id("local_testnet") | ||
.with_chain_type(ChainType::Local) | ||
.with_extensions(None) | ||
.with_code(WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?) | ||
.with_genesis_config_patch(testnet_genesis( | ||
// Initial PoA authorities | ||
vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], | ||
// Sudo account | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
// Pre-funded accounts | ||
vec![ | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
// Pre-funded accounts | ||
vec![ | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
get_account_id_from_seed::<sr25519::Public>("Bob"), | ||
get_account_id_from_seed::<sr25519::Public>("Charlie"), | ||
get_account_id_from_seed::<sr25519::Public>("Dave"), | ||
get_account_id_from_seed::<sr25519::Public>("Eve"), | ||
get_account_id_from_seed::<sr25519::Public>("Ferdie"), | ||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Dave//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Eve//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"), | ||
], | ||
true, | ||
) | ||
}, | ||
// Bootnodes | ||
vec![], | ||
// Telemetry | ||
None, | ||
// Protocol ID | ||
None, | ||
// Properties | ||
None, | ||
None, | ||
// Extensions | ||
None, | ||
)) | ||
get_account_id_from_seed::<sr25519::Public>("Bob"), | ||
get_account_id_from_seed::<sr25519::Public>("Charlie"), | ||
get_account_id_from_seed::<sr25519::Public>("Dave"), | ||
get_account_id_from_seed::<sr25519::Public>("Eve"), | ||
get_account_id_from_seed::<sr25519::Public>("Ferdie"), | ||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Dave//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Eve//stash"), | ||
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"), | ||
], | ||
true, | ||
)) | ||
.build()) | ||
} | ||
|
||
/// Configure initial storage state for FRAME modules. | ||
fn testnet_genesis( | ||
wasm_binary: &[u8], | ||
initial_authorities: Vec<(AuraId, GrandpaId)>, | ||
root_key: AccountId, | ||
endowed_accounts: Vec<AccountId>, | ||
_enable_println: bool, | ||
) -> RuntimeGenesisConfig { | ||
RuntimeGenesisConfig { | ||
system: SystemConfig { | ||
// Add Wasm runtime to storage. | ||
code: wasm_binary.to_vec(), | ||
..Default::default() | ||
}, | ||
balances: BalancesConfig { | ||
) -> serde_json::Value { | ||
serde_json::json!({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By using (Maybe I'm going to say something stupid, not 100% confident with metadata) but isn't possible to have some sanity check using the runtime metadata? |
||
"balances": { | ||
// Configure endowed accounts with initial balance of 1 << 60. | ||
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), | ||
"balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::<Vec<_>>(), | ||
}, | ||
aura: AuraConfig { | ||
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(), | ||
"aura": { | ||
"authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>(), | ||
}, | ||
grandpa: GrandpaConfig { | ||
authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(), | ||
..Default::default() | ||
"grandpa": { | ||
"authorities": initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::<Vec<_>>(), | ||
}, | ||
sudo: SudoConfig { | ||
"sudo": { | ||
// Assign network admin rights. | ||
key: Some(root_key), | ||
"key": Some(root_key), | ||
}, | ||
transaction_payment: Default::default(), | ||
} | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"] | |
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } | ||
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } | ||
|
||
scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde"] } | ||
pallet-aura = { version = "4.0.0-dev", default-features = false, path = "../../../frame/aura" } | ||
pallet-balances = { version = "4.0.0-dev", default-features = false, path = "../../../frame/balances" } | ||
frame-support = { version = "4.0.0-dev", default-features = false, path = "../../../frame/support" } | ||
|
@@ -28,16 +27,18 @@ pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, | |
frame-executive = { version = "4.0.0-dev", default-features = false, path = "../../../frame/executive" } | ||
sp-api = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/api" } | ||
sp-block-builder = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/block-builder"} | ||
sp-consensus-aura = { version = "0.10.0-dev", default-features = false, path = "../../../primitives/consensus/aura" } | ||
sp-consensus-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/consensus/grandpa" } | ||
sp-core = { version = "21.0.0", default-features = false, path = "../../../primitives/core" } | ||
sp-consensus-aura = { version = "0.10.0-dev", default-features = false, path = "../../../primitives/consensus/aura", features = ["serde"] } | ||
sp-consensus-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/consensus/grandpa", features = ["serde"] } | ||
sp-core = { version = "21.0.0", default-features = false, path = "../../../primitives/core", features=["serde"] } | ||
sp-inherents = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/inherents"} | ||
sp-offchain = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/offchain" } | ||
sp-runtime = { version = "24.0.0", default-features = false, path = "../../../primitives/runtime" } | ||
sp-runtime = { version = "24.0.0", default-features = false, path = "../../../primitives/runtime", features = ["serde"] } | ||
sp-session = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/session" } | ||
sp-std = { version = "8.0.0", default-features = false, path = "../../../primitives/std" } | ||
sp-transaction-pool = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/transaction-pool" } | ||
sp-version = { version = "22.0.0", default-features = false, path = "../../../primitives/version" } | ||
sp-version = { version = "22.0.0", default-features = false, path = "../../../primitives/version", features=["serde"] } | ||
serde_json = { version = "1.0.85", default-features = false, features = ["alloc"] } | ||
sp-genesis-builder = { version = "0.1.0-dev", default-features = false, path = "../../../primitives/genesis-builder" } | ||
|
||
# Used for the node template's RPCs | ||
frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, path = "../../../frame/system/rpc/runtime-api/" } | ||
|
@@ -87,6 +88,8 @@ std = [ | |
"sp-transaction-pool/std", | ||
"sp-version/std", | ||
"substrate-wasm-builder", | ||
"serde_json/std", | ||
"sp-genesis-builder/std", | ||
] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
|
@@ -113,3 +116,6 @@ try-runtime = [ | |
"pallet-timestamp/try-runtime", | ||
"pallet-transaction-payment/try-runtime", | ||
] | ||
|
||
#Enabling this flag will disable GenesisBuilder API implementation in runtime. | ||
disable-genesis-builder = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just an idea to open a discussion (not saying this is better). What about instead using a feature called Then define |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really related (feel free to ignore), but I'd rename the functions retuning the
ChainSpec
with something likedevelopment_chain_spec()