Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Stash/controller model for staking #1782

Merged
merged 85 commits into from
Mar 2, 2019
Merged

Stash/controller model for staking #1782

merged 85 commits into from
Mar 2, 2019

Conversation

gavofyork
Copy link
Member

@gavofyork gavofyork commented Feb 13, 2019

Implements #1709.

Also:

  • Moves Fee payment traits into SRML support, where they belong (they're not core).
  • Refactors EnsureAccountLiquid by adding a finer grained querier.
  • Refactors the spec generation code, getting it a bit more ready for when authorities use different crypto to accounts.

Associated spec/docs are at https://github.com/paritytech/substrate/blob/1a2ec9eec1fe9b3cc2677bac629fd7e9b0f6cf8e/srml/staking/Staking.md

TODO:

  • Refactor Intentions and Nominating over to Desired
  • Remove NominatorsFor, rename CurrentNominatorsFor to Stakers and populate at new era naively from Desired.
  • Avoid paying out per-session; pay out per-era to reduce trie churn.
  • Full documentation/specification.
  • Controller account can wield stash for governance stuff (democracy, council voting). Can probably be done easiest as a kind of sudo that checks to make sure the Call is to the governance module.
  • Tests - @shawntabrizi & @kianenigma
  • Introduce online Phragmén. Introduced in this branch
  • Introduce offline Phragmén, along with desire/unlock freeze for period at end of era.

@gavofyork gavofyork added the A3-in_progress Pull request is in progress. No review needed at this stage. label Feb 13, 2019
@gavofyork gavofyork closed this Feb 15, 2019
@gavofyork gavofyork reopened this Feb 15, 2019
@gavofyork gavofyork closed this Feb 15, 2019
@gavofyork gavofyork reopened this Feb 15, 2019
@gavofyork gavofyork added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. A4-gotissues labels Feb 28, 2019
Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the global tests and merge conflicts in the last commit and of course had to build the wasm files again. I only learned afterward that once wasm is re-built a impl version bump is usually needed. Is this the case when now the PR impl_version is already bumped w.r.t. master?
In either case, if someone with a bit more experience with versioning confirms that this spec/impl versioning is ok then this is all good to merge. Rest of the minor test cases can be created via the separate phragmen PR.

https://github.com/paritytech/substrate/pull/1782/files#diff-5e5e1c3aec9ddfde0a9054d062ab3db9R63

Copy link
Member

@shawntabrizi shawntabrizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to merge in with a temporary validator choosing algorithm.
There should be a second pass at tests once Phragmen is in, and there are TODO items everywhere this will need to be addressed.

Additionally, I think it makes sense to drop ensure_account_liquid with ensure_account_can_withdraw, but that can be discussed elsewhere.

Almost forgot this one
@@ -386,6 +386,7 @@ decl_module! {
let controller = ensure_signed(origin)?;
let _ledger = Self::ledger(&controller).ok_or("not a controller")?;
<Nominators<T>>::remove(&controller);
ensure!(prefs.unstake_threshold <= MAX_UNSTAKE_THRESHOLD, "unstake threshold too large");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure! after you've made changes to storage. Rookie error :-P

@@ -770,6 +771,8 @@ impl<T: Trait> OnSessionChange<T::Moment> for Module<T> {
}

impl<T: Trait> EnsureAccountLiquid<T::AccountId, BalanceOf<T>> for Module<T> {
// TODO: Consider replacing uses of this function in favor for ensure_account_can_withdraw
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It remains here on purpose. Contracts module cannot be changed in order to use the finer-grained function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it remains on purpose, we should create an issue for it :)


/*
#[test]
fn slot_stake_is_least_staked_validator_and_limits_maximum_punishment() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shawntabrizi shouldn't we uncomment this now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, please commit no commented-out-code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@gavofyork gavofyork merged commit 701fd11 into master Mar 2, 2019
@gavofyork gavofyork deleted the gav-new-staking branch March 2, 2019 13:32
@kianenigma kianenigma mentioned this pull request Mar 4, 2019
5 tasks
@burdges
Copy link

burdges commented Mar 11, 2019

I'd think withdraw_unbonded would be functions controlled by the stash account's key? Or maybe the name just confused me and it leaves the funds under the control of the stash account, but now unbonded?

MTDK1 pushed a commit to bdevux/substrate that referenced this pull request Apr 12, 2019
* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants