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

feat: add total reward for epoch #204

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

neocybereth
Copy link

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
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
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
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
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

brentstone commented Jan 2, 2025

Does this PR depend on anoma/namada#4196?

@neocybereth
Copy link
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
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
Author

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 @brentstone any idea when [anoma/namada#4196] will get merged in?

@joel-u410
Copy link
Contributor

resolved this one here: b129655

In my fork, for now, I've added this commit which fixes the /pos/reward/:address API route to restore its original behavior of returning only the current/latest reward entry.

I don't think your commit will work unless you also change the route in webserver/src/app.rs to be /pos/reward/:address/:epoch -- but that would be a breaking change to the API, and would require the caller to specify an epoch (which in most cases they probably won't want to do).

Perhaps though a 2nd endpoint, or optional epoch parameter, would be useful for (optionally) querying for past epochs. But I think the default should remain as "query latest epoch" if the user doesn't specify.

@joel-u410
Copy link
Contributor

@joel-u410 @brentstone any idea when [anoma/namada#4196] will get merged in?

I still need to write some unit tests for it, then I think it should be ready to merge -- pending review of course.

@neocybereth
Copy link
Author

resolved this one here: b129655

In my fork, for now, I've added this commit which fixes the /pos/reward/:address API route to restore its original behavior of returning only the current/latest reward entry.

I don't think your commit will work unless you also change the route in webserver/src/app.rs to be /pos/reward/:address/:epoch -- but that would be a breaking change to the API, and would require the caller to specify an epoch (which in most cases they probably won't want to do).

Perhaps though a 2nd endpoint, or optional epoch parameter, would be useful for (optionally) querying for past epochs. But I think the default should remain as "query latest epoch" if the user doesn't specify.

Nice, I updated that here: d36ec9e to match your commit

@Fraccaman
Copy link
Member

Fraccaman commented Jan 29, 2025

This looks very cool! I was wondering, do you think we could add a epoch query parameter to the v1/pos/reward/<address> route ?

@joel-u410
Copy link
Contributor

This looks very cool! I was wondering, do you think we could add a epoch query parameter to the v1/pos/reward/<address> route ?

@Fraccaman I took a shot at adding that in this commit. I haven't tested it however.

If this looks good, @neocybereth feel free to cherry-pick it into your branch here.

@neocybereth
Copy link
Author

Sounds good. Let me know if that's all good @Fraccaman and I'll cherry pick it in.

@neocybereth
Copy link
Author

neocybereth commented Feb 4, 2025

Alright I added in 68d63cf
in my latest commit 7320744 and also fixed all merge conflicts

@neocybereth neocybereth requested a review from joel-u410 February 4, 2025 00:35
@neocybereth
Copy link
Author

@joel-u410 I guess now that anoma/namada#4196 is merged this one needs to be updated to take advantage of it like you mentioned above?

If so, what in particular do you want done to this PR to update it accordingly?

@joel-u410
Copy link
Contributor

joel-u410 commented Feb 4, 2025

@joel-u410 I guess now that anoma/namada#4196 is merged this one needs to be updated to take advantage of it like you mentioned above?

If so, what in particular do you want done to this PR to update it accordingly?

I think this should be merged as-is, then we can follow up later to update it with the new functionality from anoma/namada#4196. That requires the RPC node to be updated in order to take advantage, so we'll probably need to wait till the next namada release for it anyway.

@neocybereth
Copy link
Author

neocybereth commented Feb 5, 2025

Roger that, thank you @joel-u410. @Fraccaman this is ready for a review when you next get a chance 🙏

@Fraccaman
Copy link
Member

I think this needs to be rebased 1.0.0-maint

@neocybereth neocybereth force-pushed the feat/add-total-reward-for-epoch branch from 9b76f1d to 928d0e0 Compare February 17, 2025 20:32
@neocybereth neocybereth changed the base branch from main to 1.0.0-maint February 17, 2025 20:33
@neocybereth
Copy link
Author

neocybereth commented Feb 17, 2025

Alright @Fraccaman I rebased to 1.0.0-maint but it doesn't seem right to me. @joel-u410 the changes left when comparign to 1.0.0-maint after rebase seem like many more files than I've touched, were there any additionals that you're seeing here that seem out of whack as well?

@neocybereth neocybereth changed the base branch from 1.0.0-maint to main February 17, 2025 21:48
@neocybereth neocybereth changed the base branch from main to 1.0.0-maint February 17, 2025 21:49
@Fraccaman
Copy link
Member

something is messed up in here :S

@neocybereth
Copy link
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
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
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?

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