fix: handle over allocated condition correctly #1154
Merged
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.
Problem
When an indexer is over-allocated (allocated tokens exceed provisioned stake + delegated stake), the unallocate operation fails the simulation with
AllocationClosed(0x61b66e0d) error. This happens because:collect(),stopService()] (stopService()is the newcloseAllocation())collect(), the contract presents POI, collects rewards and then checks for over allocated condition_closeAllocation()closing the allocationstopService()executes and tries to close an already-closed allocation → revertsSolution
Before building the unallocate transaction, check
SubgraphService.isOverAllocated(allocationId):collect()— it will auto-close the allocationcollect(),stopService()]Note that it's possible for the indexer to be over allocated when the agent checks for the condition, but under allocated once the transaction (consisting of just
collect()) is confirmed on chain. In this case, on chain the indexer would have collected rewards but the allocation would remain open. The agent handles this well, it will expect anAllocationClosedevent regardless of the calls being made, if it does not find one it will mark the action as failed. Retrying it later will result in the allocation being closed correctly (and potentially new rewards being collected as well).Also fixed event detection for
graph indexer allocation closecommand to look forAllocationClosedinstead ofServiceStopped, sinceAllocationClosedis emitted in both paths.