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

feat: add at query param for staking-payouts #1388

Merged
merged 18 commits into from
Feb 6, 2024
Merged

feat: add at query param for staking-payouts #1388

merged 18 commits into from
Feb 6, 2024

Conversation

TarikGul
Copy link
Member

@TarikGul TarikGul commented Feb 1, 2024

Summary

This PR focuses on expanding the query params for /accounts/{accountId}/staking-payouts to include the at query param. This required me to remove the old api.derive.staking.eraExposure(eraIndex) that is exposed from polkadot-js and write a modified version that was abstracted from the polkadot-js source code to allow us to add a historic api to it.

Query param

at - Block height (as a non-negative integer) or hash (as a hex string).

Extra

I rewrote all the tests for the endpoint to be cleaner and include specific information on the block and the era so if anything needs to be added in the future it will be simple to extract the necessary data from polkadot.

closes: #1033

@TarikGul TarikGul requested a review from a team as a code owner February 1, 2024 17:34
@TarikGul TarikGul changed the title feat: add at query param for staking-payouts feat: add at query param for staking-payouts [WIP] Feb 1, 2024
@TarikGul TarikGul changed the title feat: add at query param for staking-payouts [WIP] feat: add at query param for staking-payouts Feb 4, 2024
Copy link
Contributor

@bee344 bee344 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@Imod7 Imod7 left a comment

Choose a reason for hiding this comment

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

Great work! 💯

It might be worth noting that Subscan and Sidecar display rewards differently (at least in the views I checked). I thought of adding the difference here in case it is helpful for others who might also check Subscan:

  • For example, while connected in Kusama and checking some rewards from this list from Subscan I can see the rewards for different eras and blocks.
  • For example, for block 20193750 I can see the reward 0.152 KSMfor era 5787
  • If I query the Sidecar endpoint for this block accounts/J47U9wGuwzccFPoz8bnMTKJt7WGpPp8ZNgvtXFDL9PHwpCt/staking-payouts?unclaimedOnly=false&at=20193750 it returns the reward for era 5789
  • So for the same block I get different era.
  • The difference is due to the fact that:
    • Sidecar gives back the rewards that correspond to each era (claimed or unclaimed) so it gives the state information.
    • Subscan gives back only the rewards that were claimed hence when and if someone made that call to get the corresponding reward. If no one makes that call and if 84 eras pass, this reward will be lost. (polkadot wiki)

Important Note

  • The reward amounts per era is consistent across both platforms.
  • Also, just noting that there are examples that some blocks and eras will be aligned in both platforms too.

Credits to @IkerAlus for the explanation and clarifications.

@TarikGul TarikGul merged commit a8b96ff into master Feb 6, 2024
21 checks passed
@TarikGul TarikGul deleted the tarik-era-at branch February 6, 2024 15:33
This pull request was closed.
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.

feat: Increase the history_depth beyond the 84 eras in staking-payouts endpoint
4 participants