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 message to withdraw emission rewards #1811

Closed
wants to merge 8 commits into from

Conversation

kingpinXD
Copy link
Contributor

@kingpinXD kingpinXD commented Feb 27, 2024

Description

  • Add a message to enable observers to collect emission rewards

Closes: #1653

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Include instructions and any relevant details so others can reproduce.

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Checklist:

  • I have added unit tests that prove my fix feature works

@kingpinXD kingpinXD changed the title add a message to withdraw emission rewards feat: add a message to withdraw emission rewards Feb 27, 2024
@kingpinXD kingpinXD changed the title feat: add a message to withdraw emission rewards feat: add message to withdraw emission rewards Feb 27, 2024
Copy link

codecov bot commented Feb 27, 2024

Codecov Report

Attention: Patch coverage is 87.87879% with 12 lines in your changes are missing coverage. Please review.

Project coverage is 38.70%. Comparing base (cfd27a7) to head (d2e3fd9).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1811      +/-   ##
===========================================
+ Coverage    38.03%   38.70%   +0.66%     
===========================================
  Files          205      208       +3     
  Lines        12524    12623      +99     
===========================================
+ Hits          4764     4886     +122     
+ Misses        7372     7349      -23     
  Partials       388      388              
Files Coverage Δ
x/emissions/abci.go 85.58% <100.00%> (+3.36%) ⬆️
.../emissions/keeper/msg_server_withdraw_emissions.go 100.00% <100.00%> (ø)
x/emissions/keeper/withdraw_emissions.go 100.00% <100.00%> (ø)
x/emissions/keeper/withdrawable_emissions.go 100.00% <100.00%> (+100.00%) ⬆️
x/emissions/types/message_withdraw_emissions.go 42.85% <42.85%> (ø)

@kingpinXD kingpinXD marked this pull request as ready for review February 28, 2024 02:38
Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

I'm not sure to understand.
Why creating a withdraw object in the message and processing it in the endblocker, instead of directly processing it in the message?
What does the WithdrawEmission object brings on top of WithdrawableEmission?

Comment on lines +154 to +158
defer func() {
for _, withdrawEmission := range allWithdrawEmissions {
keeper.DeleteWithdrawEmissions(ctx, withdrawEmission.Address)
}
}()
Copy link
Member

Choose a reason for hiding this comment

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

Why using a defer here? It seems we never return an error in the function body

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used it just for code readability.

@kingpinXD
Copy link
Contributor Author

I'm not sure to understand. Why creating a withdraw object in the message and processing it in the endblocker, instead of directly processing it in the message? What does the WithdrawEmission object brings on top of WithdrawableEmission?

This is to prevent more than one emission withdraw in the same block. Although I can't really think of a condition which,would allow observers to withdraw more rewards than they own , Using the endblock and processing all withdraws in the block at once makes the logic a bit safer
I don't think it adds much of an overhead on top of a regular tx .

@kingpinXD kingpinXD requested a review from lumtis March 1, 2024 06:17
@lumtis
Copy link
Member

lumtis commented Mar 1, 2024

I'm not sure to understand. Why creating a withdraw object in the message and processing it in the endblocker, instead of directly processing it in the message? What does the WithdrawEmission object brings on top of WithdrawableEmission?

This is to prevent more than one emission withdraw in the same block. Although I can't really think of a condition which,would allow observers to withdraw more rewards than they own , Using the endblock and processing all withdraws in the block at once makes the logic a bit safer I don't think it adds much of an overhead on top of a regular tx .

I don't get it.

We have a WithdrawableEmissions object, already in the store, containing the amount an address can withdraw.
We're implementing a MsgWithdrawEmission that creates a WithdrawEmissions containing the exact same fields as above.
The end blocker iterates these WithdrawEmissions, send funds to user, delete WithdrawEmissions and subtract WithdrawableEmissions from value in WithdrawEmissions

Why not directly having MsgWithdrawEmission that decrease WithdrawableEmissions and send funds to user?

This is to prevent more than one emission withdraw in the same block.

Why is it a problem if we verify that the withdrawn amount is below withdrawable amount?

Although I can't really think of a condition which,would allow observers to withdraw more rewards than they own

How does using a intermediate end blocker add more protection for this?

@kingpinXD
Copy link
Contributor Author

Closing pr for now to make changes mentioned above cc @lumtis

@kingpinXD kingpinXD closed this Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

emissions : enable withdraw
2 participants