fix: staking payouts change claimed value #1429
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.
Issue
In the
/accounts/{accountId}/staking-payouts
endpoint, for some accounts if we query :era
and at a sample block height, e.g. 1400000 we do not get any payouts for the accountera
but 100k blocks later, e.g. 1500000 we do get payouts for that same accountExample Requests
1. endpoint
era= 518
block = 1475279
response
2. endpoint
era = 518
block = 1575279 (1475279 + 100k)
response
What is happening in general
If I run in debug mode, in both block heights the payouts are correctly calculated but :
claimed
boolean value) that is in place results tofalse
true
What is happening in the code
totalExposure
andnominatorExposure
exposure
numbers found in step 1 (after thecalc_payout
) are pushed in thepayouts
array in this linepayouts
in the response (here)payouts
) that is the issue in the above 2 requestsWhy this happens (Root Cause)
false
, the code will go into thecontinue
case (here, here and here)continue
means that the code will skip everything that is after this statement thus will never arrive at the line where it populates thepayouts
array and it will not give back any payouts (or more precisely it will give back an empty array).continue
is this one where we are checking thelastReward
lastReward
isNULL
so it will just skip everything after that.Suggested Solution
With the proposed change in this PR, we basically give back the payouts in both block heights but the
claimed
variable/field is set tofalse
in the 1st case andtrue
in the 2nd case based on the value oflastReward
.More specifically, this change will result in the following :
lastReward
isNULL
, we setindexOfEra = -1
instead of skipping/continue
claimed
tofalse
payouts
array andpayouts
) to the user with the only difference thatclaimed
field will befalse
Important Note
The payouts in both block heights are the same.
Results from same requests after the change
1. endpoint
response
2. endpoint
response
Things to confirm
lastReward
isNULL
, settingclaimed
toFALSE
is the right logic.Credits & Thanks