Skip to content

Commit

Permalink
Feature/bootstrap (paritytech#265)
Browse files Browse the repository at this point in the history
* Various fixes

* Correct init

* Add name and url in endowed intentions

* Update wasm

* Init tokens vote weight of endowed

* 10 blocks per session

* Take care of precision between price and cross chain assets

* Update wasm

* Fix/spot quotationss  (paritytech#260)

rename online&add some event

* compile wasm

* compile wasm

* Fix run bug

* new genesis

* Add straging telemetry url

* update genesis

* Fix bridge storage name (paritytech#263)

* Fix bridge storage name

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Add pub

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Update new wasm

* update genesis

* Adjust penalty as 0

* update genesis

* Fix/handicap (paritytech#264)

* fix handicap

* Let auth3 is charlie

* Rebuild
  • Loading branch information
liuchengxu authored and gguoss committed Feb 11, 2019
1 parent 23c7b8c commit 45e7f71
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 97 deletions.
6 changes: 3 additions & 3 deletions cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ fn local_testnet_genesis() -> GenesisConfig {
/// Local testnet config (multivalidator Alice + Bob)
pub fn local_testnet_config() -> ChainSpec {
ChainSpec::from_genesis(
"Local Testnet",
"local_testnet",
"ChainX Testnet",
"chainx_testnet",
local_testnet_genesis,
vec![],
None,
Some(STAGING_TELEMETRY_URL.into()),
None,
None,
None,
Expand Down
33 changes: 21 additions & 12 deletions cli/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ pub fn testnet_genesis(genesis_spec: GenesisSpec) -> GenesisConfig {

let auth1 = alice.into();
let auth2 = bob.into();
let auth3 = gavin.into();
let auth3 = charlie.into();
let auth4 = satoshi.into();
let initial_authorities = match genesis_spec {
GenesisSpec::Dev => vec![auth1],
GenesisSpec::Local => vec![auth1, auth2],
GenesisSpec::Multi => vec![auth1, auth2, auth3, auth4, charlie.into(), dave.into()],
GenesisSpec::Local => vec![auth1, auth2, auth3],
GenesisSpec::Multi => vec![auth1, auth2, auth3, auth4, gavin.into(), dave.into()],
};

const CONSENSUS_TIME: u64 = 1;
Expand Down Expand Up @@ -98,12 +98,18 @@ pub fn testnet_genesis(genesis_spec: GenesisSpec) -> GenesisConfig {
)
.unwrap();

let endowed = initial_authorities
let apply_prec = |x| x * 10_u64.pow(pcx_precision as u32);
let mut full_endowed = vec![
(auth1, apply_prec(30), b"Alice".to_vec(), b"Alice.com".to_vec()),
(auth2, apply_prec(10), b"Bob".to_vec(), b"Bob.com".to_vec()),
(auth3, apply_prec(10), b"Charlie".to_vec(), b"Charlie".to_vec()),
];
full_endowed.truncate(initial_authorities.len());
let endowed = full_endowed
.clone()
.into_iter()
.map(|x| (x, 12500))
.map(|(auth, balance, _, _)| (auth, balance))
.collect::<Vec<_>>();

GenesisConfig {
consensus: Some(ConsensusConfig {
code: include_bytes!(
Expand All @@ -121,7 +127,7 @@ pub fn testnet_genesis(genesis_spec: GenesisSpec) -> GenesisConfig {
}),
session: Some(SessionConfig {
validators: endowed.iter().cloned().map(|(account, balance)| (account.into(), balance)).collect(),
session_length: 30, // 30 blocks per session
session_length: 10, // 30 blocks per session
}),
sudo: Some(SudoConfig {
key: auth1.into(),
Expand All @@ -146,9 +152,9 @@ pub fn testnet_genesis(genesis_spec: GenesisSpec) -> GenesisConfig {
// asset, is_psedu_intention, init for account
// Vec<(Asset, bool, Vec<(T::AccountId, u64)>)>;
asset_list: vec![
(btc_asset, true, vec![(Keyring::Alice.to_raw_public().into(), 100),(Keyring::Bob.to_raw_public().into(), 100)]),
(btc_asset.clone(), true, vec![(Keyring::Alice.to_raw_public().into(), 100_000),(Keyring::Bob.to_raw_public().into(), 100_000)]),
// (dot_asset.clone(), false, vec![(Keyring::Alice.to_raw_public().into(), 1_000_000_000),(Keyring::Bob.to_raw_public().into(), 1_000_000_000)]),
(xdot_asset.clone(), true, vec![(Keyring::Alice.to_raw_public().into(), 100),(Keyring::Bob.to_raw_public().into(), 100)])
(xdot_asset.clone(), true, vec![(Keyring::Alice.to_raw_public().into(), 10_000),(Keyring::Bob.to_raw_public().into(), 10_000)])
],
}),
xprocess: Some(XAssetsProcessConfig {
Expand All @@ -161,14 +167,17 @@ pub fn testnet_genesis(genesis_spec: GenesisSpec) -> GenesisConfig {
sessions_per_era: 1,
bonding_duration: 30,
current_era: 0,
penalty: 100,
penalty: 0,
funding: Default::default(),
intentions: endowed.iter().cloned().map(|(account, balance)| (account.into(), balance)).collect(),
intentions: full_endowed.into_iter().map(|(who, value, name, url)| (who.into(), value, name, url)).collect(),
validator_stake_threshold: 1,
}),
xtokens: Some(XTokensConfig {
token_discount: Permill::from_percent(30),
_genesis_phantom_data: Default::default(),
endowed_users: vec![
(btc_asset.token(), vec![(Keyring::Alice.to_raw_public().into(), 100_000),(Keyring::Bob.to_raw_public().into(), 100_000)]),
(xdot_asset.token(), vec![(Keyring::Alice.to_raw_public().into(), 10_000),(Keyring::Bob.to_raw_public().into(), 10_000)])
],
}),
xspot: Some(XSpotConfig {
pair_list: vec![
Expand Down
7 changes: 4 additions & 3 deletions rpc/src/chainx/impl_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ where
let mut intention_info = Vec::new();

let key = <session::Validators<Runtime>>::key();
let validators =
Self::pickout::<Vec<AccountId>>(&state, &key)?.expect("Validators can't be empty");
let validators = Self::pickout::<Vec<(AccountId, u64)>>(&state, &key)?
.expect("Validators can't be empty");
let validators: Vec<AccountId> = validators.into_iter().map(|(who, _)| who).collect();

let key = <xaccounts::TrusteeIntentions<Runtime>>::key();

Expand Down Expand Up @@ -399,7 +400,7 @@ where
info.assets = String::from_utf8_lossy(&pair.first).into_owned();
info.currency = String::from_utf8_lossy(&pair.second).into_owned();
info.precision = pair.precision;
info.on_line = pair.on_line;
info.online = pair.online;
info.unit_precision = pair.unit_precision;

let price_key = <xspot::OrderPairPriceOf<Runtime>>::key_for(&i);
Expand Down
4 changes: 1 addition & 3 deletions rpc/src/chainx/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ pub struct IntentionInfo {
pub account: AccountId,
/// name of intention
pub name: String,
/// when is the intention registered
pub registered_at: Timestamp,
/// url
pub url: String,
/// about
Expand Down Expand Up @@ -104,7 +102,7 @@ pub struct PairInfo {
pub currency: String,
pub precision: u32, //价格精度
pub unit_precision: u32, //最小单位精度
pub on_line: bool,
pub online: bool,
pub last_price: Balance,
pub aver_price: Balance,
pub update_height: BlockNumber,
Expand Down
2 changes: 2 additions & 0 deletions runtime/wasm/Cargo.lock

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

Binary file not shown.
2 changes: 1 addition & 1 deletion xrml/xbridge/bitcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ decl_event!(
);

decl_storage! {
trait Store for Module<T: Trait> as BridgeOfBTC {
trait Store for Module<T: Trait> as XBridgeOfBTC {
/// get bestheader
pub BestIndex get(best_index): H256;

Expand Down
26 changes: 13 additions & 13 deletions xrml/xbridge/bitcoin/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub fn new_test_ext_err_genesisblock() -> runtime_io::TestExternalities<Blake2Ha
r.into()
}

type BridgeOfBTC = Module<Test>;
type XBridgeOfBTC = Module<Test>;
type Timestamp = timestamp::Module<Test>;

fn generate_blocks() -> (Vec<BlockHeader>, Vec<BlockHeader>) {
Expand Down Expand Up @@ -436,7 +436,7 @@ fn test_init_mock_blocks() {
#[test]
fn test_genesis() {
with_externalities(&mut new_test_ext(), || {
let (header, num) = BridgeOfBTC::genesis_info();
let (header, num) = XBridgeOfBTC::genesis_info();
let _r = <GenesisInfo<Test>>::get();
let h = header.hash().reversed();
assert_eq!(
Expand All @@ -445,7 +445,7 @@ fn test_genesis() {
);
assert_eq!(num, 1451572);

let best_hash = BridgeOfBTC::best_index();
let best_hash = XBridgeOfBTC::best_index();
assert_eq!(best_hash, header.hash());
})
}
Expand All @@ -461,19 +461,19 @@ fn test_normal() {
Timestamp::set_timestamp(current_time());
let (c1, _) = generate_blocks();
assert_err!(
BridgeOfBTC::apply_push_header(c1.get(0).unwrap().clone(), &1),
XBridgeOfBTC::apply_push_header(c1.get(0).unwrap().clone(), &1),
"Block parent is unknown"
);
assert_ok!(BridgeOfBTC::apply_push_header(
assert_ok!(XBridgeOfBTC::apply_push_header(
c1.get(1).unwrap().clone(),
&2
));
assert_ok!(BridgeOfBTC::apply_push_header(
assert_ok!(XBridgeOfBTC::apply_push_header(
c1.get(2).unwrap().clone(),
&3
));

let best_hash = BridgeOfBTC::best_index();
let best_hash = XBridgeOfBTC::best_index();
assert_eq!(best_hash, c1.get(2).unwrap().hash());
})
}
Expand All @@ -486,7 +486,7 @@ fn test_call() {
let origin = system::RawOrigin::Signed(99).into();
let v = ser::serialize(c1.get(1).unwrap());
let v = v.take();
assert_ok!(BridgeOfBTC::push_header(origin, v));
assert_ok!(XBridgeOfBTC::push_header(origin, v));
})
}

Expand Down Expand Up @@ -543,18 +543,18 @@ fn test_genesis2() {
Timestamp::set_timestamp(current_time());
let (c1, _) = generate_blocks();
assert_err!(
BridgeOfBTC::apply_push_header(c1.get(0).unwrap().clone(), &1),
XBridgeOfBTC::apply_push_header(c1.get(0).unwrap().clone(), &1),
"Block parent is unknown"
);
assert_ok!(BridgeOfBTC::apply_push_header(
assert_ok!(XBridgeOfBTC::apply_push_header(
c1.get(1).unwrap().clone(),
&1
));
assert_ok!(BridgeOfBTC::apply_push_header(
assert_ok!(XBridgeOfBTC::apply_push_header(
c1.get(2).unwrap().clone(),
&1
));
assert_ok!(BridgeOfBTC::apply_push_header(
assert_ok!(XBridgeOfBTC::apply_push_header(
c1.get(3).unwrap().clone(),
&1
));
Expand Down Expand Up @@ -652,7 +652,7 @@ fn test_changebit() {

#[test]
pub fn test_address() {
BridgeOfBTC::verify_btc_address(&b"mqVznxoxdeSNYgDCg6ZVE5pc6476BY6zHK".to_vec()).unwrap();
XBridgeOfBTC::verify_btc_address(&b"mqVznxoxdeSNYgDCg6ZVE5pc6476BY6zHK".to_vec()).unwrap();
}

#[test]
Expand Down
9 changes: 3 additions & 6 deletions xrml/xbridge/xdot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,11 @@ decl_event!(
);

decl_storage! {
// A macro for the Storage trait, and its implementation, for this module.
// This allows for type-safe usage of the Substrate storage database, so you can
// keep things around between blocks.
trait Store for Module<T: Trait> as Claims {
Claims get(claims) build(|config: &GenesisConfig<T>| {
trait Store for Module<T: Trait> as XBridgeOfXDOT {
pub Claims get(claims) build(|config: &GenesisConfig<T>| {
config.claims.iter().map(|(a, b)| (a.clone(), b.clone())).collect::<Vec<_>>()
}): map EthereumAddress => Option<T::Balance>;
Total get(total) build(|config: &GenesisConfig<T>| {
pub Total get(total) build(|config: &GenesisConfig<T>| {
config.claims.iter().fold(Zero::zero(), |acc: T::Balance, &(_, n)| acc + n)
}): T::Balance;
}
Expand Down
4 changes: 2 additions & 2 deletions xrml/xdex/spot/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct OrderPair {
pub second: Token,
pub precision: u32, //价格精度
pub unit_precision: u32, //最小单位精度
pub on_line: bool,
pub online: bool,
}
impl OrderPair {
pub fn new(
Expand All @@ -93,7 +93,7 @@ impl OrderPair {
second: second,
precision: precision,
unit_precision: unit,
on_line: status,
online: status,
}
}
}
Expand Down
Loading

0 comments on commit 45e7f71

Please sign in to comment.