Skip to content

Accumulated subgraph rewards reset to zero on edge case #452

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 3 commits into from
Apr 27, 2021

Conversation

abarmat
Copy link
Contributor

@abarmat abarmat commented Feb 17, 2021

Description

The RewardsManager contract main responsibility is to calculate rewards accrued for allocations based on the total token supply, tokens signalled on subgraphs, accumulated rewards on a subgraph and allocations. Under certain edge condition the calculation could fail and block closing an allocation that would collect rewards.

Problem

There is a particular edge case that happens when there are running allocations on a subgraph deployment ID, the total amount of curation signal is removed back to zero and closeAllocation() is called by an indexer. If this happens, the indexer won't be able to close that allocation unless it is opting for no rewards by sending POI=0x0. The reason for this is that getAccRewardsForSubgraph() is reseting the accumulated rewards for a subgraph when the curation pool is empty. The consequence is that subgraph.accRewardsForSubgraphSnapshot can be larger than subgraph.accRewardsForSubgraph leading to a revert when calculating new accrued rewards.

Solution

By removing the early check within getAccRewardsForSubgraph() that returns zero for the subgraph accumulated rewards when the signal is zero we will always return the accumulated amount, as it should be an ever increasing number.

Additional Changes

  • Check that rewards > 0 before minting
  • Linting differences
  • Improve some comments

@abarmat abarmat added the bug Something isn't working label Feb 17, 2021
@abarmat abarmat requested a review from davekay100 February 17, 2021 21:23
@abarmat abarmat force-pushed the ariel/fix-nosignal-rewards branch from 8772dfe to 63e300e Compare February 21, 2021 21:13
@abarmat abarmat added the GIP label Mar 30, 2021
@abarmat abarmat force-pushed the ariel/fix-nosignal-rewards branch from 63e300e to c4f1c09 Compare April 1, 2021 16:23
@abarmat abarmat force-pushed the ariel/fix-nosignal-rewards branch from c4f1c09 to fd8683b Compare April 27, 2021 16:59
@abarmat
Copy link
Contributor Author

abarmat commented Apr 27, 2021

Rebased

@abarmat abarmat merged commit 7e9adca into master Apr 27, 2021
@abarmat abarmat deleted the ariel/fix-nosignal-rewards branch May 4, 2021 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audited bug Something isn't working GIP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant