Skip to content

Update the topic's state and weight on RemoveStakes()#773

Merged
xmariachi merged 1 commit intodevfrom
ENGN-3511
May 7, 2025
Merged

Update the topic's state and weight on RemoveStakes()#773
xmariachi merged 1 commit intodevfrom
ENGN-3511

Conversation

@fernandofcampos
Copy link
Contributor

@fernandofcampos fernandofcampos commented Mar 18, 2025

Purpose of Changes and their Description

The issue:

  • The RemoveStakes and RemoveDelegateStakes functions were reducing a topic's staking amount
  • However, they were not updating the topic's weight or the totalSumPreviousTopicWeights
  • This was causing unfair distribution of rewards, as inactive topics or topics with reduced stake were still receiving a share of rewards they shouldn't

The fix:

  • When stake is removed from a topic, the topic's weight is immediately recalculated
  • The totalSumPreviousTopicWeights value is updated accordingly
  • This ensures that reward distribution is fair and accurate
  • Topics that should receive a larger share now do

Link(s) to Ticket(s) or Issue(s) resolved by this PR

https://linear.app/alloralabs/issue/ENGN-3511/136-the-removestakes-function-does-not-update-the-topics-state-or

Are these changes tested and documented?

  • If tested, please describe how. If not, why tests are not needed.
  • If documented, please describe where. If not, describe why docs are not needed.
  • Added to Unreleased section of CHANGELOG.md?

Still Left Todo

Fill this out if this is a Draft PR so others can help.

Copy link
Contributor

@guilherme-brandao guilherme-brandao left a comment

Choose a reason for hiding this comment

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

Looks good! Just need to add tests that check the topic weight recalculation

@fernandofcampos
Copy link
Contributor Author

Looks good! Just need to add tests that check the topic weight recalculation

Done.

Copy link
Contributor

@xmariachi xmariachi left a comment

Choose a reason for hiding this comment

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

Left some comments

@fernandofcampos fernandofcampos force-pushed the ENGN-3511 branch 4 times, most recently from 76c8251 to 60ec66f Compare March 20, 2025 12:34
Copy link
Contributor

@amimart amimart left a comment

Choose a reason for hiding this comment

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

I noticed that there's an end blocker updating topic weights, AFAIU topic weights depends on stake only, so since we now update topic weights when stake is added or removed we should removed this end blocker cc @xmariachi @guilherme-brandao

amimart
amimart previously approved these changes Mar 24, 2025
Copy link
Contributor

@amimart amimart left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Contributor

@xmariachi xmariachi left a comment

Choose a reason for hiding this comment

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

Please do not merge this just yet; there is a quirk I want to check with research re. cadence of updates. Setting review as "Request Changes" to block it explicitly

@fernandofcampos fernandofcampos force-pushed the ENGN-3511 branch 4 times, most recently from 53a330b to 0307085 Compare March 25, 2025 16:36
@xmariachi
Copy link
Contributor

xmariachi commented Apr 29, 2025

I noticed that there's an end blocker updating topic weights, AFAIU topic weights depends on stake only, so since we now update topic weights when stake is added or removed we should removed this end blocker cc @xmariachi @guilherme-brandao

Hey @amimart , topic weights depend on reputers' stake and topicFeeRevenue. In the EndBlocker the topicFeeRevenue is modified in the EndBlocker (where the feeRevenue is "dripped") so we shouldn't remove it from there, I believe.

@amimart
Copy link
Contributor

amimart commented Apr 29, 2025

Hey @amimart , topic weights depend on reputers' stake and topicFeeRevenue. In the EndBlocker the topicFeeRevenue is modified in the EndBlocker (where the feeRevenue is "dripped") so we shouldn't remove it from there, I believe.

@xmariachi Yeah you're right we need to keep this EndBlocker

@fernandofcampos fernandofcampos force-pushed the ENGN-3511 branch 2 times, most recently from 13d24fb to 53f7ee1 Compare May 2, 2025 15:30
xmariachi
xmariachi previously approved these changes May 5, 2025
Copy link
Contributor

@xmariachi xmariachi left a comment

Choose a reason for hiding this comment

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

I think it is consistent with the other topic operations (which happen at that time too).
LGTM, please rebase.

amimart
amimart previously approved these changes May 6, 2025
Copy link
Contributor

@xmariachi xmariachi left a comment

Choose a reason for hiding this comment

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

lgtm!

@xmariachi xmariachi merged commit 5522994 into dev May 7, 2025
11 checks passed
@xmariachi xmariachi deleted the ENGN-3511 branch May 7, 2025 12:15
zale144 pushed a commit that referenced this pull request May 13, 2025
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
v           ✰  Thanks for creating a PR! You're awesome! ✰
v Please note that maintainers will only review those PRs with a
completed PR template.
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >  -->

