Skip to content

Commit

Permalink
Improve genesis config (paritytech#292)
Browse files Browse the repository at this point in the history
* improve btc genesis params
* update script

Signed-off-by: koushiro <koushiro.cqx@gmail.com>
  • Loading branch information
koushiro authored Oct 17, 2020
1 parent 69f3f84 commit 404d31e
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 238 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

9 changes: 4 additions & 5 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sc-chain-spec = "2.0.0"

sc-cli = { version = "0.8.0", optional = true }
sc-service = { version = "0.8.0", optional = true }
frame-benchmarking-cli = "2.0.0"
frame-benchmarking-cli = { version = "2.0.0", optional = true }

# Substrate primitives
sp-core = "2.0.0"
Expand All @@ -46,14 +46,12 @@ sp-authority-discovery = "2.0.0"
# Substrate pallets
pallet-im-online = "2.0.0"

chainx-executor = { path = "../executor" }
chainx-primitives = { path = "../primitives" }
chainx-rpc = { path = "../rpc" }
chainx-runtime = { path = "../runtime" }
xp-io = { path = "../primitives/io" }
chainx-rpc = { path = "../rpc" }
chainx-executor = { path = "../executor" }

xpallet-protocol = { path = "../xpallets/protocol" }
xpallet-gateway-bitcoin = { path = "../xpallets/gateway/bitcoin" }

[build-dependencies]
substrate-build-script-utils = "2.0.0"
Expand All @@ -63,6 +61,7 @@ default = ["cli"]
cli = [
"sc-cli",
"sc-service",
"frame-benchmarking-cli",
"chainx-executor/wasmi-errno",
]
wasmtime = [
Expand Down
100 changes: 49 additions & 51 deletions cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ use chainx_runtime::{
XSystemConfig,
};

use crate::genesis::trustees::TrusteeParams;
use crate::res::BitcoinParams;
use crate::genesis::bitcoin::{BtcGenesisParams, BtcTrusteeParams};

// Note this is the URL for the telemetry server
//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
Expand Down Expand Up @@ -135,7 +134,7 @@ pub fn development_config() -> Result<ChainSpec, String> {

let endowed_balance = 50 * DOLLARS;
let constructor = move || {
testnet_genesis(
build_genesis(
wasm_binary,
vec![authority_keys_from_seed("Alice")],
get_account_id_from_seed::<sr25519::Public>("Alice"),
Expand All @@ -147,8 +146,10 @@ pub fn development_config() -> Result<ChainSpec, String> {
("Alice//stash", endowed_balance),
("Bob//stash", endowed_balance),
],
crate::res::testnet_btc_genesis_header,
crate::genesis::trustees::local_testnet_trustees(),
crate::genesis::bitcoin::btc_genesis_params(include_str!(
"res/btc_genesis_params_testnet.json"
)),
crate::genesis::bitcoin::local_testnet_trustees(),
)
};
Ok(ChainSpec::from_genesis(
Expand All @@ -170,7 +171,7 @@ pub fn benchmarks_config() -> Result<ChainSpec, String> {

let endowed_balance = 50 * DOLLARS;
let constructor = move || {
testnet_genesis(
build_genesis(
wasm_binary,
vec![authority_keys_from_seed("Alice")],
get_account_id_from_seed::<sr25519::Public>("Alice"),
Expand All @@ -182,8 +183,10 @@ pub fn benchmarks_config() -> Result<ChainSpec, String> {
("Alice//stash", endowed_balance),
("Bob//stash", endowed_balance),
],
crate::res::mainnet_btc_genesis_header,
crate::genesis::trustees::benchmarks_trustees(),
crate::genesis::bitcoin::btc_genesis_params(include_str!(
"res/btc_genesis_params_mainnet.json"
)),
crate::genesis::bitcoin::benchmarks_trustees(),
)
};
Ok(ChainSpec::from_genesis(
Expand All @@ -205,7 +208,7 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {

let endowed_balance = 50 * DOLLARS;
let constructor = move || {
testnet_genesis(
build_genesis(
wasm_binary,
vec![
authority_keys_from_seed("Alice"),
Expand All @@ -228,8 +231,10 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
("Eve//stash", endowed_balance),
("Ferdie//stash", endowed_balance),
],
crate::res::testnet_btc_genesis_header,
crate::genesis::trustees::local_testnet_trustees(),
crate::genesis::bitcoin::btc_genesis_params(include_str!(
"res/btc_genesis_params_testnet.json"
)),
crate::genesis::bitcoin::local_testnet_trustees(),
)
};
Ok(ChainSpec::from_genesis(
Expand Down Expand Up @@ -361,15 +366,17 @@ pub fn staging_testnet_config() -> Result<ChainSpec, String> {
endowed.insert(pcx_id, endowed_info);

let constructor = move || {
testnet_genesis(
build_genesis(
wasm_binary,
initial_authorities.clone(),
root_key.clone(),
root_key.clone(), // use root key as vesting_account
assets.clone(),
endowed.clone(),
crate::res::testnet_btc_genesis_header,
crate::genesis::trustees::staging_testnet_trustees(),
crate::genesis::bitcoin::btc_genesis_params(include_str!(
"res/btc_genesis_params_testnet.json"
)),
crate::genesis::bitcoin::staging_testnet_trustees(),
)
};
Ok(ChainSpec::from_genesis(
Expand Down Expand Up @@ -504,15 +511,17 @@ pub fn testnet_config() -> Result<ChainSpec, String> {
endowed.insert(pcx_id, endowed_info);

let constructor = move || {
testnet_genesis(
build_genesis(
&wasm_binary[..],
initial_authorities.clone(),
root_key.clone(),
root_key.clone(), // use root key as vesting_account
assets.clone(),
endowed.clone(),
crate::res::testnet_btc_genesis_header,
crate::genesis::trustees::staging_testnet_trustees(),
crate::genesis::bitcoin::btc_genesis_params(include_str!(
"res/btc_genesis_params_testnet.json"
)),
crate::genesis::bitcoin::staging_testnet_trustees(),
)
};
Ok(ChainSpec::from_genesis(
Expand Down Expand Up @@ -606,19 +615,16 @@ fn init_assets(
(init_assets, assets_restrictions)
}

fn testnet_genesis<F>(
fn build_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<AuthorityKeysTuple>,
root_key: AccountId,
vesting_account: AccountId,
assets: Vec<AssetParams>,
endowed: BTreeMap<AssetId, Vec<(AccountId, Balance)>>,
bitcoin_info: F,
trustees: Vec<(Chain, TrusteeInfoConfig, Vec<TrusteeParams>)>,
) -> GenesisConfig
where
F: FnOnce() -> BitcoinParams,
{
bitcoin: BtcGenesisParams,
trustees: Vec<(Chain, TrusteeInfoConfig, Vec<BtcTrusteeParams>)>,
) -> GenesisConfig {
const ENDOWMENT: Balance = 10_000_000 * DOLLARS;
const STASH: Balance = 100 * DOLLARS;
const STAKING_LOCKED: Balance = 1_000 * DOLLARS;
Expand Down Expand Up @@ -666,7 +672,7 @@ where
let validators = initial_authorities
.clone()
.into_iter()
.map(|((val, referral_id), _, _, _, _, _)| (val, referral_id, STAKING_LOCKED))
.map(|((validator, referral), _, _, _, _, _)| (validator, referral, STAKING_LOCKED))
.collect::<Vec<_>>();
let btc_genesis_trustees = trustees
.iter()
Expand Down Expand Up @@ -735,32 +741,24 @@ where
endowed: assets_endowed,
}),
xpallet_gateway_common: Some(XGatewayCommonConfig { trustees }),
xpallet_gateway_bitcoin: {
let BitcoinParams {
genesis_info,
genesis_hash,
network,
confirmed_count,
} = bitcoin_info(); // crate::res::mainnet_btc_genesis_header();
Some(XGatewayBitcoinConfig {
genesis_trustees: btc_genesis_trustees,
genesis_info,
genesis_hash,
network_id: network,
params_info: BtcParams::new(
486604799, // max_bits
2 * 60 * 60, // block_max_future
2 * 7 * 24 * 60 * 60, // target_timespan_seconds
10 * 60, // target_spacing_seconds
4, // retargeting_factor
),
verifier: BtcTxVerifier::Recover,
confirmation_number: confirmed_count,
reserved_block: 2100,
btc_withdrawal_fee: 500000,
max_withdrawal_count: 100,
})
},
xpallet_gateway_bitcoin: Some(XGatewayBitcoinConfig {
genesis_trustees: btc_genesis_trustees,
network_id: bitcoin.network,
confirmation_number: bitcoin.confirmation_number,
genesis_hash: bitcoin.hash(),
genesis_info: (bitcoin.header(), bitcoin.height),
params_info: BtcParams::new(
486604799, // max_bits
2 * 60 * 60, // block_max_future
2 * 7 * 24 * 60 * 60, // target_timespan_seconds
10 * 60, // target_spacing_seconds
4, // retargeting_factor
), // retargeting_factor
reserved_block: 2100,
btc_withdrawal_fee: 500000,
max_withdrawal_count: 100,
verifier: BtcTxVerifier::Recover,
}),
xpallet_mining_staking: Some(XStakingConfig {
validators,
validator_count: 50,
Expand Down
Loading

0 comments on commit 404d31e

Please sign in to comment.