Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
aa83f22
initial doc for the staking module
kianenigma Mar 9, 2019
b9d09bb
Remove md style links.
kianenigma Mar 9, 2019
7df2b19
Remove todos.
kianenigma Mar 9, 2019
28b959b
Add rust code types
kianenigma Mar 9, 2019
91be68b
Rename and fix review notes.
kianenigma Mar 11, 2019
5912ff5
Add new md file
kianenigma Mar 11, 2019
64ca546
Final touches.
kianenigma Mar 11, 2019
a8ba78e
Migrate compleatly to rustdoc
kianenigma Mar 11, 2019
982d7e8
Update link
kianenigma Mar 11, 2019
4a572a2
Fix heading
kianenigma Mar 11, 2019
ea5ae00
Merge branch 'master' into kiz-document-staking
kianenigma Mar 12, 2019
89682a6
Final touches wrt the new template.
kianenigma Mar 12, 2019
956ec96
Remove empty prereq.
kianenigma Mar 12, 2019
2879e1d
Fix more reviews
kianenigma Mar 12, 2019
105723b
Some final nits.
kianenigma Mar 12, 2019
531ae73
Merge branch 'master' of github.com:paritytech/substrate into kiz-doc…
kianenigma Mar 14, 2019
5567859
Fix some side issues.
kianenigma Mar 14, 2019
e739361
Fix another set of reviews
kianenigma Mar 15, 2019
4eb568c
Fix + stabilize leftover reivews.
kianenigma Mar 15, 2019
9b026cc
Remove unused test parameters
kianenigma Mar 15, 2019
a8075c7
Fix typo.
kianenigma Mar 15, 2019
a33205b
Merge redundant loops
kianenigma Mar 15, 2019
07f9710
Merge branch 'kiz-document-staking' into kiz-staking-enhance
kianenigma Mar 15, 2019
cfb39b9
Adds phantom self-vote
kianenigma Mar 16, 2019
a4c298c
Fix broken tests.
kianenigma Mar 17, 2019
5eb6f24
Refactor some names to match the reference.
kianenigma Mar 17, 2019
c4bdb81
Remove redundant inner loops from election round.
kianenigma Mar 18, 2019
03d7583
Introduce phragmen post-processing.
kianenigma Mar 19, 2019
bf8212f
Some fixes and todos.
kianenigma Mar 19, 2019
85f1294
Fix some tests with new phragmen params
kianenigma Mar 21, 2019
eb6d9b5
master.into()
kianenigma Mar 21, 2019
54c1417
Fix test
gavofyork Mar 21, 2019
abc1685
Bump spec
gavofyork Mar 21, 2019
0cdc3c1
Fix wasm build
gavofyork Mar 21, 2019
0d429d8
Fix tests and phragmen fallback. Avoid double-controlling
gavofyork Mar 22, 2019
ae0f53e
Fix and rebuild wasm
gavofyork Mar 22, 2019
7b301ad
Whitespaces, whitespaces everywhere.
kianenigma Mar 22, 2019
1488960
Merge remote-tracking branch 'origin/master' into kiz-staking-enhance
gavofyork Mar 22, 2019
f6b9fbc
Rebuild
gavofyork Mar 22, 2019
c26f890
Disable post-processing.
kianenigma Mar 22, 2019
f40f671
Merge test conflicts.
kianenigma Mar 22, 2019
b399c8a
Identify by stash, not controller account.
gavofyork Mar 22, 2019
d3e5539
Couple of fixes
gavofyork Mar 22, 2019
fcce528
Fix first test
gavofyork Mar 22, 2019
202f67b
Merge branch 'kiz-staking-enhance' of github.com:paritytech/substrate…
gavofyork Mar 22, 2019
6c64125
Fix invulnerability_should_work
gavofyork Mar 22, 2019
badd121
Fix a couple more tests
gavofyork Mar 22, 2019
7b83e30
Fix more tests
gavofyork Mar 22, 2019
a9a3a92
Fix more tests
gavofyork Mar 22, 2019
f14977d
Fix more tests
gavofyork Mar 22, 2019
a41aeec
Fix some tests
kianenigma Mar 22, 2019
f584fd1
Merge branch 'kiz-staking-enhance' of github.com:paritytech/substrate…
kianenigma Mar 22, 2019
817d538
Fix update-ledger.
gavofyork Mar 22, 2019
1257dfe
Merge remote-tracking branch 'origin/kiz-staking-enhance' into kiz-st…
gavofyork Mar 22, 2019
a879983
Fix update-ledger.
gavofyork Mar 22, 2019
0d6136d
Fix another test
gavofyork Mar 22, 2019
0dbff72
Fix another test
gavofyork Mar 22, 2019
184cb5c
Fix rest of staking tests
gavofyork Mar 22, 2019
1b4b05f
Remove printlns
gavofyork Mar 22, 2019
1be69c2
Rebuild wasm
gavofyork Mar 22, 2019
d380360
Merge remote-tracking branch 'origin/master' into kiz-staking-enhance
gavofyork Mar 22, 2019
f255ef5
Fix & tests for auth/val syncing
gavofyork Mar 22, 2019
fd5b2cd
Merge remote-tracking branch 'origin/master' into kiz-staking-enhance
gavofyork Mar 22, 2019
e20b766
Fix up threading for tests
gavofyork Mar 22, 2019
4d8a2fd
Remove superfluous asserts
gavofyork Mar 22, 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
108 changes: 54 additions & 54 deletions srml/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
//!
//! ### Types
//!
//! - `Currency`: Used as the measurement means of staking and funds management.
//!
//! - `Currency`: Used as the measurement means of staking and funds management.
//!
//! ### Dispatchable
//!
//! The Dispatchable functions of the staking module enable the steps needed for entities to accept and change their
Expand All @@ -114,97 +114,97 @@
//!
//! ## Usage
//!
//!
//!
//! ### Snippet: Bonding and Accepting Roles
//!
//!
//! An arbitrary account pair, given that the associated stash has the required funds, can become stakers via the following call:
//!
//!
//! ```rust,ignore
//! // bond account 3 as stash
//! // account 4 as controller
//! // with stash value 1500 units
//! // account 4 as controller
//! // with stash value 1500 units
//! // while the rewards get transferred to the controller account.
//! Staking::bond(Origin::signed(3), 4, 1500, RewardDestination::Controller);
//! ```
//!
//! To state desire to become a validator:
//!
//!
//! To state desire to become a validator:
//!
//! ```rust,ignore
//! // controller account 4 states desire for validation with the given preferences.
//! Staking::validate(Origin::signed(4), ValidatorPrefs::default());
//! Staking::validate(Origin::signed(4), ValidatorPrefs::default());
//! ```
//!
//!
//! Note that, as mentioned, the stash account is transparent in such calls and only the controller initiates the function calls.
//!
//! Similarly, to state desire in nominating:
//!
//!
//! Similarly, to state desire in nominating:
//!
//! ```rust,ignore
//! // controller account 4 nominates for account 10 and 20.
//! Staking::nominate(Origin::signed(4), vec![20, 10]);
//! ```
//!
//!
//! Finally, account 4 can withdraw from any of the above roles via
//!
//!
//! ```rust,ignore
//! Staking::chill(Origin::signed(4));
//! ```
//!
//!
//! ## Implementation Details
//!
//! ### Slot Stake
//!
//! The term `slot_stake` will be used throughout this section. It refers to a value calculated at the end of each era,
//!
//! ### Slot Stake
//!
//! The term `slot_stake` will be used throughout this section. It refers to a value calculated at the end of each era,
//! containing the _minimum value at stake among all validators._
//!
//! ### Reward Calculation
//!
//! - Rewards are recorded **per-session** and paid **per-era**. The value of the reward for each session is calculated at
//! the end of the session based on the timeliness of the session, then accumulated to be paid later. The value of
//!
//! ### Reward Calculation
//!
//! - Rewards are recorded **per-session** and paid **per-era**. The value of the reward for each session is calculated at
//! the end of the session based on the timeliness of the session, then accumulated to be paid later. The value of
//! the new _per-session-reward_ is calculated at the end of each era by multiplying `slot_stake` and a configuration
//! storage item named `SessionReward`.
//! - Once a new era is triggered, rewards are paid to the validators and the associated nominators.
//! - The validator can declare an amount, named `validator_payment`, that does not get shared with the nominators at
//! storage item named `SessionReward`.
//! - Once a new era is triggered, rewards are paid to the validators and the associated nominators.
//! - The validator can declare an amount, named `validator_payment`, that does not get shared with the nominators at
//! each reward payout through their `ValidatorPrefs`. This value gets deducted from the total reward that can be paid.
//! The remaining portion is split among the validator and all of the nominators who had a vote for this validator,
//! proportional to their staked value.
//! - All entities who receive a reward have the option to choose their reward destination, through the `Payee` storage item (see `set_payee()`), to be one of the following:
//! proportional to their staked value.
//! - All entities who receive a reward have the option to choose their reward destination, through the `Payee` storage item (see `set_payee()`), to be one of the following:
//! - Controller account.
//! - Stash account, not increasing the staked value.
//! - Stash account, also increasing the staked value.
//!
//! ### Slashing details
//!
//! - A validator can be _reported_ to be offline at any point via `on_offline_validator` public function.
//! - Each validator declares how many times it can be _reported_ before it actually gets slashed via the
//! `unstake_threshold` in `ValidatorPrefs`. On top of this, the module also introduces an `OfflineSlashGrace`,
//!
//! ### Slashing details
//!
//! - A validator can be _reported_ to be offline at any point via `on_offline_validator` public function.
//! - Each validator declares how many times it can be _reported_ before it actually gets slashed via the
//! `unstake_threshold` in `ValidatorPrefs`. On top of this, the module also introduces an `OfflineSlashGrace`,
//! which applies to all validators and prevents them from getting immediately slashed.
//! - Similar to the reward value, the slash value is updated at the end of each era by multiplying `slot_stake` and a
//! - Similar to the reward value, the slash value is updated at the end of each era by multiplying `slot_stake` and a
//! configuration storage item, `OfflineSlash`.
//! - Once a validator has been reported a sufficient number of times, the actual value that gets deducted from that
//! validator, and every single nominator that voted for it is calculated by multiplying the result of the above point
//! - Once a validator has been reported a sufficient number of times, the actual value that gets deducted from that
//! validator, and every single nominator that voted for it is calculated by multiplying the result of the above point
//! by `2.pow(unstake_threshold)`.
//! - If the previous overflows, then `slot_stake` is used.
//! - If the previous is more than what the validator/nominator has in stake, all of its stake is slashed (`.max(total_stake)`).
//!
//!
//! ### Additional Fund Management Operations
//!
//!
//! Any funds already placed into stash can be the target of the following operations:
//!
//! - The controller account can free a portion (or all) of the funds using the `unbond()` call. Note that the funds
//!
//! - The controller account can free a portion (or all) of the funds using the `unbond()` call. Note that the funds
//! are not immediately accessible, instead, a duration denoted by `BondingDuration` (in number of eras) must pass until the funds can actually be removed.
//! - To actually remove the funds, once the bonding duration is over, `withdraw_unbonded()` can be used.
//! - As opposed to the above, additional funds can be added to the stash account via the `bond_extra()` transaction call.
//!
//! - As opposed to the above, additional funds can be added to the stash account via the `bond_extra()` transaction call.
//!
//! ### Election algorithm details.
//!
//!
//! The current election algorithm is implemented based on Phragmén. The reference implementation can be found [here](https://github.com/w3f/consensus/tree/master/NPoS).
//!
//!
//! ## GenesisConfig
//!
//!
//! See the [`GensisConfig`] for a list of attributes that can be provided.
//!
//! ## Related Modules
//!
//!
//! ## Related Modules
//!
//! - [**Balances**](https://crates.parity.io/srml_balances/index.html): Used to manage values at stake.
//! - [**Sessions**](https://crates.parity.io/srml_session/index.html): Used to manage sessions. Also, a list of new validators is also stored in the sessions module's `Validators` at the end of each era.
//! - [**System**](https://crates.parity.io/srml_system/index.html): Used to obtain block number and time, among other details.
Expand Down Expand Up @@ -908,7 +908,7 @@ impl<T: Trait> Module<T> {
Self::slashable_balance_of,
min_validator_count,
ElectionConfig::<BalanceOf<T>> {
equalise: true,
equalise: false,
tolerance: <BalanceOf<T>>::sa(10 as u64),
iterations: 10,
}
Expand Down
2 changes: 1 addition & 1 deletion srml/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl ExtBuilder {
self.current_era = current_era;
self
}
pub fn validator_pool(mut self, validator_pool: bool) -> Self {
pub fn validator_pool(mut self, validator_pool: bool) -> Self {
self.validator_pool = validator_pool;
self
}
Expand Down
7 changes: 6 additions & 1 deletion srml/staking/src/phragmen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ pub fn elect<T: Trait + 'static, FR, FN, FV, FS>(
}
}));

