Accumulated subgraph rewards reset to zero on edge case #452
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thatgetAccRewardsForSubgraph()
is reseting the accumulated rewards for a subgraph when the curation pool is empty. The consequence is thatsubgraph.accRewardsForSubgraphSnapshot
can be larger thansubgraph.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