This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
chain-spec
: support for json
config/patch (and GenesisBuilder
API)
#14562
Open
michalkucharczyk
wants to merge
53
commits into
master
Choose a base branch
from
mku-chain-spec-support-for-genesis-builder-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
52d6a4f
frame::system: code removed
michalkucharczyk e333e16
chain-spec: mod genesis -> genesis_block
michalkucharczyk ea2e252
chain-spec: genesis_config_builder (wasm based)
michalkucharczyk b4f5267
chain-spec: support for code and config patching
michalkucharczyk baacd30
chain-spec: runtime caller added
michalkucharczyk b40193f
chain-spec: doc + minor improvements
michalkucharczyk dc6c927
chain-spec: set_code added
michalkucharczyk ae9b2a8
chain-spec-builder: from_genesis removed
michalkucharczyk e166fec
chain-spec-builder: boot_nodes call optional
michalkucharczyk c200e26
chain-spec-builder: support for runtime wasm blobs
michalkucharczyk e64b7d1
bin/node: GenesisBuilder implementation added
michalkucharczyk 5d450a4
bin/node-template: serde enabled in runtime deps
michalkucharczyk b945d4d
bin/node/runtime: arbitrary_precision feature added to serde_json
michalkucharczyk ae9415f
bin/node: fixes
michalkucharczyk 98a9a58
bin/node: from_genesis moved to ChainSpecBuilder
michalkucharczyk f49362e
bin/node: boot_nodes call optional
michalkucharczyk f62284d
bin/node: GenesisBuilder helper struct removed
michalkucharczyk 12dac2c
bin/node: frame_system::code removed
michalkucharczyk ab4ae6b
node-template: frame_system::code removed
michalkucharczyk fc55a8d
client/cli: from_genesis - code arg added
michalkucharczyk dbe0c8b
chain-spec: naming fixed
michalkucharczyk 01f10b9
node-template: ChainSpecBuilder used
michalkucharczyk 7015549
bin/node: ChainSpecBuilder used (tests)
michalkucharczyk 86ab3d3
cli/cmd/insert_key: ChainSpecBuilder used (tests)
michalkucharczyk 1418558
cli/runner: ChainSpecBuilder used (tests)
michalkucharczyk 2faefc1
ChainSpec: note corrected
michalkucharczyk ef29d30
Merge remote-tracking branch 'origin/master' into mku-chain-spec-supp…
michalkucharczyk fc1c393
chain-spec-builder: after-merge cleanup
michalkucharczyk 4e9732c
Merge remote-tracking branch 'origin/master' into mku-chain-spec-supp…
bbfabb5
Cargo.lock updated
michalkucharczyk ce2b20a
test-runtime: frame_system::code removed
michalkucharczyk b214805
node-bench: code addded to genesis storage
michalkucharczyk 1fd42a0
node-testing: code added to genesis storage
michalkucharczyk b77b45e
bin/node: executor test fix
michalkucharczyk a445c68
Merge remote-tracking branch 'origin/master' into mku-chain-spec-supp…
michalkucharczyk f869b0e
Cargo.lock updated
michalkucharczyk e41a161
chainspec::code field is better handled for raw specs
michalkucharczyk 991f9fa
code field improvements
michalkucharczyk 0258f52
doc + naming
michalkucharczyk 0215340
Merge remote-tracking branch 'origin/master' into mku-chain-spec-supp…
20bee68
doc improvements
michalkucharczyk 0bf081e
improvements
michalkucharczyk 67a77ad
test-runtime: json files moved to res dir
michalkucharczyk da79f96
Cargo.toml fixes
michalkucharczyk 2bd3fab
".git/.scripts/commands/fmt/fmt.sh"
d788003
Cargo.lock updated
michalkucharczyk 298305b
minor fixes
michalkucharczyk 97e5b1b
Apply suggestions from code review
michalkucharczyk 5f60a4b
cleanup
michalkucharczyk 0f58273
".git/.scripts/commands/fmt/fmt.sh"
1096d36
Merge remote-tracking branch 'origin/master' into mku-chain-spec-supp…
e1c7e11
removing unneeded refs to runtime PalletGenesisConfig types
michalkucharczyk fc33dfb
Merge branch 'master' into mku-chain-spec-support-for-genesis-builder…
michalkucharczyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
|
@@ -115,3 +118,6 @@ try-runtime = [ | |
"sp-runtime/try-runtime" | ||
] | ||
experimental = ["pallet-aura/experimental"] | ||
|
||
#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. missing newline before EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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()