fix: duplicate payouts in staking-payouts endpoint #1439
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Closes #1438
This PR fixes duplicate payouts found in the
accounts/<address>/staking-payouts
endpoint when querying some specific cases of nominators.Root cause
In certain rare cases (eras
6xx
), a single nominator may have multiple nominations for the same validator and at the same era, each with a different stake amount.How Sidecar handles this case
In Sidecar we were not expecting to have this case. We were expecting one stake of a nominator per validator, not multiple. Consequently :
Suggested Fix
The suggested solution includes adding an index with which we can check the right stake amount that we need to retrieve every time and then return its corresponding payout.
Response (old code)
For some particular cases of nominators (whose addresses we refrain to disclose)
[http://127.0.0.1:8080/accounts/<nominatorAddress>/staking-payouts?at=1879836&depth=1&era=661&unclaimedOnly=false
We would have duplicate payouts in the response as shown below:
Response (new code)
For the same cases of nominators
[http://127.0.0.1:8080/accounts/<nominatorAddress>/staking-payouts?at=1879836&depth=1&era=661&unclaimedOnly=false
We now have multiple payouts in the response as shown below:
but with different
nominatorExposure
andnominatorStakingPayout
in each case. Each payout was calculated based on the stake of each nomination (of that nominator to that validator and at that era).Testing
Credits & Thanks