The issue:
- The RemoveStakes and RemoveDelegateStakes functions were reducing a
topic's staking amount
- However, they were not updating the topic's weight or the
totalSumPreviousTopicWeights
- This was causing unfair distribution of rewards, as inactive topics or
topics with reduced stake were still receiving a share of rewards they
shouldn't

The fix:
- When stake is removed from a topic, the topic's weight is immediately
recalculated
- The totalSumPreviousTopicWeights value is updated accordingly
- This ensures that reward distribution is fair and accurate
- Topics that should receive a larger share now do

https://linear.app/alloralabs/issue/ENGN-3511/136-the-removestakes-function-does-not-update-the-topics-state-or

- [x] If tested, please describe how. If not, why tests are not needed.
- [ ] If documented, please describe where. If not, describe why docs
are not needed.
- [x] Added to `Unreleased` section of `CHANGELOG.md`?

*Fill this out if this is a Draft PR so others can help.*
zale144 pushed a commit that referenced this pull request Jun 2, 2025
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
v           ✰  Thanks for creating a PR! You're awesome! ✰
v Please note that maintainers will only review those PRs with a
completed PR template.
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >  -->

The issue:
- The RemoveStakes and RemoveDelegateStakes functions were reducing a
topic's staking amount
- However, they were not updating the topic's weight or the
totalSumPreviousTopicWeights
- This was causing unfair distribution of rewards, as inactive topics or
topics with reduced stake were still receiving a share of rewards they
shouldn't

The fix:
- When stake is removed from a topic, the topic's weight is immediately
recalculated
- The totalSumPreviousTopicWeights value is updated accordingly
- This ensures that reward distribution is fair and accurate
- Topics that should receive a larger share now do

https://linear.app/alloralabs/issue/ENGN-3511/136-the-removestakes-function-does-not-update-the-topics-state-or

- [x] If tested, please describe how. If not, why tests are not needed.
- [ ] If documented, please describe where. If not, describe why docs
are not needed.
- [x] Added to `Unreleased` section of `CHANGELOG.md`?

*Fill this out if this is a Draft PR so others can help.*
zale144 pushed a commit that referenced this pull request Jun 2, 2025
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
v           ✰  Thanks for creating a PR! You're awesome! ✰
v Please note that maintainers will only review those PRs with a
completed PR template.
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >  -->

The issue:
- The RemoveStakes and RemoveDelegateStakes functions were reducing a
topic's staking amount
- However, they were not updating the topic's weight or the
totalSumPreviousTopicWeights
- This was causing unfair distribution of rewards, as inactive topics or
topics with reduced stake were still receiving a share of rewards they
shouldn't

The fix:
- When stake is removed from a topic, the topic's weight is immediately
recalculated
- The totalSumPreviousTopicWeights value is updated accordingly
- This ensures that reward distribution is fair and accurate
- Topics that should receive a larger share now do

https://linear.app/alloralabs/issue/ENGN-3511/136-the-removestakes-function-does-not-update-the-topics-state-or

- [x] If tested, please describe how. If not, why tests are not needed.
- [ ] If documented, please describe where. If not, describe why docs
are not needed.
- [x] Added to `Unreleased` section of `CHANGELOG.md`?

*Fill this out if this is a Draft PR so others can help.*
zale144 pushed a commit that referenced this pull request Jun 2, 2025
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
v           ✰  Thanks for creating a PR! You're awesome! ✰
v Please note that maintainers will only review those PRs with a
completed PR template.
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >  -->

The issue:
- The RemoveStakes and RemoveDelegateStakes functions were reducing a
topic's staking amount
- However, they were not updating the topic's weight or the
totalSumPreviousTopicWeights
- This was causing unfair distribution of rewards, as inactive topics or
topics with reduced stake were still receiving a share of rewards they
shouldn't

The fix:
- When stake is removed from a topic, the topic's weight is immediately
recalculated
- The totalSumPreviousTopicWeights value is updated accordingly
- This ensures that reward distribution is fair and accurate
- Topics that should receive a larger share now do

https://linear.app/alloralabs/issue/ENGN-3511/136-the-removestakes-function-does-not-update-the-topics-state-or

- [x] If tested, please describe how. If not, why tests are not needed.
- [ ] If documented, please describe where. If not, describe why docs
are not needed.
- [x] Added to `Unreleased` section of `CHANGELOG.md`?

*Fill this out if this is a Draft PR so others can help.*

# Conflicts:
#	x/emissions/keeper/keeper_test.go
#	x/emissions/module/rewards/nonce_management_test.go
#	x/emissions/module/rewards/rewards_test.go
#	x/emissions/module/rewards/scores_test.go
#	x/emissions/module/rewards/topic_rewards_test.go
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.

4 participants