Skip to content

Commit

Permalink
Update staking test (paritytech#146)
Browse files Browse the repository at this point in the history
* Update staking test

* Update README.md

* Change name to Genesis

* Update README.md

* Add images

* Resize image

* Update roadmap

* Resize images in roadmap

* Updates

* And more

* Drop roadmap images

* Don't use Alice as genesis cert owner

* remove tokenstaking trigger&fix bug to remove pcx token in tokenstaking

* Disable on_dilution

* Nit
  • Loading branch information
liuchengxu authored and gguoss committed Dec 5, 2018
1 parent 8951bdd commit bd418e5
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 811 deletions.
148 changes: 57 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# ChainX

[![Build Status](https://travis-ci.com/chainx-org/ChainX.svg?branch=master)](https://travis-ci.com/chainx-org/ChainX)

<!-- TOC GFM -->

* [Introduction](#introduction)
* [Features](#features)
* [Roadmap](#roadmap)
* [1.0: Independent Chain](#10-independent-chain)
* [2.0: Polkadot Parachain](#20-polkadot-parachain)
* [3.0: Polkadot level 2 multi-chain system](#30-polkadot-level-2-multi-chain-system)
* [Installation](#installation)
* [Building from source](#building-from-source)
* [Requirement](#requirement)
* [Build the code](#build-the-code)
* [Testnet](#testnet)
* [Development](#development)
* [Validator node](#validator-node)
* [Local single validator](#local-single-validator)
* [Local two validator node](#local-two-validator-node)
* [Multiple validator node](#multiple-validator-node)
* [Sync node](#sync-node)
* [Public testnet](#public-testnet)
* [Development](#development-1)
* [Run a local testnet](#run-a-local-testnet)
* [License](#license)

<!-- /TOC -->
Expand All @@ -25,138 +23,106 @@

For the time being the goal of [ChainX](https://github.com/chainx-org/ChainX) is to build a cross-chain digital asset management platform on the strength of [substrate](https://github.com/paritytech/substrate) which is next-generation framework for blockchain created by [paritytech](https://github.com/paritytech). The long-term vision of ChainX is to evolve as a general blockchain infrastrcutre platform.

ChainX is still at a very early stage and in an active development. The instruction as followed is not stable and may change in the future.

:tada: Run this command to connect to our public testnet:
<p align="center">
<a href="http://chainx.org" target="_blank">
<img width="800" alt="transparent" src="http://chainx.org/static/media/section2.0347a5e3.png">
</a>
</p>

```bash
$ chainx --chainspec=multi --telemetry --bootnodes=/ip4/47.105.73.172/tcp/30333/p2p/QmW7aJxigxGFXLmn966nJBBCexZA4nfSiydeg1JfmGFC9q --db-path=/tmp/chainx
```

## Installation
ChainX is still at a very early stage and in an active development. The instruction as followed is not stable and may change in the future.

### Building from source
## Features

#### Requirement
- Built-in light client of existing blockchains.

Ensure you have [Rust](https://www.rust-lang.org/) and the support software installed:
- Built-in Coin DEX.

Ubuntu:
- Progressive staking and election machanism.

```bash
$ curl https://sh.rustup.rs -sSf | sh
$ rustup update nightly
$ rustup target add wasm32-unknown-unknown --toolchain nightly
$ rustup update stable
$ cargo install --git https://github.com/alexcrichton/wasm-gc
$ sudo apt install cmake pkg-config libssl-dev git
```
- And more.

#### Build the code
## Roadmap

```bash
# Get the source code
$ git clone https://github.com/chainx-org/ChainX ~/ChainX
$ cd ~/ChainX
### 1.0: Independent Chain

# Build all native code, the executable binary will be present in target/debug/chainx.
$ cargo build
ChainX 1.0 will operate as an independent chain at the very beginning, supporting the Coin DEX between the system currency PCX and BTC powed by BTC cross-chain transaction from the relay. At this stage, ChainX will continue to relay BCH, LTC, ZEC, ETH, DAI, ERC20, ERC721, ADA, EOS and other chains for Coin DEX.

# If your want to run chainx in production, please build it in release mode
$ cargo build --release
```
### 2.0: Polkadot Parachain

## Development
ChainX 2.0 will begin at Q3 2019 when Polkadot releases v1. It will connect into Polkadot and transform into a para-chain, adding new applications such as decentralized stable currency collateralized by BTC and derivatives exchanges.

When you succeed to build the project with `cargo build`, the `chainx` binary should be present in `target/debug/chainx`.
### 3.0: Polkadot level 2 multi-chain system

We assume `chainx` is in your `$PATH` in the following sections. Run this command so that `chainx` could be found in `$PATH`:
ChainX 3.0 will begin at 2020 when Polkadot releases v2, splited into a multi-chain architecture operating as Polkadot's level 2 relay network.

```bash
$ export PATH=$(pwd)/target/debug:$PATH
```

See all the avaliable options and commands via `chainx -h`.

### Validator node

#### Local single validator

You can run a simple single-node development _network_ on your machine by running in a terminal:

```bash
$ RUST_LOG=info chainx --chainspec=dev --db-path=/tmp/dev-alice validator --auth=alice
```
## Installation

Don't forget to run with `RUST_LOG=info` to see the logs, or you prefer to `export RUST_LOG=info` to avoid specifying every time.
### Building from source

```bash
$ export RUST_LOG=info
```
#### Requirement

#### Local two validator node
Refer to [Hacking on Substrate](https://github.com/paritytech/substrate#61-hacking-on-substrate) as well.

Run the first node:
Ensure you have [Rust](https://www.rust-lang.org/) and the support software installed:

```bash
$ chainx --chainspec=local --db-path=/tmp/local-alice validator --auth=alice
INFO 2018-09-11T05:09:59Z: chainx: Chainspec is local mode
INFO 2018-09-11T05:09:59Z: substrate_client::client: Initialising Genesis block/state (state: 0x1529…4159, header-hash: 0xbcf4…9a00)
INFO 2018-09-11T05:09:59Z: substrate_network_libp2p::service: Local node address is: /ip4/127.0.0.1/tcp/20222/p2p/Qmevv1ggYD5dLf3MwAJ5zKeRGtnjfV7i85cPAsYwNaVW2o
INFO 2018-09-11T05:10:00Z: chainx: Auth is alice
......
$ curl https://sh.rustup.rs -sSf | sh
$ rustup update nightly
$ rustup target add wasm32-unknown-unknown --toolchain nightly
$ rustup update stable
$ cargo install --git https://github.com/alexcrichton/wasm-gc
```

Run the second node with option `bootnodes` from the address of first node:
Ubuntu:

```bash
$ chainx --chainspec=local --db-path=/tmp/local-bob --bootnodes=/ip4/127.0.0.1/tcp/20222/p2p/Qmevv1ggYD5dLf3MwAJ5zKeRGtnjfV7i85cPAsYwNaVW2o validator --auth=bob
$ sudo apt install cmake pkg-config libssl-dev git
```

#### Multiple validator node

Run the first node:
Mac:

```bash
$ chainx --chainspec=multi --db-path=/tmp/multi-alice validator --auth=alice
$ brew install cmake pkg-config openssl git
```

Run the second node:
#### Build the code

```bash
$ chainx --chainspec=multi --db-path=/tmp/multi-bob --bootnodes=/ip4/127.0.0.1/tcp/20222/p2p/QmWrZEJcYn3m8HeiHsYDVH1apitFF1h4ojyRYu9AjFkTuH validator --auth=bob
```
# Get the source code
$ git clone https://github.com/chainx-org/ChainX ~/ChainX
$ cd ~/ChainX

Run the third node:
# Build all native code, the executable binary will be present in target/debug/chainx.
$ cargo build

```bash
$ chainx --chainspec=multi --db-path=/tmp/multi-gavin --bootnodes=/ip4/127.0.0.1/tcp/20222/p2p/QmWrZEJcYn3m8HeiHsYDVH1apitFF1h4ojyRYu9AjFkTuH validator --auth=gavin
# If your want to run chainx in production, please build it in release mode
$ cargo build --release
```

These nodes won't be able to produce blocks until the number of validators is no less than 3.
## Testnet

We can add one more validator:
Connect to the public testnet of ChainX:

```bash
$ chainx --chainspec=multi --db-path=/tmp/multi-satoshi --bootnodes=/ip4/127.0.0.1/tcp/20222/p2p/QmWrZEJcYn3m8HeiHsYDVH1apitFF1h4ojyRYu9AjFkTuH validator --auth=satoshi
$ RUST_LOG=info ./chainx --chainspec=dev --telemetry --bootnodes=/ip4/47.93.16.189/tcp/20222/p2p/QmRdBJk8eVPjkHcxZvRAUZdWtTq96mWivJFc7tpJ8fUEGU --db-path=/tmp/chainx
```

### Sync node
## Development

#### Public testnet
When you succeed to build the project with `cargo build`, the `chainx` binary should be present in `target/debug/chainx`.

Run the following command to connect to our public testnet:
We assume `chainx` is in your `$PATH` in the following sections. Run this command so that `chainx` could be found in `$PATH`:

```bash
$ chainx --chainspec=multi --telemetry --bootnodes=/ip4/47.105.73.172/tcp/30333/p2p/QmW7aJxigxGFXLmn966nJBBCexZA4nfSiydeg1JfmGFC9q --db-path=/tmp/chainx
$ export PATH=$(pwd)/target/debug:$PATH
```

#### Development
### Run a local testnet

Running `chainx` without `validator` subcommand is to synchronise to the chain, e.g., synchronise to a node in local mode:
Start a local chainx testnet by running:

```bash
$ chainx --chainspec=local --db-path=/tmp/local-sync --bootnodes=/ip4/127.0.0.1/tcp/20222/p2p/Qmevv1ggYD5dLf3MwAJ5zKeRGtnjfV7i85cPAsYwNaVW2o
$ chainx --chainspec=dev --key=Alice validator
```

## License
Expand Down
14 changes: 9 additions & 5 deletions cxrml/mining/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern crate sr_io as runtime_io;
extern crate substrate_primitives;

use associations::{ChannelRelationship, RevChannelRelationship};
use balances::{address::Address, FreeBalance, OnDilution, ReservedBalance};
use balances::{address::Address, FreeBalance, OnDilution, ReservedBalance, TotalIssuance};
use codec::Codec;
use primitives::{
traits::{As, OnFinalise, One, Zero},
Expand Down Expand Up @@ -323,6 +323,8 @@ decl_storage! {

let mut stats: Stats<T::AccountId, T::Balance> = Stats::default();

let mut total_issuance = T::Balance::sa(0);

for (acnt, name, url) in config.intention_profiles.iter() {

let mut nprof: NominatorProfs<T::AccountId, T::Balance> = NominatorProfs::default();
Expand All @@ -346,6 +348,8 @@ decl_storage! {
let free = T::Balance::sa(100_000_000_000 - config.activation_per_share as u64);
storage.insert(GenesisConfig::<T>::hash(&<FreeBalance<T>>::key_for(acnt)).to_vec(), free.encode());

total_issuance += iprof.total_nomination;

let mut nominations: BTreeMap<T::AccountId, NominationRecord<T::Balance, T::BlockNumber>> = BTreeMap::new();
let mut record = NominationRecord::default();
record.nomination = iprof.total_nomination;
Expand All @@ -360,6 +364,8 @@ decl_storage! {
storage.insert(GenesisConfig::<T>::hash(&<RevChannelRelationship<T>>::key_for(intention)).to_vec(), channel.encode());
}

storage.insert(GenesisConfig::<T>::hash(&<TotalIssuance<T>>::key()).to_vec(), total_issuance.encode());

storage.insert(GenesisConfig::<T>::hash(&<StakingStats<T>>::key()).to_vec(), stats.encode());

let cert_index = index + 1;
Expand Down Expand Up @@ -1049,7 +1055,6 @@ impl<T: Trait> Module<T> {
if !total_active_stake.is_zero() {
for (v, s) in active_intentions.iter() {
let i_reward = *s * reward / total_active_stake;
// TODO session reward
<SessionRewardOf<T>>::insert(v, i_reward);
total_minted += i_reward;
match v {
Expand All @@ -1060,9 +1065,8 @@ impl<T: Trait> Module<T> {
}

Self::deposit_event(RawEvent::Reward(reward));
//// TODO Self::total_stake?
let stats = <StakingStats<T>>::get();
T::OnRewardMinted::on_dilution(total_minted, stats.total_stake);
// FIXME
// T::OnRewardMinted::on_dilution(total_minted, total_minted);
}

let session_index = <session::Module<T>>::current_index();
Expand Down
Loading

0 comments on commit bd418e5

Please sign in to comment.