Skip to content

feat: add total reward for epoch for each user #204

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

Merged
merged 31 commits into from
Mar 31, 2025

Conversation

neocybereth
Copy link
Contributor

No description provided.

@Fraccaman
Copy link
Member

this looks nice! thanks for the PR. You are missing a migration to add the epoch field to the rewards table. You can check it here https://diesel.rs/guides/getting-started#setup-diesel-for-your-project

@Fraccaman
Copy link
Member

Ehi! you are still missing the migration, you need to add a folder here https://github.com/anoma/namada-indexer/tree/main/orm/migrations (you can follow the guide https://diesel.rs/guides/getting-started#setup-diesel-for-your-project to auto generate the folder for you). The migration is needed to modify the rewards table schema and add the epoch field

@neocybereth
Copy link
Contributor Author

neocybereth commented Dec 16, 2024

Oof! Sorry about that, coming right up!

I think this should do it:

Screenshot 2024-12-17 at 12 15 34 PM

@Fraccaman
Copy link
Member

you might also want to update the webserver? I mean, update/create a new endpoint

Comment on lines 4 to 6
ALTER TABLE pos_rewards ADD COLUMN epoch INTEGER NOT NULL DEFAULT 0;
-- Now we can safely drop the default
ALTER TABLE pos_rewards ALTER COLUMN epoch DROP DEFAULT;
Copy link
Contributor

Choose a reason for hiding this comment

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

While testing this, I ran into a problem where the pos_rewards table didn't have an updated UNIQUE constraint which incorporates the epoch column.

I pushed a commit that fixes that: 725f9c9

Feel free to add it to your branch also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated that here:

1244bab

validator_id,
raw_amount: BigDecimal::from(reward.amount),
Copy link
Contributor

Choose a reason for hiding this comment

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

Note - this is assigning to raw_amount the decimal value of nam (i.e. 12.34567 not 1234567 unam) -- which is different than the previous behavior of the rewards crawler. I noticed it in my testing because the raw_amount column has type numeric(78,0) which only stores integer values, and the reward amounts were being truncated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

0957a4a

Fixed here with:

            raw_amount: BigDecimal::from_str(&reward.amount.to_string()).unwrap(),

@neocybereth
Copy link
Contributor Author

neocybereth commented Dec 30, 2024

you might also want to update the webserver? I mean, update/create a new endpoint

fae5e1f all the webserver endpoints are in.

basically it takes a delegator address, validator address and epoch and gives back the rewards. The validator address is used to find a validator id to look up the reward. Again, my rust sucks so let me know if there's anything off.

@brentstone
Copy link
Contributor

brentstone commented Jan 2, 2025

Does this PR depend on anoma/namada#4196?

@neocybereth
Copy link
Contributor Author

Does this PR depend on anoma/namada#4196?

I'm 99% sure yes, but I'm also a noob to this codebase so @joel-u410 or @Fraccaman could confirm for sure.

@joel-u410
Copy link
Contributor

joel-u410 commented Jan 6, 2025

Does this PR depend on anoma/namada#4196?

Hi @brentstone @neocybereth -- no, currently it does not, but after anoma/namada#4196 is merged I would like this one to be updated to take advantage of it.

Right now, in this branch, it only queries "current epoch" rewards, and just assigns the current epoch number to their records -- after anoma/namada#4196 is merged I would want to change this to use the epoch argument to be more precise about which epoch is being requested when rewards are indexed.

(I have a Draft commit where I've started working on that, including adding support for --backfill-from to rewards -- see #193 for context on the --backfill-from feature)

@joel-u410
Copy link
Contributor

joel-u410 commented Jan 9, 2025

Just realized something here ... delete_claimed_rewards is now going to delete things it shouldn't.

Instead of deleting, it should probably insert rows with raw_amount = 0 to indicate they've been claimed.

Which will need to be distinguished somehow from the pos_rewards entry in the same epoch.

We'll probably need to add a column -- either block_height perhaps (to indicate the block where claim occurred) or maybe just a boolean claimed column would work.

@joel-u410
Copy link
Contributor

@neocybereth I'm looking at the existing /pos/reward/:address endpoint and it also needs to be updated to return only the latest reward -- right now it's returning every reward from every epoch in a giant list 😁

@neocybereth
Copy link
Contributor Author

@joel-u410 epic, tahnk you for the heads up! What's your go to testing methodology here? I'm just shooting in the dark and YOLO-ing atm and surely there's gotta be a better way :D

@neocybereth
Copy link
Contributor Author

something is messed up in here :S

Yeaaaaa it was my rebase. I'm going to have to go through and piece the PR back together.

@sug0
Copy link
Collaborator

sug0 commented Feb 19, 2025

do you still have the old tip of your branch in your git reflog? it would be easier to take that as a starting point

@neocybereth
Copy link
Contributor Author

do you still have the old tip of your branch in your git reflog? it would be easier to take that as a starting point

omg you're a lifesaver!

@neocybereth neocybereth force-pushed the feat/add-total-reward-for-epoch branch from 6d45623 to 7320744 Compare February 21, 2025 04:01
@neocybereth neocybereth changed the base branch from 1.0.0-maint to main February 21, 2025 04:02
@neocybereth
Copy link
Contributor Author

@Fraccaman okay, we're back to clean. Everythings up-to-date against main.

Anything else I need to do before getting approval? Shall I attempt another (hopefully successful :D) rebase against 1.0.0-maint from here?

@Fraccaman
Copy link
Member

@neocybereth can you take a look at. theci failures?

@neocybereth neocybereth requested review from Fraccaman and joel-u410 and removed request for joel-u410 March 11, 2025 08:58
@neocybereth
Copy link
Contributor Author

@Fraccaman sorry I've been busy with other work! I've fixed up all the CI issues.

@neocybereth
Copy link
Contributor Author

Fixed those up @sug0

@neocybereth neocybereth requested a review from sug0 March 14, 2025 00:09
@neocybereth neocybereth changed the title feat: add total reward for epoch feat: add total reward for epoch for each user Mar 25, 2025
@neocybereth
Copy link
Contributor Author

@Fraccaman @sug0 just checking back in to see if these are good to merge?

@sug0 sug0 added this pull request to the merge queue Mar 31, 2025
Merged via the queue into anoma:main with commit a8e87b1 Mar 31, 2025
14 checks passed
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.

5 participants