-
Notifications
You must be signed in to change notification settings - Fork 151
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: claimed in staking info endpoint #1445
base: master
Are you sure you want to change the base?
Conversation
The change is reasonable. Sidecar user does not care of internal renaming changes since the retrieved info has the same meaning. Is this PR ready for review or are we waiting for the Todos list to be checked? |
Yes, ideally the todos needs to be completed before a review. However, if any review will speed things up then please feel free to add them. |
Update
The response will also needs to be changed from a Related Resource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just had a question about unwraps
docs/src/openapi-v1.yaml
Outdated
for _validators._ This array is populated with values from `stakingLedger.legacyClaimedRewards` | ||
or `stakingLedger.claimedRewards`, as well as the `query.staking.claimedRewards` call, depending | ||
on whether the queried block is before or after the migration. For more details on the implementation | ||
and the migration, refer to the related PR and linked issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where/how can the user find the relevant linked info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added specific links of the PR and linked issue. Let me know if this covers your question. I also updated the schema description since I no longer return lastReward
. Changes included in this commit.
Do we have specific data for this statement? How long does it take to return the staking info in the any worst case scenario (for example, 84 eras in different pages and/or with different logic)? |
You are right, I didn't have any formal data when I wrote that. It was based on my observations from the tests I did and also on my knowledge of the calculations of each implementation.
|
@IkerAlus After our last convo on whether the status
Here is the next round of conclusions about
Currently, I am also considering that in both scenarios, it is useful to add the |
- removed `partially claimed` value - added `undefined` value - updated tests
- bringing back `partially claimed` for validator
Description
Closes #1433
This PR restores the field
claimed
(understaking
) in thestaking-info
endpoint's response which was previously replaced bylegacyClaimedRewards
. The root cause of this is explained here.Suggested Fix
The suggested solution includes :
IStakingLedger
interface to have more control on the response fields understaking
.stakingLedger.legacyClaimedRewards
ORstakingLedger.claimedRewards
(depending on what call is available every time)staking.claimedRewards
(if available)Checks needed per Type of Account
Validator Account
If the account queried in the endpoint is a
validator
account, the following logic is implemented:claimed
if all pages oferasStakersPaged
were claimed.unclaimed
if no pages were claimed.partially claimed
if some of the pages were claimed.Nominator Account
Logic implemented
1st Check
In early blocks/eras there is
lastReward
instead ofclaimedRewards
understakingLedger
. In this case, we set asclaimed
the era mentioned in thelastReward
so:lastReward
==552
claimedRewards: {era: 552, status : claimed
HP8qJ8P4u4W2QgsJ8jzVuSsjfFTT6orQomFD6eTRSGEbiTK
lastReward
instead ofclaimedRewards
. This has been changed so that we always returnclaimedRewards
. Depending on which call is available, values (era & status) inclaimedRewards
are updated according to the logic described in this PR.2nd Check
stakingLedger.legacyClaimedRewards
call is available, retrieveclaimed
information from that callclaimed
info fromstakingLedger.claimedRewards
{era: eraNumber, status : claimed | unclaimed | partially claimed}
*** Note : the 2 calls mentioned above are per specific block height and stash account.
3rd Check
Then, independently of the previous check, check also:
query.staking.claimedRewards
call is availableclaimed
information from that call but only for the eras that we are still missing and complete the missing info*** Note : this call is per specific block height, era and stash account.
More specifically :
depth
andcurrent_era
the eras we are missingstaking.erasStakersOverview.pageCount
==query.staking.claimedRewards
-> then we set the queried era asclaimed
staking.erasStakersOverview.pageCount
!=query.staking.claimedRewards. length
-> we set the era aspartially claimed
overview == null
&&erasStakers > 0
-> this means thatpageCount
= 1query.staking.claimedRewards
value to see if eraclaimed
orunclaimed
.{ "era": "6453", "status": "claimed" },
*** Note : the output from
query.staking.claimedRewards
is of format[0]
if only one page was claimed or[0, 1]
if 2 pages were claimed depending on how many pages the stakers of the specific validator are split into (shown fromstaking.erasStakersOverview.pageCount
).Different Cases
Case
staking.erasStakersOverview.pageCount
==staking.claimedRewards.length
This is the case when
erasStakersOverview
->pageCount
) per era andclaimedRewards
arrayExample
DteShXKaQQy2un2VizKwwhViN5e7F47UrkAZDkxgK22LdBv
- subscan6577
in Kusama chain23032300
0xf9362e71ed123c3a057b75bce389a4c0758ad405556125fee00529569a433898
staking.claimedRewards
=[0]
staking.erasStakersOverview.pageCount
=1
http://127.0.0.1:8080/accounts/DteShXKaQQy2un2VizKwwhViN5e7F47UrkAZDkxgK22LdBv/staking-info?at=23032300
6577
- ClaimedCase Handled
This case is handled by setting queried era as claimed.
Case
staking.erasStakersOverview.pageCount
!=staking.claimedRewards.length
This is the case when a validator has multiple pages of nominators and only some of these pages were claimed.
Example
Account 11VR4pF6c7kfBhfmuwwjWY3FodeYBKWx7ix2rsRCU2q6hqJ
Era
1470
in Polkadot chainpjs apps
1468
0x59de258cf9999635c866df7bc5f397d152892827f887d3629344cb3cebba134f
claimedRewards =
[0]
erasStakersOverview = 2
Sidecar
http://127.0.0.1:8080/accounts/11VR4pF6c7kfBhfmuwwjWY3FodeYBKWx7ix2rsRCU2q6hqJ/staking-info?at=21157800
1468
-Partially Claimed
Case handled
This case is handled currently by setting queried era as partially claimed.
Case
staking.erasStakersOverview
=null
&staking.claimedRewards
=[0]
This is a case where
staking.erasStakersOverview
isnull
so the information about thepageCount
(in how many pages the stakers are divided into) needs to be retrieved fromerasStakers
and then compare it withstaking.claimedRewards
.Example
6513
in Kusama chain0x1ef674fffb042c9016987e0e3995a36401a7e2b66e0b6c0bb111a0b049857098
[0]
null
http://127.0.0.1:8080/accounts/F2VckTExmProzJnwNaN3YVqDoBPS1LyNVmyG8HUAygtDV3T/staking-info?at=22939322
6513
-Claimed
Case handled
This case is handled by checking if
erasStakers > 0
(hence pageCount == 1) &&staking.claimedRewards
is equal to[0]
(hence length is 1) -> which is true for era6513
so era is set toclaimed
.Case
staking.erasStakersOverview
=null
&erasStakers
= 0Based on this comment, exposure is not found so we cannot conclude in a status for this specific era. An example is the below request in which only 48 eras are returned since for the rest 36 ->
staking.erasStakersOverview
=null
&erasStakers
= 0.Response (old code)
http://127.0.0.1:8080/accounts/CmjHFdR59QAZMuyjDF5Sn4mwTgGbKMH2cErUFuf6UT51UwS/staking-info?at=22869643
Response (new code)
Testing
🗒️ Implementation Notes
true
so that it does not break the current functionality of the endpoint. Implementation in a separate PR.current era - depth
if only the new calls are available orarray.length
from result of old calls up until depth. So ifarray.length
= 20 anddepth
= 84, we will check 64 more eras after the last era found in the array (from the old calls).Todos
partially claimed
eras &erasStakersOverview
= nulldepth
.lastReward
instead ofclaimedRewards
understakingLedger
.era < 518
andchain = isKusama
-> the era is considered asclaimed
"automatically".status = undefined
-> which is when we do not have enough info to determine the status of the era.nominator
logic mentioned in this commentNice to have
staking.erasStakersOverview
=null
&erasStakers
= 0 which can be implemented by mocking this requesthttp://127.0.0.1:8080/accounts/CmjHFdR59QAZMuyjDF5Sn4mwTgGbKMH2cErUFuf6UT51UwS/staking-info?at=22869643
Changelog
This PR introduces breaking changes to the
staking-info
endpoint response by :lastReward
for early eras and addingclaimedRewards
updated accordingly.claimedRewards
field (understaking
)Hence, it should be explicitly mentioned in the corresponding Changelog and Release Notes of the next release.