Stash/controller model for staking (#1782)

* First steps to stash/controller separation

* More drafting

* More drafting

* Finish draft.

* Optimisation

* Remove accidental commit

* Make it build.

* Fix linked map for traits.

* Fix Option<_> variant.

*  Improve naming a tad

* Rebuild runtime

* Builds!

* First test.

* Bump RT version

* Minor fix

* Update Mock

* adds the correct reward testcase (+staking eras which was already ok)

* fixes the basic staking testcase to work properly (along with a small fix in the module)

* New logic to avoid controller transferring stash.

* Fix some build issues.

* adding some comments to tests

* Fix impls.

* adds a few more lines to explain the test case

* More fixes.

* gets the basic test up and running again

* Fix rest of build

* Rebuild wasm

* Fix docs.

* fix staking test with new chnages

* updating some tests, pending questions

* More working tests

* adds double staking test

* Docs

* remove invalid slashing test

* Payee stuff.

* Fix build

* Docs

* Fix test

* Fix a couple of tests

* Layout plan for finishing tests before Pragmen

* Add some working tests

* re-build staking and reward tests

* Add more tests

* fix offline grace test

* Nominator should have payee checked for cleanup

* adds more nomination tets

* adds validator prefs tests

* Fix and clean up some TODOs

* Fix a couple of issues

* Fix tests

* noting warnings from tests

* final fix of local tests

* Fix slot_stake bug

* Half baked test

* Add logic to limit `unstake_threshold` set in storage

* Make sure to check before writing!

Almost forgot this one

* Move a couple of comments

* fix last broken slot_stake test

* Ignore broken test
This commit is contained in:
Gav Wood
2019-03-02 14:31:48 +01:00
committed by GitHub
parent ff331e7fdc
commit 828cd9580a
24 changed files with 1871 additions and 910 deletions
+17 -4
View File
@@ -24,7 +24,7 @@ use primitives::traits::{Zero, As};
use parity_codec_derive::{Encode, Decode};
use srml_support::{StorageValue, StorageMap, Parameter, Dispatchable, IsSubType};
use srml_support::{decl_module, decl_storage, decl_event, ensure};
use srml_support::traits::{Currency, OnFreeBalanceZero, EnsureAccountLiquid, ArithmeticType};
use srml_support::traits::{Currency, OnFreeBalanceZero, EnsureAccountLiquid, WithdrawReason, ArithmeticType};
use srml_support::dispatch::Result;
use system::ensure_signed;
@@ -415,12 +415,25 @@ impl<T: Trait> OnFreeBalanceZero<T::AccountId> for Module<T> {
}
}
impl<T: Trait> EnsureAccountLiquid<T::AccountId> for Module<T> {
impl<T: Trait> EnsureAccountLiquid<T::AccountId, BalanceOf<T>> for Module<T> {
fn ensure_account_liquid(who: &T::AccountId) -> Result {
if Self::bondage(who) <= <system::Module<T>>::block_number() {
if Self::bondage(who) > <system::Module<T>>::block_number() {
Err("stash accounts are not liquid")
} else {
Ok(())
}
}
fn ensure_account_can_withdraw(
who: &T::AccountId,
_value: BalanceOf<T>,
reason: WithdrawReason,
) -> Result {
if reason == WithdrawReason::TransactionPayment
|| Self::bondage(who) <= <system::Module<T>>::block_number()
{
Ok(())
} else {
Err("cannot transfer illiquid funds")
Err("cannot transfer voting funds")
}
}
}