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

Track per-epoch staking rewards #813

Open
Andrew7234 opened this issue Dec 2, 2024 · 0 comments
Open

Track per-epoch staking rewards #813

Andrew7234 opened this issue Dec 2, 2024 · 0 comments
Assignees

Comments

@Andrew7234
Copy link
Collaborator

Andrew7234 commented Dec 2, 2024

When a user account stakes tokens with a validator, they receive staking rewards at the end of each epoch. Even though the reward is auto-staked and not technically in the end users' possession yet, users want to see the number of ROSE that they received each epoch. This is a highly requested feature. Oasis Monitor used to provide it, but currently no explorer does.

It would be good to expose slashing of staked funds in the same way.

**Suggestion from OP
I suggest we expose this as synthetic events. It's a little unprincipled because we normally only expose events emitted by the chain, but it's the natural place to show these.

Implementation:
This will require us to keep track of some historical values, likely validators' balances and shares at the end of each epoch (What about slashing? Can happen at any time.). Possible approach:
introduce a new table or two for historical values
at the end of fast-sync, backfill the table(s) and generate events
during slow sync, at the start of each epoch, add rows to historical tables and generate events

Helpful reading: Split 2023 presentation on technicalities of staking rewards: [redacted]

**Alternative
We should consider exposing this in a custom endpoint that returns the rewards for each epoch in a given year. The events table is already quite large and inserting ~5 years of epochs(44k) with ~30k (delegator/delegatee) pairs would easily create an additional 1 billion synthetic events.

Calculating the per-epoch staking rewards for a given account is likely too slow to be done on request, but we can test and confirm. Otherwise, it could be done in a secondary analyzer or a materialized view.

@Andrew7234 Andrew7234 self-assigned this Dec 2, 2024
@csillag csillag mentioned this issue Dec 22, 2024
1 task
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

No branches or pull requests

1 participant