Skip to content

Commit

Permalink
Merge pull request #16 from 3ierratango/remove-qp-config-genesis
Browse files Browse the repository at this point in the history
[feat] Remove qp config from genesis
  • Loading branch information
naiemk committed Jan 18, 2023
2 parents f680ea5 + 783c7aa commit c0f14c7
Show file tree
Hide file tree
Showing 18 changed files with 281 additions and 183 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ rls*.log
.cargo-remote.toml
*.bin
*.iml
/chain
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions alice_node_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"networks": {
"network_vec": [{
"url": "https://rpc-mumbai.maticvigil.com/",
"ledger_manager": "A8B001Ff4191F5e0D6b5DD15b8D466d8546d214b",
"id": 80001
},
{
"url": "https://data-seed-prebsc-1-s1.binance.org:8545",
"ledger_manager": "A8B001Ff4191F5e0D6b5DD15b8D466d8546d214b",
"id": 97
}],
"pair_vec": [[80001, 97], [97, 80001]],
"signer_public_key": "020a1091341fe5664bfa1782d5e04779689068c916b04cb365ec3153755684d9a1",
"authority_manager_contract_name" : "FERRUM_QUANTUM_PORTAL_AUTHORITY_MGR",
"authority_manager_contract_version" : "000.010",
"authority_manager_contract_address" : "7cD4f4B67A2cB13f46E70b37F79da1942572029E",
"role" : "QP_MINER"
}
}
20 changes: 20 additions & 0 deletions bob_node_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"networks": {
"network_vec": [{
"url": "https://rpc-mumbai.maticvigil.com/",
"ledger_manager": "A8B001Ff4191F5e0D6b5DD15b8D466d8546d214b",
"id": 80001
},
{
"url": "https://data-seed-prebsc-1-s1.binance.org:8545",
"ledger_manager": "A8B001Ff4191F5e0D6b5DD15b8D466d8546d214b",
"id": 97
}],
"pair_vec": [[80001, 97], [97, 80001]],
"signer_public_key": "0390084fdbf27d2b79d26a4f13f0ccd982cb755a661969143c37cbc49ef5b91f27",
"authority_manager_contract_name" : "FERRUM_QUANTUM_PORTAL_AUTHORITY_MGR",
"authority_manager_contract_version" : "000.010",
"authority_manager_contract_address" : "7cD4f4B67A2cB13f46E70b37F79da1942572029E",
"role" : "QP_MINER"
}
}
18 changes: 6 additions & 12 deletions default_dev_config.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
{
"chain_spec": {
"initial_authourity_seed_list": ["Alice"],
"root_seed": "e04cc55ebee1cbce552f250e85c57b70b2e2625b",
"endowed_accounts_seed_list": ["e04cc55ebee1cbce552f250e85c57b70b2e2625b"],
"address_list": ["d43593c715fdd31c61141abd04a99fd6822c8558", "6be02d1d3665660d22ff9624b7be0551ee1ac91b", "0bdb79846e8331a19a65430363f240ec8acc2a52","467502ef1c444f98349dacdf0223ccb5e2019f36"],
"offchain_signer_secret_seed" : "//Alice"
},
"networks": {
"network_vec": [{
"url": "https://rpc-mumbai.maticvigil.com/",
"ledger_manager": "1dC011A64112fc8a2928E2EFe60007ef0F705ED9",
"ledger_manager": "A8B001Ff4191F5e0D6b5DD15b8D466d8546d214b",
"id": 80001
},
{
"url": "https://data-seed-prebsc-1-s1.binance.org:8545",
"ledger_manager": "1dC011A64112fc8a2928E2EFe60007ef0F705ED9",
"ledger_manager": "A8B001Ff4191F5e0D6b5DD15b8D466d8546d214b",
"id": 97
}],
"pair_vec": [[80001, 97], [97, 80001]],
"signer_public_key": "020a1091341fe5664bfa1782d5e04779689068c916b04cb365ec3153755684d9a1",
"signer_public_key": "0390084fdbf27d2b79d26a4f13f0ccd982cb755a661969143c37cbc49ef5b91f27",
"authority_manager_contract_name" : "FERRUM_QUANTUM_PORTAL_AUTHORITY_MGR",
"authority_manager_contract_version" : "000.010",
"authority_manager_contract_address" : "948d09CbC3E260Ed408C70027310d1ca4a42153B"
"authority_manager_contract_address" : "7cD4f4B67A2cB13f46E70b37F79da1942572029E",
"role" : "QP_MINER"
}
}
}
58 changes: 58 additions & 0 deletions ferrum-local-testnet.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_bytes = "0.11"
serde_json = "1.0"
libsecp256k1 = { version = "0.7.0", default-features = false, features = ['static-context'] }
bincode = "1.3.3"

