Skip to content

Commit d233fa6

Browse files
authored
bootstrap, chainspec: Make network-id modular (#651)
Signed-off-by: Shreevatsa N <vatsa@dhiway.com>
1 parent 3404d90 commit d233fa6

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

node/cli/src/chain_spec/bootstrap.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub struct ChainParams {
5757
pub council_members: Vec<String>,
5858
pub tech_committee_members: Vec<String>,
5959
pub sudo_key: String,
60+
pub network_id: i32,
6061
}
6162

6263
impl ChainParams {
@@ -159,6 +160,7 @@ fn cord_braid_custom_config_genesis(config: ChainParams) -> serde_json::Value {
159160
initial_well_known_nodes,
160161
initial_authorities,
161162
initial_sudo_key,
163+
config.network_id,
162164
)
163165
}
164166

@@ -189,7 +191,7 @@ fn cord_loom_custom_config_genesis(config: ChainParams) -> serde_json::Value {
189191

190192
let initial_sudo_key: AccountId = array_bytes::hex_n_into_unchecked(&config.authorities[0][0]);
191193

192-
cord_loom_custom_genesis(initial_authorities, initial_sudo_key)
194+
cord_loom_custom_genesis(initial_authorities, initial_sudo_key, config.network_id)
193195
}
194196

195197
fn cord_weave_custom_config_genesis(config: ChainParams) -> serde_json::Value {
@@ -219,7 +221,7 @@ fn cord_weave_custom_config_genesis(config: ChainParams) -> serde_json::Value {
219221

220222
let initial_sudo_key: AccountId = array_bytes::hex_n_into_unchecked(&config.authorities[0][0]);
221223

222-
cord_weave_custom_genesis(initial_authorities, initial_sudo_key)
224+
cord_weave_custom_genesis(initial_authorities, initial_sudo_key, config.network_id)
223225
}
224226

225227
pub fn cord_custom_config(config: ChainParams) -> Result<CordChainSpec, String> {
@@ -299,12 +301,14 @@ fn cord_braid_custom_genesis(
299301
BeefyId,
300302
)>,
301303
root_key: AccountId,
304+
network_id: i32,
302305
) -> serde_json::Value {
303306
serde_json::json!( {
304307
"balances": {
305308
"balances": initial_authorities.iter().map(|k| (k.0.clone(), ENDOWMENT)).collect::<Vec<_>>(),
306309
},
307-
"doken": { "networkId": 2003},
310+
/* TODO: Make the protocolId modular as well, to support origin chains */
311+
"doken": { "protocolId": "c0rd".to_string(), "networkId": network_id },
308312
"nodeAuthorization": {
309313
"nodes": initial_well_known_nodes.iter().map(|x| (x.0.clone(), x.1.clone())).collect::<Vec<_>>(),
310314
},
@@ -353,12 +357,14 @@ fn cord_loom_custom_genesis(
353357
BeefyId,
354358
)>,
355359
root_key: AccountId,
360+
network_id: i32,
356361
) -> serde_json::Value {
357362
serde_json::json!( {
358363
"balances": {
359364
"balances": initial_authorities.iter().map(|k| (k.0.clone(), ENDOWMENT)).collect::<Vec<_>>(),
360365
},
361-
"doken": { "networkId": 2002},
366+
/* TODO: Make the protocolId modular as well, to support origin chains */
367+
"doken": { "protocolId": "c0rd".to_string(), "networkId": network_id },
362368
"authorityMembership": {
363369
"initialAuthorities": initial_authorities
364370
.iter()
@@ -413,12 +419,14 @@ fn cord_weave_custom_genesis(
413419
BeefyId,
414420
)>,
415421
root_key: AccountId,
422+
network_id: i32,
416423
) -> serde_json::Value {
417424
serde_json::json!( {
418425
"balances": {
419426
"balances": initial_authorities.iter().map(|k| (k.0.clone(), ENDOWMENT)).collect::<Vec<_>>(),
420427
},
421-
"doken": { "networkId": 2001},
428+
/* TODO: Make the protocolId modular as well, to support origin chains */
429+
"doken": { "protocolId": "c0rd".to_string(), "networkId": network_id },
422430
"session": {
423431
"keys": initial_authorities
424432
.iter()

node/cli/src/command/chain_setup.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct ChainConfigParams {
4040
pub council_members: Option<Vec<String>>,
4141
pub tech_committee_members: Option<Vec<String>>,
4242
pub sudo_key: Option<String>,
43+
pub network_id: i32,
4344
}
4445

4546
#[derive(Debug, Args)]
@@ -140,6 +141,12 @@ impl BootstrapChainCmd {
140141
.expect("No authorities provided; cannot set sudo_key")
141142
});
142143

144+
/* TODO: Make ProtocolId modular so we can support for Origin based custom chain
145+
* deployments. Currently we have the default protocol_id as 'c0rd' which is standalone
146+
* mode & it requires the network-id to be in range of [100, 1999)
147+
*/
148+
let network_id: i32 = config.network_id;
149+
143150
let chain_params = ChainParams {
144151
chain_name,
145152
chain_type,
@@ -150,6 +157,7 @@ impl BootstrapChainCmd {
150157
council_members: initial_council_members,
151158
tech_committee_members: initial_tech_committee_members,
152159
sudo_key: initial_sudo_key,
160+
network_id,
153161
};
154162

155163
let chain_spec = match cord_custom_config(chain_params) {

scripts/bootstrap.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function usage() {
1111
echo " -s, --SECRET Secret key or seed for generating new accounts"
1212
echo " -r, --runtime-type Choose one of chain runtimes from braid, loom and weave. Default is loom."
1313
echo " -o, --output-directory Directory where output files will be saved (default is current directory)"
14+
echo " -i, --network-id Network ID of the bootstraped chain"
1415
echo ""
1516
echo "Description:"
1617
echo " This script generates a configuration file for the CORD Custom Chain, including"
@@ -29,8 +30,9 @@ NUM_AUTHORITIES=3
2930
SECRET="0xf32255f569d8b1a12086dfd194653a5377fafcb67345753987741ec5542920ce"
3031
OUTPUT_DIR="."
3132
RUNTIME_TYPE="loom"
33+
NETWORK_ID=105
3234

33-
while getopts "m:n:a:s:r:o:" flag; do
35+
while getopts "m:n:a:s:r:o:i:" flag; do
3436
case "${flag}" in
3537
m) NUM_MEMBERS=${OPTARG} ;;
3638
n) NUM_NODES=${OPTARG} ;;
@@ -45,6 +47,7 @@ while getopts "m:n:a:s:r:o:" flag; do
4547
fi
4648
;;
4749
o) OUTPUT_DIR=${OPTARG} ;;
50+
i) NETWORKD_ID=${OPTARG} ;;
4851
*)
4952
usage
5053
exit 1
@@ -67,6 +70,8 @@ echo "
6770
echo "chain_name = \"CORD Custom Chain\"" >>$CONFIG_FILE
6871
echo "chain_type = \"local\"" >>$CONFIG_FILE
6972
echo "runtime_type = \"${RUNTIME_TYPE}\"" >>$CONFIG_FILE
73+
echo "network_id = \"${NETWORK_ID}\"" >>$CONFIG_FILE
74+
7075
echo "" >>$CONFIG_FILE
7176

7277
# Initialize Accounts files

0 commit comments

Comments
 (0)