Skip to content

Commit

Permalink
Tweak staking initialization (paritytech#241)
Browse files Browse the repository at this point in the history
* Need to resolve finalized paritytech#30

* Fixes unfinalized issue after 30 blocks

* Avoid invoke pcx_move

* Draft

* Split out

* Rebuild wasm

* Init session validators

* Quick fix for unfinalized issue

* Mul first
  • Loading branch information
liuchengxu authored Jan 25, 2019
1 parent 5ac8909 commit cbafb06
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 161 deletions.
30 changes: 13 additions & 17 deletions cli/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ pub fn testnet_genesis(genesis_spec: GenesisSpec) -> GenesisConfig {
existential_deposit: 0,
transfer_fee: 0,
creation_fee: 0,
balances: vec![
(Keyring::Alice.to_raw_public().into(), 1_000_000_000),
(Keyring::Bob.to_raw_public().into(), 1_000_000_000),
],
balances: vec![],
};
//let balances_config_copy = BalancesConfigCopy::create_from_src(&balances_config).src();

Expand All @@ -78,6 +75,12 @@ pub fn testnet_genesis(genesis_spec: GenesisSpec) -> GenesisConfig {
)
.unwrap();

let endowed = initial_authorities
.clone()
.into_iter()
.map(|x| (x, 12500))
.collect::<Vec<_>>();

GenesisConfig {
consensus: Some(ConsensusConfig {
code: include_bytes!(
Expand All @@ -94,22 +97,14 @@ pub fn testnet_genesis(genesis_spec: GenesisSpec) -> GenesisConfig {
period: CONSENSUS_TIME, // 2 second block time.
}),
session: Some(SessionConfig {
validators: initial_authorities
.iter()
.cloned()
.map(|account_id| (account_id.into(), 0))
.collect(),
validators: endowed.iter().cloned().map(|(account, balance)| (account.into(), balance)).collect(),
session_length: 30, // 30 blocks per session
}),
sudo: Some(SudoConfig {
key: auth1.into(),
}),
grandpa: Some(GrandpaConfig {
authorities: initial_authorities
.clone()
.into_iter()
.map(|k| (k, 1))
.collect(),
authorities: endowed.clone(),
}),
// chainx runtime module
xsystem: Some(XSystemConfig {
Expand All @@ -122,7 +117,7 @@ pub fn testnet_genesis(genesis_spec: GenesisSpec) -> GenesisConfig {
maximum_cert_count: 180,
shares_per_cert: 50,
total_issued: 1,
cert_owner: auth1.into(),
_genesis_phantom_data: Default::default(),
}),
fee_manager: Some(XFeeManagerConfig {
switch: false,
Expand All @@ -136,16 +131,17 @@ pub fn testnet_genesis(genesis_spec: GenesisSpec) -> GenesisConfig {
asset_list: vec![
(btc_asset, true, vec![(Keyring::Alice.to_raw_public().into(), 1_000_000_000),(Keyring::Bob.to_raw_public().into(), 1_000_000_000)])
],
initial_reserve: endowed.iter().cloned().map(|(account, balance)| (account.into(), balance)).collect(),
}),
xstaking: Some(XStakingConfig {
validator_count: 7,
minimum_validator_count: 1,
sessions_per_era: 10,
sessions_per_era: 1,
bonding_duration: 10,
current_era: 0,
penalty: 100,
funding: Default::default(),
intentions: initial_authorities.clone().into_iter().map(|i| i.0.into()).collect(),
intentions: endowed.iter().cloned().map(|(account, balance)| (account.into(), balance)).collect(),
}),
xspot: Some(XSpotConfig {
pair_list: vec![(<xassets::Module<Runtime> as ChainT>::TOKEN.to_vec(),<bitcoin::Module<Runtime> as ChainT>::TOKEN.to_vec(),7,100,100,true)],
Expand Down
7 changes: 1 addition & 6 deletions rpc/src/chainx/impl_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,8 @@ where
let mut info = IntentionInfo::default();

let key = <xaccounts::IntentionImmutablePropertiesOf<Runtime>>::key_for(&intention);
if let Some(props) =
Self::pickout::<IntentionImmutableProps<Timestamp>>(&state, &key)?
{
if let Some(props) = Self::pickout::<IntentionImmutableProps>(&state, &key)? {
info.name = String::from_utf8_lossy(&props.name).into_owned();
info.activator = String::from_utf8_lossy(&props.activator).into_owned();
info.initial_shares = props.initial_shares;
info.registered_at = props.registered_at;
}

let key = <xaccounts::IntentionPropertiesOf<Runtime>>::key_for(&intention);
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl CheckFee for Call {
},
// xmining
Call::XStaking(call) => match call {
XStakingCall::register(_, _, _, _, _, _) => Some(100),
XStakingCall::register(_) => Some(100),
XStakingCall::refresh(_, _, _, _) => Some(100),
XStakingCall::nominate(_, _, _) => Some(5),
XStakingCall::unnominate(_, _, _) => Some(3),
Expand Down
Binary file not shown.
27 changes: 2 additions & 25 deletions xrml/xaccounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ pub struct CertImmutableProps<BlockNumber: Default, Moment: Default> {
#[derive(PartialEq, Eq, Clone, Encode, Decode, Default)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
pub struct IntentionImmutableProps<Moment> {
pub struct IntentionImmutableProps {
pub name: Name,
pub activator: Name,
pub initial_shares: u32,
pub registered_at: Moment,
}

/// Intention mutable properties
Expand Down Expand Up @@ -117,32 +114,12 @@ decl_storage! {
/// intention name => intention
pub IntentionOf get(intention_of): map Name => Option<T::AccountId>;

pub IntentionImmutablePropertiesOf get(intention_immutable_props_of): map T::AccountId => Option<IntentionImmutableProps<T::Moment>>;
pub IntentionImmutablePropertiesOf get(intention_immutable_props_of): map T::AccountId => Option<IntentionImmutableProps>;

pub IntentionPropertiesOf get(intention_props_of): map T::AccountId => IntentionProps;

}

add_extra_genesis {
config(cert_owner): T::AccountId;

build(|storage: &mut runtime_primitives::StorageMap, _: &mut runtime_primitives::ChildrenStorageMap, config: &GenesisConfig<T>| {
use runtime_io::with_externalities;
use substrate_primitives::Blake2Hasher;
use runtime_primitives::StorageMap;

let s = storage.clone().build_storage().unwrap().0;
let mut init: runtime_io::TestExternalities<Blake2Hasher> = s.into();
with_externalities(&mut init, || {
let cert_name = b"genesis_cert".to_vec();
let frozen_duration = 1u32;
let cert_owner = config.cert_owner.clone();
Module::<T>::issue(cert_name, frozen_duration, cert_owner).unwrap();
});
let init: StorageMap = init.into();
storage.extend(init);
});
}
}

impl<T: Trait> Module<T> {
Expand Down
13 changes: 13 additions & 0 deletions xrml/xassets/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,31 @@ decl_storage! {
/// memo len
pub MemoLen get(memo_len) config(): u32;
}

add_extra_genesis {
config(asset_list): Vec<(Asset, bool, Vec<(T::AccountId, u64)>)>;
config(pcx): (Token, Precision, Desc);
config(initial_reserve): Vec<(T::AccountId, T::Balance)>;

build(|storage: &mut primitives::StorageMap, _: &mut primitives::ChildrenStorageMap, config: &GenesisConfig<T>| {
use runtime_io::with_externalities;
use substrate_primitives::Blake2Hasher;
use primitives::traits::{Zero, As};

let src_r = storage.clone().build_storage().unwrap().0;
let mut tmp_storage: runtime_io::TestExternalities<Blake2Hasher> = src_r.into();
with_externalities(&mut tmp_storage, || {
let chainx: Token = <Module<T> as ChainT>::TOKEN.to_vec();

let pcx = Asset::new(chainx, config.pcx.0.clone(), Chain::ChainX, config.pcx.1, config.pcx.2.clone()).unwrap();
Module::<T>::register_asset(pcx, false, Zero::zero()).unwrap();

// initial reserve
for (intention, value) in config.initial_reserve.iter() {
let _ = Module::<T>::pcx_issue(intention, *value);
let _ = Module::<T>::pcx_move_balance(intention, AssetType::Free, intention, AssetType::ReservedStaking, *value);
}

// init for asset_list
for (asset, is_psedu_intention, init_list) in config.asset_list.iter() {
let token = asset.token();
Expand Down Expand Up @@ -480,6 +492,7 @@ impl<T: Trait> Module<T> {

pub fn is_valid_asset(token: &Token) -> Result {
is_valid_token(token)?;

if let Some(info) = Self::asset_info(token) {
if info.1 == true {
return Ok(());
Expand Down
Loading

0 comments on commit cbafb06

Please sign in to comment.