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 2 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
26 changes: 23 additions & 3 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ members = [

"srml/support",

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

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

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

exclude = ["node/runtime/wasm"]
Expand Down
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
4 changes: 3 additions & 1 deletion node/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ state_machine = { package = "substrate-state-machine", git = 'https://github.com
substrate-executor = { git = 'https://github.com/darwinia-network/substrate.git' }
primitives = { package = "substrate-primitives", git = 'https://github.com/darwinia-network/substrate.git' }
trie = { package = "substrate-trie", git = 'https://github.com/darwinia-network/substrate.git' }

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

Expand All @@ -21,7 +22,6 @@ test-client = { package = "substrate-test-client", git = 'https://github.com/dar
keyring = { package = "substrate-keyring", git = 'https://github.com/darwinia-network/substrate.git' }
runtime_primitives = { package = "sr-primitives", git = 'https://github.com/darwinia-network/substrate.git' }
runtime_support = { package = "srml-support", git = 'https://github.com/darwinia-network/substrate.git' }
balances = { package = "srml-balances",git = 'https://github.com/darwinia-network/substrate.git' }
session = { package = "srml-session", git = 'https://github.com/darwinia-network/substrate.git' }
staking = { package = "darwinia-staking", path = '../../srml/staking' }
system = { package = "srml-system", git = 'https://github.com/darwinia-network/substrate.git' }
Expand All @@ -32,5 +32,7 @@ grandpa = { package = "srml-grandpa", git = 'https://github.com/darwinia-network
indices = { package = "srml-indices", git = 'https://github.com/darwinia-network/substrate.git' }
wabt = "0.9.2"

balances = { package = "darwinia-balances", path = '../../srml/balances', default-features = false }

[features]
benchmarks = []
2 changes: 1 addition & 1 deletion node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ sr-primitives = { git = 'https://github.com/darwinia-network/substrate.git', def
offchain-primitives = { package = "substrate-offchain-primitives", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
version = { package = "sr-version", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
support = { package = "srml-support", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
balances = { package = "srml-balances", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
executive = { package = "srml-executive", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
finality-tracker = { package = "srml-finality-tracker", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
grandpa = { package = "srml-grandpa", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
Expand Down Expand Up @@ -61,6 +60,7 @@ inherents = { package = "substrate-inherents", git = 'https://github.com/darwini

transaction-payment-rpc-runtime-api = { package = "srml-transaction-payment-rpc-runtime-api", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }

balances = { package = "darwinia-balances", path = '../../srml/balances', default-features = false }
kton = { package = "darwinia-kton", path = '../../srml/kton', default-features = false }
staking = { package = "darwinia-staking", path = "../../srml/staking", default-features = false }

Expand Down
58 changes: 19 additions & 39 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
use authority_discovery_primitives::{AuthorityId as EncodedAuthorityId, Signature as EncodedSignature};
use babe_primitives::{AuthorityId as BabeId, AuthoritySignature as BabeSignature};
pub use balances::Call as BalancesCall;
use sr_api::impl_runtime_apis;
use codec::{Decode, Encode};
pub use contracts::Gas;
use sr_api::impl_runtime_apis;

//use grandpa::fg_primitives;
//use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
Expand All @@ -49,24 +49,23 @@ use support::{
};

pub use timestamp::Call as TimestampCall;
use version::RuntimeVersion;
#[cfg(any(feature = "std", test))]

use version::NativeVersion;
use version::RuntimeVersion;

use substrate_primitives::OpaqueMetadata;
use grandpa::AuthorityList as GrandpaAuthorityList;
use grandpa::fg_primitives;
use im_online::sr25519::{AuthorityId as ImOnlineId};
use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
use grandpa::AuthorityList as GrandpaAuthorityList;
use im_online::sr25519::AuthorityId as ImOnlineId;
use substrate_primitives::OpaqueMetadata;
use system::offchain::TransactionSubmitter;
use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;

use staking::EraIndex;
pub use staking::StakerStatus;

/// Implementations of some helper traits passed into runtime modules as associated types.
pub mod impls;
use impls::{CurrencyToVoteHandler, Author, LinearWeightToFee, TargetedFeeAdjustment};
use impls::{Author, CurrencyToVoteHandler, LinearWeightToFee, TargetedFeeAdjustment};

/// Constant values used within the runtime.
pub mod constants;
Expand Down Expand Up @@ -137,7 +136,6 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
pub const Version: RuntimeVersion = VERSION;
}

impl system::Trait for Runtime {
type Origin = Origin;
type Call = Call;
Expand Down Expand Up @@ -173,7 +171,6 @@ parameter_types! {
pub const TransferFee: Balance = 1 * MILLI;
pub const CreationFee: Balance = 1 * MILLI;
}

impl balances::Trait for Runtime {
type Balance = Balance;
type OnFreeBalanceZero = (Staking, Session);
Expand All @@ -194,7 +191,6 @@ parameter_types! {
// for a sane configuration, this should always be less than `AvailableBlockRatio`.
pub const TargetBlockFullness: Perbill = Perbill::from_percent(25);
}

impl transaction_payment::Trait for Runtime {
type Currency = Balances;
type OnTransactionPayment = DealWithFees;
Expand All @@ -208,7 +204,6 @@ parameter_types! {
pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS;
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
}

impl babe::Trait for Runtime {
type EpochDuration = EpochDuration;
type ExpectedBlockTime = ExpectedBlockTime;
Expand All @@ -218,17 +213,12 @@ impl babe::Trait for Runtime {
parameter_types! {
pub const MinimumPeriod: Moment = SLOT_DURATION / 2;
}

impl timestamp::Trait for Runtime {
type Moment = u64;
type OnTimestampSet = Babe;
type MinimumPeriod = MinimumPeriod;
}

parameter_types! {
pub const UncleGenerations: BlockNumber = 5;
}

impl_opaque_keys! {
pub struct SessionKeys {
pub grandpa: Grandpa,
Expand All @@ -237,6 +227,9 @@ impl_opaque_keys! {
}
}

parameter_types! {
pub const UncleGenerations: BlockNumber = 5;
}
impl authorship::Trait for Runtime {
type FindAuthor = session::FindAccountFromAuthorIndex<Self, Babe>;
type UncleGenerations = UncleGenerations;
Expand All @@ -250,17 +243,10 @@ impl authorship::Trait for Runtime {
// TODO: Introduce some structure to tie these together to make it a bit less of a footgun. This
// should be easy, since OneSessionHandler trait provides the `Key` as an associated type. #2858

parameter_types! {
pub const Period: BlockNumber = 1 * MINUTES;
pub const Offset: BlockNumber = 0;
}

type SessionHandlers = (Grandpa, Babe, ImOnline, AuthorityDiscovery);

parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
}

impl session::Trait for Runtime {
type Event = Event;
type ValidatorId = <Self as system::Trait>::AccountId;
Expand All @@ -278,14 +264,6 @@ impl session::historical::Trait for Runtime {
type FullIdentificationOf = staking::ExposureOf<Runtime>;
}

parameter_types! {
pub const SessionsPerEra: sr_staking_primitives::SessionIndex = 5;
// about 14 days
pub const BondingDuration: staking::EraIndex = 4032;
// 365 days * 24 hours * 60 minutes / 5 minutes
pub const ErasPerEpoch: EraIndex = 105120;
}

impl sudo::Trait for Runtime {
type Event = Event;
type Proposal = Call;
Expand All @@ -302,18 +280,16 @@ impl offences::Trait for Runtime {
}

type SubmitTransaction = TransactionSubmitter<ImOnlineId, Runtime, UncheckedExtrinsic>;

parameter_types! {
pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_SLOTS as _;
}

impl im_online::Trait for Runtime {
type AuthorityId = ImOnlineId;
type Event = Event;
type Call = Call;
type SubmitTransaction = SubmitTransaction;
type ReportUnresponsiveness = Offences;
type SessionDuration = SessionDuration;
type ReportUnresponsiveness = Offences;
}

impl authority_discovery::Trait for Runtime {
Expand All @@ -324,7 +300,6 @@ parameter_types! {
pub const WindowSize: BlockNumber = 101;
pub const ReportLatency: BlockNumber = 1000;
}

impl finality_tracker::Trait for Runtime {
type OnFinalizationStalled = Grandpa;
type WindowSize = WindowSize;
Expand All @@ -342,7 +317,6 @@ parameter_types! {
pub const RentDepositOffset: Balance = 1000 * COIN;
pub const SurchargeReward: Balance = 150 * COIN;
}

impl contracts::Trait for Runtime {
type Currency = Balances;
type Time = Timestamp;
Expand Down Expand Up @@ -410,10 +384,16 @@ impl kton::Trait for Runtime {
}

parameter_types! {
pub const Period: BlockNumber = 1 * MINUTES;
// pub const Offset: BlockNumber = 0;
pub const SessionsPerEra: sr_staking_primitives::SessionIndex = 5;
// about 14 days
pub const BondingDuration: staking::EraIndex = 4032;
// 365 days * 24 hours * 60 minutes / 5 minutes
pub const ErasPerEpoch: EraIndex = 105120;
// decimal 9
pub const CAP: Balance = 10_000_000_000 * COIN;
}

impl staking::Trait for Runtime {
type Ring = Balances;
type Kton = Kton;
Expand Down Expand Up @@ -449,7 +429,6 @@ construct_runtime!(
AuthorityDiscovery: authority_discovery::{Module, Call, Config<T>},
Authorship: authorship::{Module, Call, Storage},
Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
Balances: balances::{default, Error},
Contracts: contracts,
FinalityTracker: finality_tracker::{Module, Call, Inherent},
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
Expand All @@ -464,6 +443,7 @@ construct_runtime!(
TransactionPayment: transaction_payment::{Module, Storage},
Utility: utility::{Module, Call, Event},

Balances: balances::{default, Error},
Kton: kton,
Staking: staking::{default, OfflineWorker},
EOSBridge: eos_bridge::{Storage, Module, Event<T>, Call},
Expand Down
39 changes: 39 additions & 0 deletions srml/balances/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "darwinia-balances"
version = "2.0.0"
authors = ["Xavier Lau <c.estlavie@icloud.com>"]
edition = "2018"

[dependencies]
serde = { version = "1.0.101", optional = true }
safe-mix = { version = "1.0.0", default-features = false }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
substrate-keyring = { git = "https://github.com/darwinia-network/substrate.git", optional = true }
rstd = { package = "sr-std", git = "https://github.com/darwinia-network/substrate.git", default-features = false }
sr-primitives = { git = "https://github.com/darwinia-network/substrate.git", default-features = false }
support = { package = "srml-support", git = "https://github.com/darwinia-network/substrate.git", default-features = false }
system = { package = "srml-system", git = "https://github.com/darwinia-network/substrate.git", default-features = false }
timestamp = { package = "srml-timestamp", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }

darwinia-support = { path = "../support", default-features = false }

[dev-dependencies]
runtime-io = { package = "sr-io", git = "https://github.com/darwinia-network/substrate.git" }
primitives = { package = "substrate-primitives", git = "https://github.com/darwinia-network/substrate.git" }
transaction-payment = { package = "srml-transaction-payment", git = "https://github.com/darwinia-network/substrate.git" }

[features]
default = ["std"]
std = [
"serde",
"safe-mix/std",
"substrate-keyring",
"codec/std",
"rstd/std",
"support/std",
"sr-primitives/std",
"system/std",
"timestamp/std",

"darwinia-support/std"
]
Loading