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

withdraw Ring/Kton automatically #92

Merged
merged 32 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f3b316c
update: change `LockableCurrency::Moment` from `BlockNumber` to `Time…
AurevoirXavier Nov 14, 2019
aad5db0
update: kton tests
AurevoirXavier Nov 14, 2019
1de2b6c
update: `LockableCurrency::Moment` support generic Type
AurevoirXavier Nov 14, 2019
9cf10b6
update: new design for `LockableCurrency`
AurevoirXavier Nov 14, 2019
ff7d278
Merge remote-tracking branch 'upstream/develop' into chainrelay
AurevoirXavier Nov 15, 2019
d0cc605
update: new design for `LockableCurrency`
AurevoirXavier Nov 15, 2019
554fa7d
fix: typo
AurevoirXavier Nov 15, 2019
0272998
update: new `LockableCurrency` design
AurevoirXavier Nov 15, 2019
3f5119f
update: withdraw Ring/Kton automatically
AurevoirXavier Nov 18, 2019
a7885eb
update: ok with `set_lock`
AurevoirXavier Nov 18, 2019
0f26ef0
update: now, we can update the staking ledger after `remove_lock`
AurevoirXavier Nov 18, 2019
ad5028d
update: more powerful lock
AurevoirXavier Nov 19, 2019
4fdd232
update: move `ensure_can_withdraw` logic to `LockableCurrency`'s `can…
AurevoirXavier Nov 19, 2019
9554a52
update: move `ensure_can_withdraw` logic to `LockableCurrency`'s `can…
AurevoirXavier Nov 19, 2019
7f0ed10
fix: doc
AurevoirXavier Nov 19, 2019
dc95b8a
update: remove check overflow/underflow
AurevoirXavier Nov 19, 2019
6a51c51
add: Ring test
AurevoirXavier Nov 19, 2019
171c023
add: `is_empty` for `CompositeLock`
AurevoirXavier Nov 19, 2019
b9f12a7
hanging: bakcup
AurevoirXavier Nov 19, 2019
c69838e
hanging: hanging
AurevoirXavier Nov 19, 2019
4f39b0d
fix: pass `cargo fmt`
AurevoirXavier Nov 20, 2019
c2642a5
remove: unused macro
AurevoirXavier Nov 20, 2019
425099b
update: new `LockableCurrency` design
AurevoirXavier Nov 20, 2019
85291fd
Merge remote-tracking branch 'upstream/develop' into chainrelay
AurevoirXavier Nov 20, 2019
85966d4
add: tests for Ring
AurevoirXavier Nov 20, 2019
1698c2c
update: compare condition
AurevoirXavier Nov 20, 2019
912c9d5
fix: missing `PartialEq`
AurevoirXavier Nov 20, 2019
f9cdfc9
update: `Locks` storage accept a `Locks` struct which implement `Lock…
AurevoirXavier Nov 20, 2019
e13138b
rename: `ensure_can_withdraw` to `can_withdraw`
AurevoirXavier Nov 20, 2019
be17217
remove: phragmen
AurevoirXavier Nov 20, 2019
695d740
add: BONDING_DURATION_ERA_TO_SECS_RATIO
AurevoirXavier Nov 20, 2019
3b9c1a1
rename: `update_lock` to `update_locks`
AurevoirXavier Nov 20, 2019
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
23 changes: 16 additions & 7 deletions 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 @@ -75,11 +75,11 @@ members = [

"srml/support",

"srml/chainrelay/bridge/eos",
"srml/chainrelay/bridge/ethereum",

"srml/balances",
"srml/kton",
"srml/staking",

"srml/chainrelay/bridge/ethereum",
]

exclude = ["node/runtime/wasm"]
Expand Down
7 changes: 3 additions & 4 deletions core/sr-rlp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RLP lib for eth transaction encoding

/// RLP lib for eth transaction encoding

#![recursion_limit = "128"]
#![cfg_attr(not(feature = "std"), no_std)]
//#![recursion_limit = "128"]
//#![cfg_attr(not(feature = "std"), no_std)]
3 changes: 2 additions & 1 deletion node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ runtime-io = { package = "sr-io", git = 'https://github.com/darwinia-network/sub
client = { package = "substrate-client", git = 'https://github.com/darwinia-network/substrate.git' }
primitives = { package = "substrate-primitives", git = 'https://github.com/darwinia-network/substrate.git' }
inherents = { package = "substrate-inherents", git = 'https://github.com/darwinia-network/substrate.git' }
node-runtime = { path = "../runtime" }
node-primitives = { path = "../primitives" }
hex-literal = "0.2.1"
substrate-basic-authorship = { git = 'https://github.com/darwinia-network/substrate.git' }
Expand Down Expand Up @@ -60,6 +59,8 @@ sr-authority-discovery = { package = "srml-authority-discovery", git = 'https://
authority-discovery = { package = "substrate-authority-discovery", git = 'https://github.com/darwinia-network/substrate.git' }
offchain = { package = "substrate-offchain", git = 'https://github.com/darwinia-network/substrate.git' }

node-runtime = { path = "../runtime" }

[dev-dependencies]
consensus-common = { package = "substrate-consensus-common", git = 'https://github.com/darwinia-network/substrate.git' }
service-test = { package = "substrate-service-test", git = 'https://github.com/darwinia-network/substrate.git' }
Expand Down
91 changes: 45 additions & 46 deletions node/cli/src/factory_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@
//! using the cli to manufacture transactions and distribute them
//! to accounts.

use rand::{Rng, SeedableRng};
use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};

use codec::{Encode, Decode};
use codec::{Decode, Encode};
use finality_tracker;
use inherents::InherentData;
use keyring::sr25519::Keyring;
use node_primitives::Signature;
use node_runtime::{
Call, CheckedExtrinsic, UncheckedExtrinsic, SignedExtra, BalancesCall, ExistentialDeposit,
MinimumPeriod
BalancesCall, Call, CheckedExtrinsic, ExistentialDeposit, MinimumPeriod, SignedExtra, UncheckedExtrinsic,
};
use node_primitives::Signature;
use primitives::{sr25519, crypto::Pair};
use primitives::{crypto::Pair, sr25519};
use sr_primitives::{
generic::Era, traits::{Block as BlockT, Header as HeaderT, SignedExtension, Verify, IdentifyAccount}
generic::Era,
traits::{Block as BlockT, Header as HeaderT, IdentifyAccount, SignedExtension, Verify},
};
use transaction_factory::RuntimeAdapter;
use transaction_factory::modes::Mode;
use inherents::InherentData;
use timestamp;
use finality_tracker;
use transaction_factory::modes::Mode;
use transaction_factory::RuntimeAdapter;

type AccountPublic = <Signature as Verify>::Signer;

Expand Down Expand Up @@ -77,11 +77,7 @@ impl RuntimeAdapter for FactoryState<Number> {

type Number = Number;

fn new(
mode: Mode,
num: u64,
rounds: u64,
) -> FactoryState<Self::Number> {
fn new(mode: Mode, num: u64, rounds: u64) -> FactoryState<Self::Number> {
FactoryState {
mode,
num: num as u32,
Expand Down Expand Up @@ -145,24 +141,28 @@ impl RuntimeAdapter for FactoryState<Number> {
) -> <Self::Block as BlockT>::Extrinsic {
let index = self.extract_index(&sender, prior_block_hash);
let phase = self.extract_phase(*prior_block_hash);
sign::<Self>(CheckedExtrinsic {
signed: Some((sender.clone(), Self::build_extra(index, phase))),
function: Call::Balances(
BalancesCall::transfer(
sign::<Self>(
CheckedExtrinsic {
signed: Some((sender.clone(), Self::build_extra(index, phase))),
function: Call::Balances(BalancesCall::transfer(
indices::address::Address::Id(destination.clone().into()),
(*amount).into()
)
)
}, key, (version, genesis_hash.clone(), prior_block_hash.clone(), (), (), (), ()))
(*amount).into(),
)),
},
key,
(version, genesis_hash.clone(), prior_block_hash.clone(), (), (), (), ()),
)
}

fn inherent_extrinsics(&self) -> InherentData {
let timestamp = (self.block_no as u64 + 1) * MinimumPeriod::get();

let mut inherent = InherentData::new();
inherent.put_data(timestamp::INHERENT_IDENTIFIER, &timestamp)
inherent
.put_data(timestamp::INHERENT_IDENTIFIER, &timestamp)
.expect("Failed putting timestamp inherent");
inherent.put_data(finality_tracker::INHERENT_IDENTIFIER, &self.block_no)
inherent
.put_data(finality_tracker::INHERENT_IDENTIFIER, &self.block_no)
.expect("Failed putting finalized number inherent");
inherent
}
Expand Down Expand Up @@ -191,11 +191,7 @@ impl RuntimeAdapter for FactoryState<Number> {
pair
}

fn extract_index(
&self,
_account_id: &Self::AccountId,
_block_hash: &<Self::Block as BlockT>::Hash,
) -> Self::Index {
fn extract_index(&self, _account_id: &Self::AccountId, _block_hash: &<Self::Block as BlockT>::Hash) -> Self::Index {
// TODO get correct index for account via api. See #2587.
// This currently prevents the factory from being used
// without a preceding purge of the database.
Expand All @@ -204,20 +200,21 @@ impl RuntimeAdapter for FactoryState<Number> {
} else {
match self.round() {
0 =>
// if round is 0 all transactions will be done with master as a sender
self.block_no() as Self::Index,
// if round is 0 all transactions will be done with master as a sender
{
self.block_no() as Self::Index
}
_ =>
// if round is e.g. 1 every sender account will be new and not yet have
// any transactions done
// if round is e.g. 1 every sender account will be new and not yet have
// any transactions done
{
0
}
}
}
}

fn extract_phase(
&self,
_block_hash: <Self::Block as BlockT>::Hash
) -> Self::Phase {
fn extract_phase(&self, _block_hash: <Self::Block as BlockT>::Hash) -> Self::Phase {
// TODO get correct phase via api. See #2587.
// This currently prevents the factory from being used
// without a preceding purge of the database.
Expand Down Expand Up @@ -245,13 +242,15 @@ fn sign<RA: RuntimeAdapter>(
let s = match xt.signed {
Some((signed, extra)) => {
let payload = (xt.function, extra.clone(), additional_signed);
let signature = payload.using_encoded(|b| {
if b.len() > 256 {
key.sign(&runtime_io::hashing::blake2_256(b))
} else {
key.sign(b)
}
}).into();
let signature = payload
.using_encoded(|b| {
if b.len() > 256 {
key.sign(&runtime_io::hashing::blake2_256(b))
} else {
key.sign(b)
}
})
.into();
UncheckedExtrinsic {
signature: Some((indices::address::Address::Id(signed), signature, extra)),
function: payload.0,
Expand Down
56 changes: 24 additions & 32 deletions node/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ where
ParseAndPrepare::Run(cmd) => cmd.run(
load_spec,
exit,
|exit, _cli_args, _custom_args, config: Config<_,_>| {
|exit, _cli_args, _custom_args, config: Config<_, _>| {
info!("{}", version.name);
info!(" version {}", config.full_version());
info!(" _____ _ _ ");
Expand All @@ -180,37 +180,31 @@ where
info!("Chain specification: {}", config.chain_spec.name());
info!("Node name: {}", config.name);
info!("Roles: {:?}", cli::display_role(&config));
let runtime = RuntimeBuilder::new().name_prefix("main-tokio-").build()
let runtime = RuntimeBuilder::new()
.name_prefix("main-tokio-")
.build()
.map_err(|e| format!("{:?}", e))?;
match config.roles {
ServiceRoles::LIGHT => run_until_exit(
runtime,
service::new_light(config)?,
exit
),
_ => run_until_exit(
runtime,
service::new_full(config)?,
exit
),
ServiceRoles::LIGHT => run_until_exit(runtime, service::new_light(config)?, exit),
_ => run_until_exit(runtime, service::new_full(config)?, exit),
}
},
),

ParseAndPrepare::BuildSpec(cmd) => cmd.run::<NoCustom, _, _, _>(load_spec),
ParseAndPrepare::ExportBlocks(cmd) => cmd.run_with_builder(|config: Config<_,_>|
Ok(new_full_start!(config).0), load_spec, exit),
ParseAndPrepare::ImportBlocks(cmd) => cmd.run_with_builder(|config: Config<_,_>|
Ok(new_full_start!(config).0), load_spec, exit),
ParseAndPrepare::ExportBlocks(cmd) => {
cmd.run_with_builder(|config: Config<_, _>| Ok(new_full_start!(config).0), load_spec, exit)
}
ParseAndPrepare::ImportBlocks(cmd) => {
cmd.run_with_builder(|config: Config<_, _>| Ok(new_full_start!(config).0), load_spec, exit)
}
ParseAndPrepare::PurgeChain(cmd) => cmd.run(load_spec),
ParseAndPrepare::RevertChain(cmd) => cmd.run_with_builder(|config: Config<_,_>|
Ok(new_full_start!(config).0), load_spec),
ParseAndPrepare::RevertChain(cmd) => {
cmd.run_with_builder(|config: Config<_, _>| Ok(new_full_start!(config).0), load_spec)
}
ParseAndPrepare::CustomCommand(CustomSubcommands::Factory(cli_args)) => {
let mut config: Config<_, _> = cli::create_config_with_db_path(
load_spec,
&cli_args.shared_params,
&version,
)?;
let mut config: Config<_, _> =
cli::create_config_with_db_path(load_spec, &cli_args.shared_params, &version)?;
config.execution_strategies = ExecutionStrategies {
importing: cli_args.execution.into(),
block_construction: cli_args.execution.into(),
Expand All @@ -219,23 +213,21 @@ where
};

match ChainSpec::from(config.chain_spec.id()) {
Some(ref c) if c == &ChainSpec::Development || c == &ChainSpec::LocalTestnet => {},
AurevoirXavier marked this conversation as resolved.
Show resolved Hide resolved
Some(ref c) if c == &ChainSpec::Development || c == &ChainSpec::LocalTestnet => {}
_ => panic!("Factory is only supported for development and local testnet."),
}

let factory_state = FactoryState::new(
cli_args.mode.clone(),
cli_args.num,
cli_args.rounds,
);
let factory_state = FactoryState::new(cli_args.mode.clone(), cli_args.num, cli_args.rounds);

let service_builder = new_full_start!(config).0;
transaction_factory::factory::<FactoryState<_>, _, _, _, _, _>(
factory_state,
service_builder.client(),
service_builder.select_chain()
.expect("The select_chain is always initialized by new_full_start!; QED")
).map_err(|e| format!("Error in transaction factory: {}", e))?;
service_builder
.select_chain()
.expect("The select_chain is always initialized by new_full_start!; QED"),
)
.map_err(|e| format!("Error in transaction factory: {}", e))?;

Ok(())
}
Expand Down
Loading