Skip to content

Commit

Permalink
Merge pull request #207 from AurevoirXavier/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
hackfisher authored Dec 27, 2019
2 parents 144a29c + 1cd25e7 commit 2732fbb
Show file tree
Hide file tree
Showing 16 changed files with 181 additions and 143 deletions.
10 changes: 6 additions & 4 deletions rustfmt.toml → .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
max_width = 120
tab_spaces = 4
hard_tabs = true
reorder_imports = true
reorder_modules = true
use_try_shorthand = true
hard_tabs = true
use_field_init_shorthand = true

max_width = 120
tab_spaces = 4

newline_style = "Unix"
34 changes: 15 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,27 @@
sudo: true
language: minimal

cache:
cargo: true
directories:
- $HOME/build/darwinia-network/darwinia/node/runtime/wasm/target/wasm32-unknown-unknown/release
cache: cargo

branches:
only:
- master
only:
- master
- develop

env:
global:
- RUST_BACKTRACE=1
global:
- RUST_BACKTRACE=1
matrix:
- RUST_TOOLCHAIN=nightly TARGET=wasm
- RUST_TOOLCHAIN=nightly TARGET=native

before_install:
# Check how much space we've got on this machine.
- df -h
- ls $HOME/build/darwinia-network/darwinia/node/runtime/wasm/target/wasm32-unknown-unknown/release
# Check how much space we've got on this machine.
- df -h

jobs:
include:
- stage: Install
script: ./ci/script.sh nightly wasm
- stage: Test
script: ./ci/script.sh stable native
script:
- ./ci/script.sh

after_script:
# Check how much free disk space left after the build
- df -h
# Check how much free disk space left after the build
- df -h
3 changes: 3 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
:toc:
:sectnums:

image:https://travis-ci.org/AurevoirXavier/darwinia.svg[Build Status (Travis CI),link=https://travis-ci.org/AurevoirXavier/darwinia]
image:https://img.shields.io/badge/License-Apache%202.0-blue.svg[License,link=https://opensource.org/licenses/Apache-2.0]

== Darwinia Relay Chain

image:https://github.com/darwinia-network/rfcs/raw/master/logo/darwinia.png[image]
Expand Down
17 changes: 10 additions & 7 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@
set -eux

# Install rustup and the specified rust toolchain.
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=$1 -y
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=$RUST_TOOLCHAIN -y

# Load cargo environment. Specifically, put cargo into PATH.
source ~/.cargo/env

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

rustup --version
cargo --version
rustc --version

case $2 in
case $TARGET in
"native")
sudo apt-get -y update
sudo apt-get install -y cmake pkg-config libssl-dev

cargo test --all --locked
# Unit test
cargo test --release --all --locked "$@"
;;

"wasm")
# Install prerequisites and build all wasm projects
./init.sh
./build.sh --locked
# Build test
cargo build --locked "$@"
;;
esac
54 changes: 27 additions & 27 deletions core/ethash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,31 +330,31 @@ mod tests {
);
}

#[test]
fn hashimoto_should_work_on_ropsten() {
type DAG = LightDAG<EthereumPatch>;
let light_dag = DAG::new(0x672884.into());
let partial_header_hash = H256::from(hex!("9cb3d16b788bfc7f2569db2d1fedb5b1e9633acfe84a4eca44a9fa50979a9887"));
let mixh = light_dag
.hashimoto(partial_header_hash, H64::from(hex!("9348d06003756cff")))
.0;
assert_eq!(
mixh,
H256::from(hex!("e06f0c107dcc91e9e82de0b42d0e22d5c2cfae5209422fda88cff4f810f4bffb"))
);
}