// println!("Nominators: {:?}", nominators);
// println!("candidates: {:?}", candidates);

// 3- optimization:
// Candidates who have 0 stake => have no votes or all null-votes. Kick them out not.
let mut candidates = candidates.into_iter().filter(|c| c.approval_stake > BalanceOf::<T>::zero())
Expand Down Expand Up @@ -205,7 +208,8 @@ pub fn elect<T: Trait + 'static, FR, FN, FV, FS>(
// if the target of this vote is among the winners, otherwise let go.
if let Some(c) = elected_candidates.iter_mut().find(|c| c.who == e.who) {
e.elected = true;
e.backing_stake = <BalanceOf<T>>::sa(n.budget.as_() * (*e.load / *n.load));
// NOTE: for now, always divide last to avoid collapse to zero.
e.backing_stake = <BalanceOf<T>>::sa((n.budget.as_() * *e.load) / *n.load);
c.backing_stake += e.backing_stake;
if c.who != n.who {
// Only update the exposure if this vote is from some other account.
Expand Down Expand Up @@ -266,6 +270,7 @@ pub fn elect<T: Trait + 'static, FR, FN, FV, FS>(
return None
}
}
// println!("++Elected {:?}", elected_candidates);
Some(elected_candidates)
}

Expand Down
Loading