# Parity
codec = { package = "parity-scale-codec", version = "3.2.1", features = ["derive"] }
Expand Down
95 changes: 14 additions & 81 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ use crate::{
config::{convert, Config, NetworkConfig},
};

const DEFAULT_DEV_PATH_BUF: &str = "./default_dev_config.json";
const DEFAULT_LOCAL_TESTNET_PATH_BUF: &str = "./default_dev_config.json";

// The URL for the telemetry server.
// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";

Expand All @@ -50,65 +47,9 @@ pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
(get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))
}

pub fn config_path_buf(cli: &Cli, dev: bool) -> PathBuf {
if let Some(local_path_buf) = cli.run.config_file_path.clone() {
local_path_buf
} else if dev {
PathBuf::from(DEFAULT_DEV_PATH_BUF)
} else {
PathBuf::from(DEFAULT_LOCAL_TESTNET_PATH_BUF)
}
}

pub fn config_elem(cli: &Cli, dev: bool) -> Result<Config, String> {
let path_buf = config_path_buf(cli, dev);

crate::config::read_config_from_file(path_buf)
}

pub fn chainspec_params(
config_elem: Config,
) -> Result<
(
Vec<(AuraId, GrandpaId)>,
AccountId,
Vec<AccountId>,
Vec<String>,
),
String,
> {
let chain_spec_config = config_elem.chain_spec;
let address_list = chain_spec_config.address_list.clone();
let initial_authoutities: Vec<_> = chain_spec_config
.initial_authourity_seed_list
.into_iter()
.map(|seed| authority_keys_from_seed(&seed))
.collect();
let root_key = AccountId::from_str(chain_spec_config.root_seed.as_str()).unwrap();
let endowed_accounts: Vec<AccountId> = chain_spec_config
.endowed_accounts_seed_list
.into_iter()
.map(|_seed| AccountId::from_str(chain_spec_config.root_seed.as_str()).unwrap())
.collect();

Ok((
initial_authoutities,
root_key,
endowed_accounts,
address_list,
))
}

pub fn development_config(cli: &Cli) -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

let config_elem = config_elem(cli, true)?;

let networks = config_elem.networks.clone();

let (initial_authoutities, root_key, endowed_accounts, address_list) =
chainspec_params(config_elem)?;