#[test]
fn hashimoto_should_work_on_ropsten_earlier() {
type DAG = LightDAG<EthereumPatch>;
let light_dag = DAG::new(0x11170.into());
let partial_header_hash = H256::from(hex!("bb698ea6e304a7a88a6cd8238f0e766b4f7bf70dc0869bd2e4a76a8e93fffc80"));
let mixh = light_dag
.hashimoto(partial_header_hash, H64::from(hex!("475ddd90b151f305")))
.0;
assert_eq!(
mixh,
H256::from(hex!("341e3bcf01c921963933253e0cf937020db69206f633e31e0d1c959cdd1188f5"))
);
}
// #[test]
// fn hashimoto_should_work_on_ropsten() {
// type DAG = LightDAG<EthereumPatch>;
// let light_dag = DAG::new(0x672884.into());
// let partial_header_hash = H256::from(hex!("9cb3d16b788bfc7f2569db2d1fedb5b1e9633acfe84a4eca44a9fa50979a9887"));
// let mixh = light_dag
// .hashimoto(partial_header_hash, H64::from(hex!("9348d06003756cff")))
// .0;
// assert_eq!(
// mixh,
// H256::from(hex!("e06f0c107dcc91e9e82de0b42d0e22d5c2cfae5209422fda88cff4f810f4bffb"))
// );
// }
//
// #[test]
// fn hashimoto_should_work_on_ropsten_earlier() {
// type DAG = LightDAG<EthereumPatch>;
// let light_dag = DAG::new(0x11170.into());
// let partial_header_hash = H256::from(hex!("bb698ea6e304a7a88a6cd8238f0e766b4f7bf70dc0869bd2e4a76a8e93fffc80"));
// let mixh = light_dag
// .hashimoto(partial_header_hash, H64::from(hex!("475ddd90b151f305")))
// .0;
// assert_eq!(
// mixh,
// H256::from(hex!("341e3bcf01c921963933253e0cf937020db69206f633e31e0d1c959cdd1188f5"))
// );
// }
}
2 changes: 1 addition & 1 deletion core/merkle-patricia-trie/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod tests {
#[test]
fn test_encode_decode() {
let nodes = vec![vec![0u8], vec![1], vec![2]];
let expected = Proof { nodes: nodes };
let expected = Proof { nodes };
let rlp_proof = rlp::encode(&expected);
let out_proof: Proof = rlp::decode(&rlp_proof).unwrap();
println!("{:?}", out_proof);
Expand Down
8 changes: 4 additions & 4 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ pub fn darwinia_genesis(
eth_backing: Some(EthBackingConfig {
ring_redeem_address: hex!["dbc888d701167cbfb86486c516aafbefc3a4de6e"].into(),
kton_redeem_address: hex!["dbc888d701167cbfb86486c516aafbefc3a4de6e"].into(),
deposit_redeem_address: hex!["ad52e0f67b6f44cd5b9a6f4fbc7c0f78f37e094b"].into(),
ring_locked: 2000000000,
kton_locked: 50000,
deposit_redeem_address: hex!["6ef538314829efa8386fc43386cb13b4e0a67d1e"].into(),
ring_locked: 2_000_000_000 * COIN,
kton_locked: 50_000 * COIN,
..Default::default()
}),
}
Expand Down Expand Up @@ -334,7 +334,7 @@ pub fn local_testnet_config() -> ChainSpec {
)
}

/// crayfish testnet config (multivalidator Alice + Bob)
/// IceFrog testnet config (multivalidator Alice + Bob)
pub fn icefrog_testnet_config() -> ChainSpec {
fn icefrog_config_genesis() -> GenesisConfig {
darwinia_genesis(
Expand Down
2 changes: 1 addition & 1 deletion node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ macro_rules! new_full {
(true, false) => {
// start the full GRANDPA voter
let grandpa_config = grandpa::GrandpaParams {
config: config,
config,
link: grandpa_link,
network: service.network(),
inherent_data_providers: inherent_data_providers.clone(),
Expand Down
3 changes: 2 additions & 1 deletion node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ impl<T: Get<Perbill>> Convert<Fixed64, Fixed64> for TargetedFeeAdjustment<T> {
} else {
// Proof: first_term > second_term. Safe subtraction.
let negative = first_term - second_term;
multiplier.saturating_sub(negative)
multiplier
.saturating_sub(negative)
// despite the fact that apply_to saturates weight (final fee cannot go below 0)
// it is crucially important to stop here and don't further reduce the weight fee
// multiplier. While at -1, it means that the network is so un-congested that all
Expand Down
2 changes: 1 addition & 1 deletion srml/balances/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ fn balance_transfer_works() {
fn force_transfer_works() {
ExtBuilder::default().build().execute_with(|| {
let _ = Balances::deposit_creating(&1, 111);
assert_noop!(Balances::force_transfer(Some(2).into(), 1, 2, 69), "RequireRootOrigin",);
assert_noop!(Balances::force_transfer(Some(2).into(), 1, 2, 69), "RequireRootOrigin");
assert_ok!(Balances::force_transfer(RawOrigin::Root.into(), 1, 2, 69));
assert_eq!(Balances::total_balance(&1), 42);
assert_eq!(Balances::total_balance(&2), 69);
Expand Down
4 changes: 2 additions & 2 deletions srml/eth-backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ decl_module! {
],
anonymous: false,
};
let log_entry = verified_receipt.
logs
let log_entry = verified_receipt
.logs
.iter()
.find(|&x| x.address == Self::deposit_redeem_address() && x.topics[0] == eth_event.signature())
.ok_or("Log Entry - NOT FOUND")?;
Expand Down
2 changes: 1 addition & 1 deletion srml/eth-relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use codec::{Decode, Encode};
use rstd::{result, vec::Vec};
use sr_primitives::RuntimeDebug;
use support::{decl_event, decl_module, decl_storage, dispatch::Result, ensure, traits::Get};
use system::{ensure_signed, ensure_root};
use system::{ensure_root, ensure_signed};

use ethash::{EthereumPatch, LightDAG};
use merkle_patricia_trie::{trie::Trie, MerklePatriciaTrie, Proof};
Expand Down
8 changes: 5 additions & 3 deletions srml/im-online/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ use rstd::convert::TryInto;
use rstd::prelude::*;
use session::historical::IdentificationTuple;
use sr_primitives::{
traits::{Convert, Member, Printable},
traits::{Convert, Member, Printable, Saturating},
transaction_validity::{InvalidTransaction, TransactionPriority, TransactionValidity, ValidTransaction},
Perbill, RuntimeDebug,
};
Expand Down Expand Up @@ -626,7 +626,9 @@ impl<Offender: Clone> Offence<Offender> for UnresponsivenessOffence<Offender> {
self.session_index
}

fn slash_fraction(_offenders: u32, _validator_set_count: u32) -> Perbill {
Perbill::from_percent(5)
fn slash_fraction(offenders: u32, validator_set_count: u32) -> Perbill {
// the formula is min((3 * max((k - 1), 1)) / n, 1) * 0.05
let x = Perbill::from_rational_approximation(3 * (offenders - 1).max(1), validator_set_count);
x.saturating_mul(Perbill::from_percent(5))
}
}
34 changes: 15 additions & 19 deletions srml/im-online/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
use std::cell::RefCell;

use crate::{Module, Trait};
use sr_primitives::Perbill;
use sr_staking_primitives::{SessionIndex, offence::ReportOffence};
use sr_primitives::testing::{Header, UintAuthorityId, TestXt};
use sr_primitives::traits::{IdentityLookup, BlakeTwo256, ConvertInto};
use primitives::H256;
use support::{impl_outer_origin, impl_outer_dispatch, parameter_types};
use sr_primitives::testing::{Header, TestXt, UintAuthorityId};
use sr_primitives::traits::{BlakeTwo256, ConvertInto, IdentityLookup};
use sr_primitives::Perbill;
use sr_staking_primitives::{offence::ReportOffence, SessionIndex};
use support::{impl_outer_dispatch, impl_outer_origin, parameter_types};
use {runtime_io, system};

impl_outer_origin!{
impl_outer_origin! {
pub enum Origin for Runtime {}
}

Expand All @@ -45,25 +45,22 @@ thread_local! {

pub struct TestOnSessionEnding;
impl session::OnSessionEnding<u64> for TestOnSessionEnding {
fn on_session_ending(_ending_index: SessionIndex, _will_apply_at: SessionIndex)
-> Option<Vec<u64>>
{
fn on_session_ending(_ending_index: SessionIndex, _will_apply_at: SessionIndex) -> Option<Vec<u64>> {
VALIDATORS.with(|l| l.borrow_mut().take())
}
}

impl session::historical::OnSessionEnding<u64, u64> for TestOnSessionEnding {
fn on_session_ending(_ending_index: SessionIndex, _will_apply_at: SessionIndex)
-> Option<(Vec<u64>, Vec<(u64, u64)>)>
{
VALIDATORS.with(|l| l
.borrow_mut()
.take()
.map(|validators| {
fn on_session_ending(
_ending_index: SessionIndex,
_will_apply_at: SessionIndex,
) -> Option<(Vec<u64>, Vec<(u64, u64)>)> {
VALIDATORS.with(|l| {
l.borrow_mut().take().map(|validators| {
let full_identification = validators.iter().map(|v| (*v, *v)).collect();
(validators, full_identification)
})
)
})
}
}

Expand All @@ -90,7 +87,6 @@ pub fn new_test_ext() -> runtime_io::TestExternalities {
t.into()
}


#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Runtime;

Expand Down Expand Up @@ -131,7 +127,7 @@ parameter_types! {
impl session::Trait for Runtime {
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
type OnSessionEnding = session::historical::NoteHistoricalRoot<Runtime, TestOnSessionEnding>;
type SessionHandler = (ImOnline, );
type SessionHandler = (ImOnline,);
type ValidatorId = u64;
type ValidatorIdOf = ConvertInto;
type Keys = UintAuthorityId;
Expand Down
Loading

0 comments on commit 2732fbb

Please sign in to comment.