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

Implement accounts/{accountId}/staking-payouts #217

Merged
merged 23 commits into from
Aug 24, 2020
Merged

Conversation

emostov
Copy link
Contributor

@emostov emostov commented Aug 17, 2020

Closes #216

In this PR we add accounts/{accountId}/staking-payouts, and Rust code to do payout calculations. The @polkadot/calc-fee wasm-pack built package becomes @substrate/calc as it now incorporates both fee calculation and payout calculation.

The main things to consider for this PR:

  • Payout amounts match on-chain so this endpoint can be used for accounting
  • No type issues going between JS - wasm. (I assume Perbill's like validator_commission fit into a u32, however if they don't we will run into overflow)
  • API is designed in such a way that is maintainable and we will not need to make breaking changes in the future.

TODO:

  • Correct arithmetic methods to simulate substrate's Perbill
  • Verify why 0% commissions still show up as one Perbill
  • General testing to verify accuracy of results
  • Update openapi-proposal.yaml to match

Follow up PRs

  • Unit tests

@emostov emostov added the A3 - In Progress PR in progress, not ready for review label Aug 17, 2020
@emostov emostov marked this pull request as draft August 17, 2020 02:19
Remove unused comment

Update comments and org

Update response structure

Remove validator count
@emostov emostov added A0 - Please Review PR is ready for review B3 - API Noteworthy API is not broken, but worth noting and removed A3 - In Progress PR in progress, not ready for review labels Aug 20, 2020
@emostov emostov marked this pull request as ready for review August 20, 2020 05:14
Copy link
Member

@athei athei left a comment

Choose a reason for hiding this comment

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

Only reviewed the Rust part. Looks generally good to me. However, I thought maybe it would be better to put all Rust stuff in one package and give it a more general name rather than having one per function. Otherwise this creates a lot of code duplication and friction when adding new stuff.

You could just put those functionalities into different submodules.

calc-payout/src/lib.rs Outdated Show resolved Hide resolved
calc-payout/src/lib.rs Outdated Show resolved Hide resolved
calc-payout/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@danforbes danforbes left a comment

Choose a reason for hiding this comment

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

Just a few nitpicks...looks great!

README.md Outdated Show resolved Hide resolved
calc/Cargo.toml Outdated Show resolved Hide resolved
calc/README.md Outdated Show resolved Hide resolved
@@ -0,0 +1,203 @@
use crate::debug;

Choose a reason for hiding this comment

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

I think you should have used git mv somewhere to avoid this. These are not new, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct

calc_payout
}

pub fn calc_payout(

Choose a reason for hiding this comment

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

You could look into making a PR to substrate and so that pallet-staking exposes a function that only does the calculation, and then you simply call into that here, rather than duplicating code.

Given that it can be done with sensible changes to staking, I will totally support this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

100% support this as it will make future runtime upgrades much easier to support.

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
@emostov emostov mentioned this pull request Aug 21, 2020
19 tasks
openapi/openapi-proposal.yaml Outdated Show resolved Hide resolved
@joepetrowski joepetrowski merged commit 2f817d1 into master Aug 24, 2020
@joepetrowski joepetrowski deleted the zeke-rewards branch August 24, 2020 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A0 - Please Review PR is ready for review B3 - API Noteworthy API is not broken, but worth noting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement account/{accountId}/staking-payouts
5 participants