Ok(ChainSpec::from_genesis(
// Name
"Ferrum X Development",
Expand All @@ -119,13 +60,15 @@ pub fn development_config(cli: &Cli) -> Result<ChainSpec, String> {
testnet_genesis(
wasm_binary,
// Initial PoA authorities
initial_authoutities.clone(),
vec![
authority_keys_from_seed("Alice"),
authority_keys_from_seed("Bob"),
],
// Sudo account
root_key,
AccountId::from_str("e04cc55ebee1cbce552f250e85c57b70b2e2625b").unwrap(),
// Pre-funded accounts
endowed_accounts.clone(),
address_list.clone(),
networks.clone(),
vec![AccountId::from_str("e04cc55ebee1cbce552f250e85c57b70b2e2625b").unwrap()],
vec![],
true,
)
},
Expand All @@ -145,14 +88,6 @@ pub fn development_config(cli: &Cli) -> Result<ChainSpec, String> {

pub fn local_testnet_config(cli: &Cli) -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

let config_elem = config_elem(cli, false)?;

let networks = config_elem.networks.clone();

let (initial_authoutities, root_key, endowed_accounts, address_list) =
chainspec_params(config_elem)?;

Ok(ChainSpec::from_genesis(
// Name
"Ferrum X Local Testnet",
Expand All @@ -163,13 +98,15 @@ pub fn local_testnet_config(cli: &Cli) -> Result<ChainSpec, String> {
testnet_genesis(
wasm_binary,
// Initial PoA authorities
initial_authoutities.clone(),
vec![
authority_keys_from_seed("Alice"),
authority_keys_from_seed("Bob"),
],
// Sudo account
root_key,
AccountId::from_str("e04cc55ebee1cbce552f250e85c57b70b2e2625b").unwrap(),
// Pre-funded accounts
endowed_accounts.clone(),
address_list.clone(),
networks.clone(),
vec![AccountId::from_str("e04cc55ebee1cbce552f250e85c57b70b2e2625b").unwrap()],
vec![],
true,
)
},
Expand All @@ -194,7 +131,6 @@ fn testnet_genesis(
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
address_list: Vec<String>,
networks: NetworkConfig,
_enable_println: bool,
) -> GenesisConfig {
GenesisConfig {
Expand Down Expand Up @@ -246,8 +182,5 @@ fn testnet_genesis(
ethereum: EthereumConfig {},
dynamic_fee: Default::default(),
base_fee: Default::default(),
quantum_portal: ferrum_x_runtime::QuantumPortalConfig {
networks: convert(networks),
},
}
}
28 changes: 9 additions & 19 deletions node/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
use std::{fs::File, io::BufReader, path::Path};

use serde::Deserialize;
use serde::{Deserialize, Serialize};

use pallet_quantum_portal::qp_types::{EIP712Config, QpConfig, QpNetworkItem};
use pallet_quantum_portal::qp_types::{EIP712Config, QpConfig, QpNetworkItem, Role};

#[derive(Deserialize, Debug, Clone)]
pub struct Config {
pub chain_spec: ChinSpecConfig,
pub networks: NetworkConfig,
}

#[derive(Deserialize, Debug, Clone)]
pub struct ChinSpecConfig {
/// Secret seed for initial authorities [aura, grandpa]
pub initial_authourity_seed_list: Vec<String>,
/// AccountId of the Sudo authority
pub root_seed: String,
/// List of AccountId to populate balances in genesis block
pub endowed_accounts_seed_list: Vec<String>,
/// List of AccountIds for EVM configuration
pub address_list: Vec<String>,
/// Secret seed for offchain signer key
pub offchain_signer_secret_seed: String,
}

#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
pub struct NetworkItem {
/// The rpc url for this network
#[serde(with = "serde_bytes")]
Expand All @@ -36,7 +21,7 @@ pub struct NetworkItem {
pub id: u64,
}

#[derive(Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NetworkConfig {
// The NetworkItem data structure
network_vec: Vec<NetworkItem>,
Expand All @@ -52,9 +37,13 @@ pub struct NetworkConfig {
pub authority_manager_contract_version: Vec<u8>,
#[serde(with = "serde_bytes")]
pub authority_manager_contract_address: Vec<u8>,
/// The role of this node
#[serde(with = "serde_bytes")]
pub role: Vec<u8>,
}

pub fn convert(network_config: NetworkConfig) -> QpConfig {
let role_as_bytes: &[u8] = &network_config.role;
QpConfig {
network_vec: network_config
.network_vec
Expand All @@ -72,6 +61,7 @@ pub fn convert(network_config: NetworkConfig) -> QpConfig {
contract_version: network_config.authority_manager_contract_version,
verifying_address: network_config.authority_manager_contract_address,
},
role: role_as_bytes.into(),
}
}

Expand Down
Loading

0 comments on commit c0f14c7

Please sign in to comment.