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

Fix tests of Staking for Crab #331

Merged
merged 8 commits into from
Mar 13, 2020
Merged

Fix tests of Staking for Crab #331

merged 8 commits into from
Mar 13, 2020

Conversation

clearloop
Copy link
Contributor

@clearloop clearloop commented Mar 10, 2020

#325


Update Steps

  • update tests from v2.0.0.alpha.3
  • seperate tests
  • fix tests failed by LockFor
  • fix tests failed by ValidatorPrefs
  • fix tests failed by BondDurationInEra

Need to separate into other prs

Both

  • check the calculation of power, reward.(marked)
  • unbond method(marked)

darwinia_tests

  • slash_validators issue(marked)

@clearloop clearloop self-assigned this Mar 10, 2020
@clearloop
Copy link
Contributor Author

I found here are various TODOs need to be done in Staking's tests:

Discussion Category

TODOs in this category, I think they need some discussion.

  1. outdated problem: disused API
  2. WithdrawLock problem, doesn't have this enum, and doesn't support unbond_withdraw fn

Fixed Category

Some TODOs I just fixed without changing any code, unconsciously, need to be reviewed also.

Trying Category

I'll try to fix these in next 3 commits.

  1. NotSlash problem
  2. overflow problem(this can refer to substrate's code)
  3. unit problem (u128 or u64 in code)

@yanganto
Copy link
Contributor

yanganto commented Mar 10, 2020

unbond_withdraw is removed, we will automatically withdraw and delete the staking ledge when there is no value in the account. So I remove the test case and leave notes here.
https://github.com/clearloop/darwinia/commit/9c016417ad0fe55aa21cb238610fb6f26b0f4463#diff-6031f6ad0d6b579272b1748548a364ddR1391
reference #154

@AurevoirXavier
Copy link
Member

  • The Staking struct in darwinia-staking-pallet is different from the substrate's staking-pallet, so the fix process mainly follows the last version of darwinia-staking-pallet.

Base on the latest substrate tests. And do some modification.

@clearloop
Copy link
Contributor Author

unbond_withdraw is removed, we will automatically withdraw and delete the staking ledge when there is no value in the account. So I remove the test case and leave notes here.

Yep, and this series can not just referring substrate's test cases in v2.0.0-alpha.3, the WithdrawLock in darwinia is required to be discussed.

@clearloop
Copy link
Contributor Author

Base on the latest substrate tests. And do some modifications.

Yep, this is the last step of this pr.

@AurevoirXavier
Copy link
Member

unbond_withdraw is removed, we will automatically withdraw and delete the staking ledge when there is no value in the account. So I remove the test case and leave notes here.

Yep, and this series can not just referring substrate's test cases in v2.0.0-alpha.3, the WithdrawLock in darwinia is required to be discussed.

But our apis (set_lock, remove_lock...) is the same as substrate's apis.

@clearloop
Copy link
Contributor Author

But our APIs (set_lock, remove_lock...) are the same as substrate's APIs.

Okay, I'll try to fix the withdraw part after I fixed the trying category

@clearloop
Copy link
Contributor Author

clearloop commented Mar 10, 2020

3 Questions

  1. Why use u128 here?

pub type Balance = u128;

  1. Why we got a CAP instead of u64::max_value() in our mock.rs?

pub const CAP: Balance = 10_000_000_000 * COIN;

  1. Why use Power instead of Balance here?

pub const TOTAL_POWER: Power = 1_000_000_000;

pub total_power: Power,

Note

I'm not sure if the questions before cause the overflow problem.

@AurevoirXavier
Copy link
Member

AurevoirXavier commented Mar 10, 2020

  1. x * COIN will overflow the u64
  2. CAP is a hardcoded total circulation of RING
    • RING provide 50% Power
    • KTON provide 50% Power

@clearloop
Copy link
Contributor Author

clearloop commented Mar 10, 2020

The reward of validating is decided by the votes(power) but not funds(balances) in staking, actual is this a part of darwinia's design...? If not, I'll fix it.

The direct effect of using votes to decide the reward is:

If an Exposure has no power, the validators will get nothing even they got involved in validating.

For nominator

let per_u64 = Perbill::from_rational_approximation(i.power, total);

For validator

let per_u64 = Perbill::from_rational_approximation(exposure.own_power, total);

@AurevoirXavier
Copy link
Member

Please read the gene paper. And understand what power is.

@clearloop
Copy link
Contributor Author

clearloop commented Mar 10, 2020

Please read the gene paper. And understand what power is.

Well, I know the power in gene paper means computing power, the votes above means, power in some Exposure and IndividualExposure are converted from darwinia_phragmen::Votes which is original from darwinia_phragmen::elect, and the doc in darwinia_phragmen::elect says validators are candidates and nominators are voters.

Please checkout this function:

fn reward_validator(stash: &T::AccountId, reward: RingBalance<T>) -> (RingPositiveImbalance<T>, Rewards<T>) {

This concept decides how I fix the reward tests(because this part is different from substrate), if there is no problem, I'll fix them to follow the design.

@hackfisher
Copy link
Contributor

Please read the gene paper. And understand what power is.

Well, I know the power in gene paper means computing power, the votes above means, power in some Exposure and IndividualExposure are converted from darwinia_phragmen::Votes which is original from darwinia_phragmen::elect, and the doc in darwinia_phragmen::elect says validators are candidates and nominators are voters.

Please checkout this function:

fn reward_validator(stash: &T::AccountId, reward: RingBalance<T>) -> (RingPositiveImbalance<T>, Rewards<T>) {

This concept decides how I fix the reward tests(because this part is different from substrate), if there is no problem, I'll fix them to follow the design.

We use power instead of balance value to represent the contribution of validators/nominators(validators can contribute too), so does the rewards.

It's by design, not sure this answers your question?

frame/staking/src/lib.rs Outdated Show resolved Hide resolved
frame/staking/src/lib.rs Outdated Show resolved Hide resolved
frame/staking/src/lib.rs Outdated Show resolved Hide resolved
frame/staking/src/lib.rs Outdated Show resolved Hide resolved
frame/staking/src/tests.rs Outdated Show resolved Hide resolved
frame/staking/src/tests.rs Outdated Show resolved Hide resolved
frame/staking/src/tests.rs Outdated Show resolved Hide resolved
frame/staking/src/tests.rs Outdated Show resolved Hide resolved
@clearloop
Copy link
Contributor Author

clearloop commented Mar 12, 2020

Review Guide

All un-fixed problems have been tagged by @ prefix, here are 3 types of @ family:

  • @review: need to be reviewed, most of them are about the calculation of power, reward
    • unbond problem is also under this tag, the unlock problem, what should happen when unbond all stakes?
  • @TODO: this tag mainly used for BondingDurationInEra problem in staking tests, these might should be fixed, because substrate v2.0.0.alpha.3 can pass these tests.
  • @darwinia: this comments the related tests different from the substrate's tests.

Note

The left problems are all about darwinia features, considering the difficulty of review the whole test files, I think we might merge this pr after passing the Travis' tests, then @yakio and I can divide the tests(whatever you choose, I prefer to fix the easier part...)

Copy link
Contributor

@yanganto yanganto left a comment

Choose a reason for hiding this comment

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

Thanks for the help. I will work on these after merging.

frame/staking/src/darwinia_tests.rs Outdated Show resolved Hide resolved
Copy link
Member

@AurevoirXavier AurevoirXavier left a comment

Choose a reason for hiding this comment

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

All <Module<Test>> can be replace with Staking, but it's ok.

@hackfisher hackfisher merged commit b2b9adc into darwinia-network:develop Mar 13, 2020
boundless-forest pushed a commit that referenced this pull request Aug 1, 2023
* Decouple backend access from EthApi

* Module instead arbitrary struct

* Fix checker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants