Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icefrog #243

Merged
merged 30 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
110865a
fix nominating_and_rewards_should_work()
readlnh Dec 31, 2019
53f57ea
fix reward_destination_works() tests
readlnh Jan 2, 2020
0c88397
fix nominators_also_get_slashed tests
readlnh Jan 3, 2020
e58145e
add doc about bond_help_in_ring and bond_help_in_kton
readlnh Jan 3, 2020
cccd44f
fix validator_payment_prefs_work test
readlnh Jan 3, 2020
88362da
delete test that doesn't need
readlnh Jan 3, 2020
30bb581
change bond_extra_and_withdraw_unbonded_automatically_works(need fix)
readlnh Jan 3, 2020
71ecce6
split bond_extra_and_withdraw_unbonded_works test into two tests
readlnh Jan 4, 2020
ffd2577
add compute_power
readlnh Jan 4, 2020
9751511
slot_stake_is_least_staked_validator_and_exposure_defines_maximum_pun…
readlnh Jan 4, 2020
4fb160c
slashing_performed_according_exposure update(need discuss)
readlnh Jan 4, 2020
8f269e9
Fix RFC links in README
yanganto Jan 6, 2020
04e5021
Merge pull request #226 from yanganto/doc/rfc-link
hackfisher Jan 6, 2020
45f041d
Add Precautions part
yanganto Jan 6, 2020
a5ba7ae
Merge pull request #212 from readlnh/develop
hackfisher Jan 6, 2020
23a8c8a
Add note to build without sccache (#229)
aurexav Jan 6, 2020
f4ef8d8
trival: rustfmt
yanganto Jan 8, 2020
a3b17fd
trival: rustfmt (#231)
aurexav Jan 8, 2020
76705c2
trival: add pre-commit git hook & bootstrap script
yanganto Jan 8, 2020
50bebde
Add rustfmt test in ci
yanganto Jan 8, 2020
9a08671
Add pre-commit git hook & bootstrap script (#233)
aurexav Jan 8, 2020
162919b
README
yanganto Jan 9, 2020
1da65ac
README (#236)
aurexav Jan 9, 2020
256c1bc
Fix documentation
yanganto Jan 9, 2020
f800f67
Fix documentation (#239)
aurexav Jan 9, 2020
4222a5d
Add environment check in bootstrap
yanganto Jan 9, 2020
566a35e
Add fast mode in bootstarp.sh
yanganto Jan 10, 2020
072dada
Trival/bootstrap (#237)
aurexav Jan 10, 2020
73c049d
Merge remote-tracking branch 'upstream/develop' into icefrog
aurexav Jan 15, 2020
fbc18dc
fix: #242
aurexav Jan 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

export PATH=$PATH:$HOME/.cargo/bin

rustfmt --version &>/dev/null
if [ $? != 0 ]; then
printf "[pre_commit] [ERROR] \"rustfmt\" not available. \n"
printf "[pre_commit] [ERROR] rustfmt can be installed via - \n"
printf "[pre_commit] $ rustup component add rustfmt \n"
exit 1
fi


problem_files=()

# first collect all the files that need reformatting
for file in $(git diff --name-only --cached); do
if [ ${file: -3} == ".rs" ]; then
rustfmt --check $file
if [ $? != 0 ]; then
problem_files+=($file)
fi
fi
done

if [ ${#problem_files[@]} != 0 ]; then
printf "[pre_commit] [ERROR] Plaese format the files via -\n"
printf "[pre_commit] $ cargo fmt --all \n"
printf "[pre_commit] [ERROR] If you want to keep your format with special reason, \n"
printf "[pre_commit] [ERROR] you can use this macro. \n"
printf "[pre_commit] #[rustfmt::skip] \n"
exit 1
fi

printf "[pre_commit] [SUCCESS] rustfmt ok \n"

exit 0
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ env:
global:
- RUST_BACKTRACE=1
matrix:
- RUST_TOOLCHAIN=nightly TARGET=rustfmt
- RUST_TOOLCHAIN=nightly TARGET=wasm
- RUST_TOOLCHAIN=nightly TARGET=native

Expand All @@ -26,4 +27,4 @@ script:

after_script:
# Check how much free disk space left after the build
- df -h
- df -h
2 changes: 1 addition & 1 deletion Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ panic = 'unwind'

[workspace]
members = [
"core/cli",
"core/ethash",
"core/cli",
"core/ethash",
# "core/merkle-mountain-range",
# "core/fly-client",
"core/sr-eth-primitives",
"core/merkle-patricia-trie",

"node/cli",
"node/cli",
"node/executor",
"node/primitives",
"node/rpc",
Expand Down
38 changes: 30 additions & 8 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ image:https://github.com/darwinia-network/rfcs/raw/master/logo/darwinia.png[imag

Darwinia Relay Chain is the hub relay chain connecting different Darwinia AppChains and can be connected to Polkadot as a Polkadot Parachain.

It could have two models, the Solo model and the Polkadot model. For more details, go to https://github.com/darwinia-network/rfcs/blob/master/zh_CN/0007-dawinia-token-staking-model.md#solo%E6%A8%A1%E5%BC%8F[RFC-0007].
It could have two models, the Solo model and the Polkadot model. For more details, go to https://github.com/darwinia-network/rfcs/blob/master/RFC/zh_CN/0007-dawinia-token-staking-model.md#solo%E6%A8%A1%E5%BC%8F[RFC-0007].

== Architecture

Expand Down Expand Up @@ -53,7 +53,8 @@ Darwinia Network provides game developers the scalability, cross-chain interoper
=== Hacking on Darwinia

If you'd actually like to hack on Darwinia, you can just grab the source code and
build it. Ensure you have Rust and the support software installed:
build it. We also provide the script to help you setup your developing environment in bellow sections.
Please ensure you have Rust and the support software installed:

==== Linux and Mac

Expand Down Expand Up @@ -223,13 +224,21 @@ Each project can be skipped individually by using the environment variable `SKIP
Where `PROJECT_NAME` needs to be replaced by the name of the cargo project, e.g. `node-runtime` will
be `NODE_RUNTIME`.

=== Precautions

If you run into problems when building this project,
please kindly check following things before making an issue.

* using the latest nightly Rust
* build without `sccache`

== Joining the IceFrog Testnet

// Latest known working version: ``

=== Quick start (professional):
* https://telemetry.polkadot.io/#list/Darwinia%20IceFrog%20Testnet[Telemetry]
* https://testnet-wallet.darwinia.network[Darwinia Web Wallet]
* https://icefrog-wallet.darwinia.network[Darwinia Web Wallet]
* Bootnodes:
** `/ip4/45.249.244.33/tcp/20222/p2p/QmPCSb9yCRAXnqvG6AnX27X6gutvVDq4NBPDNJtnBmNk43`
** `/ip4/121.199.60.87/tcp/20222/p2p/QmaRDRZZpmY9FwjSwW8JhfkyaHc6XRHsLWnp6cLtyb3FCF`
Expand Down Expand Up @@ -308,18 +317,21 @@ curl -H 'Content-Type: application/json' --data '{ "jsonrpc":"2.0", "method":"au
You can generate documentation for a Darwinia Rust package and have it automatically open in your web browser using https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html#using-rustdoc-with-cargo[rustdoc with Cargo],
(of the The Rustdoc Book), by running the following command:

```
cargo doc --open
```

If you just want to generate document from specific package, you may use following command:

```
cargo doc --package <spec> --open
```

Replacing `<spec>` with one of the following (i.e. `cargo doc --package darwinia --open`):
Replacing `<spec>` with one of the following (i.e. `cargo doc --package darwinia-cli --open`):

* All Darwinia Packages
[source, shell]
darwinia
* Darwinia Core
[source, shell]
darwinia, darwinia-cli, ethash, fly-client,
darwinia-cli, ethash, fly-client,
merkle-mountain-range, merkle-patricia-trie, sr-eth-primitives
* Darwinia Runtime Module Library
[source, shell]
Expand All @@ -331,6 +343,16 @@ node-cli, node-executor, node-primitives, node-rpc, node-rpc-client, node-runtim

== Contributing

=== Environment

The `scripts/bootstrap.sh` help set up your develop environment.
The nightly `Rust`, `cargo`, `rustfmt` will be installed,
the git hooks will be set, and ready to code.

Besides, the script will install some essential packages depends on your OS,
if you want to do it manually, use the `--fast` option to skip.
We will appreciate your contribution.

=== Contributing Guidelines

link:CONTRIBUTING.adoc[CONTRIBUTING.adoc]
Expand Down
7 changes: 5 additions & 2 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ cargo --version
rustc --version

case $TARGET in
"native")
"rustfmt")
sudo apt-get -y update
sudo apt-get install -y cmake pkg-config libssl-dev
cargo fmt --all
;;

"native")
# Unit test
cargo test --release --all --locked "$@"
;;
Expand All @@ -28,4 +31,4 @@ case $TARGET in
# Build test
cargo build --locked "$@"
;;
esac
esac
2 changes: 1 addition & 1 deletion node/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "node-cli"
version = "0.4.6"
version = "0.4.7"
authors = ["Darwinia Network <[email protected]>"]
description = "Darwinia node implementation in Rust."
build = "build.rs"
Expand Down
2 changes: 1 addition & 1 deletion node/cli/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Substrate Node CLI
//! Darwinia

#![warn(missing_docs)]

Expand Down
2 changes: 1 addition & 1 deletion node/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Substrate CLI library.
//! Darwinia CLI library.

#![warn(missing_docs)]
#![warn(unused_extern_crates)]
Expand Down
4 changes: 2 additions & 2 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node"),
impl_name: create_runtime_str!("darwinia-node"),
authoring_version: 3,
spec_version: 83,
impl_version: 83,
spec_version: 84,
impl_version: 84,
apis: RUNTIME_API_VERSIONS,
};

Expand Down
66 changes: 66 additions & 0 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
#
# The script help you set up your develop envirnment
#
# --fast: fast mode will skip OS pacakge dependency, only install git hooks and Rust
#

if [[ "$1" != "--fast" ]]; then
if [[ "$OSTYPE" == "linux-gnu" ]]; then
set -e
if [ -f /etc/redhat-release ]; then
echo "Redhat Linux detected, but current not support sorry."
echo "Contribution is always welcome."
exit 1
elif [ -f /etc/SuSE-release ]; then
echo "Suse Linux detected, but current not support sorry."
echo "Contribution is always welcome."
exit 1
elif [ -f /etc/arch-release ]; then
echo "Arch Linux detected."
sudo pacman -Syu --needed --noconfirm cmake gcc openssl-1.0 clang llvm rocksdb curl
export OPENSSL_LIB_DIR="/usr/lib/openssl-1.0";
export OPENSSL_INCLUDE_DIR="/usr/include/openssl-1.0"
elif [ -f /etc/mandrake-release ]; then
echo "Mandrake Linux detected, but current not support sorry."
echo "Contribution is always welcome."
exit 1
elif [ -f /etc/debian_version ]; then
echo "Ubuntu/Debian Linux detected."
sudo apt-get -y update
sudo apt-get install -y cmake pkg-config libssl-dev
else
echo "Unknown Linux distribution."
echo "Contribution is always welcome."
exit 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
set -e
echo "Mac OS (Darwin) detected."
if ! which brew >/dev/null 2>&1; then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
brew upgrade
brew install openssl cmake llvm
elif [[ "$OSTYPE" == "freebsd"* ]]; then
echo "FreeBSD detected, but current not support sorry."
echo "Contribution is always welcome."
exit 1
else
echo "Unknown operating system."
echo "Contribution is always welcome."
exit 1
fi
fi

# Setup git hooks
cp .hooks/* .git/hooks

# Install nightly Rust
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=nightly -y

# Install wasm toolchain
rustup target add wasm32-unknown-unknown

# Install rustfmt for coding style checking
rustup component add rustfmt --toolchain nightly
6 changes: 3 additions & 3 deletions srml/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ decl_module! {
#[weight = SimpleDispatchInfo::FreeOperational]
fn force_new_era(origin) {
ensure_root(origin)?;
ForceEra::put(Forcing::ForceNone);
ForceEra::put(Forcing::ForceNew);
}

/// Set the validators who cannot be slashed (if any).
Expand Down Expand Up @@ -1163,7 +1163,7 @@ impl<T: Trait> Module<T> {
ledger
}

// TODO: doc
// update the ledger while bonding ring and compute the kton should return
fn bond_helper_in_ring(
stash: &T::AccountId,
controller: &T::AccountId,
Expand Down Expand Up @@ -1217,7 +1217,7 @@ impl<T: Trait> Module<T> {
Self::update_ledger(&controller, &mut ledger, StakingBalances::RingBalance(value));
}

// TODO: doc
// update the ledger while bonding controller with kton
fn bond_helper_in_kton(
controller: &T::AccountId,
value: KtonBalance<T>,
Expand Down
21 changes: 17 additions & 4 deletions srml/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,14 +480,27 @@ pub fn start_era(era_index: EraIndex) {
assert_eq!(Staking::current_era(), era_index);
}


pub fn current_total_payout_for_duration(duration: u64) -> Balance {
inflation::compute_total_payout::<Test>(
duration.saturated_into::<Moment>(),
duration.saturated_into::<Moment>(),
(Timestamp::now() - <mock::Test as Trait>::GenesisTime::get()).saturated_into::<Moment>(),
(<mock::Test as Trait>::Cap::get() - Ring::total_issuance()).saturated_into::<Balance>(),
Perbill::from_percent(50)
).0
Perbill::from_percent(50),
)
.0
}

pub fn compute_power(ring_amount: u128, kton_amount: u128) -> Power {
fn calc_power<S: rstd::convert::TryInto<u128>>(active: S, pool: S) -> Power {
const HALF_POWER_COUNT: u128 = 1_000_000_000 / 2;

Perquintill::from_rational_approximation(
active.saturated_into::<Power>(),
pool.saturated_into::<Power>().max(1),
) * HALF_POWER_COUNT
}

calc_power(ring_amount, Staking::ring_pool()) + calc_power(kton_amount, Staking::kton_pool())
}

pub fn reward_all_elected() {
Expand Down
Loading