Skip to content

Suggested follow-up to #1203: extract helper + add IE090 tests#1205

Merged
tmigone merged 2 commits intotmigone/fix-overallocationfrom
mb9/over-allocation-helper-and-tests
Apr 28, 2026
Merged

Suggested follow-up to #1203: extract helper + add IE090 tests#1205
tmigone merged 2 commits intotmigone/fix-overallocationfrom
mb9/over-allocation-helper-and-tests

Conversation

@MoonBoi9001
Copy link
Copy Markdown
Member

Motivation

While reviewing #1203, two things stood out: the new over-allocation guard is duplicated byte-for-byte across the resolver path (reallocateHorizonAllocation) and the action-queue path (AllocationManager.populateReallocateTransaction), and the new IE090 throw has no test coverage. Without a shared helper, any future tweak to the guard — error message, additional diagnostic reads, metrics — has to happen twice and will eventually drift. Without tests, the guard could silently regress and we'd only find out when an over-allocated indexer hit the path in production.

This branch is offered as a suggestion stacked on top of #1203, not a replacement. Take, modify, or discard.

Summary

Two commits, each independent:

  • refactor(allocations): extract over-allocation guard into shared helper — moves the duplicated 30-line block into assertNotOverAllocated in a new over-allocation.ts module. Both call sites in fix: gracefully handle overallocation when reallocating #1203 now invoke the helper. Side improvements while extracting:

    • Parallelises the two independent reads (allocationProvisionTracker and getDelegationRatio) — saves one round-trip on the error path.
    • Clamps the over-allocated delta to 0n to defend against a negative bigint formatting into the error message if the three reads race.
    • Reworks the IE090 message to point operators at graph indexer allocations close (which already handles over-allocation gracefully and still collects rewards) instead of the ambiguous "manually unallocate that amount."
  • test(allocations): cover IE090 over-allocation guard for reallocate — four pure-unit tests against assertNotOverAllocated:

    1. happy path returns silently and skips the diagnostic reads
    2. over-allocated path throws IndexerError with code === IE090 and the GRT delta in the cause string
    3. verifier address (SubgraphService.target) and delegation ratio are forwarded correctly to HorizonStaking.getTokensAvailable
    4. negative delta from racing reads is clamped — message says 0.0 GRT, no minus sign

Verified

  • yarn compile clean against locked @graphprotocol/toolshed@1.1.1
  • yarn lint clean
  • yarn test src/indexer-management/__tests__/over-allocation.test.ts — 4/4 passing

Notes

  • The error message rewording is the most opinionated change here. If you'd rather keep "manually unallocate that amount," easy to back out — single line in the helper.
  • I did not extend the helper to the existing close paths (closeHorizonAllocation and populateUnallocateTransaction) which also call isOverAllocated but with different branching semantics. Worth a separate refactor PR but out of scope for fix: gracefully handle overallocation when reallocating #1203.

MoonBoi9001 and others added 2 commits April 27, 2026 18:54
Both reallocate paths (resolver and AllocationManager) duplicated the same
30-line check-and-throw block. Extract `assertNotOverAllocated` so future
changes happen in one place. Parallelises the two independent reads
(`allocationProvisionTracker` and `getDelegationRatio`) and clarifies the
error message to point operators at `graph indexer allocations close` as
the way to still collect rewards when over-allocated.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds unit coverage for assertNotOverAllocated: happy path skips the
diagnostic reads, the over-allocated path throws IE090 with the GRT
delta in the message, the verifier address is forwarded correctly to
HorizonStaking.getTokensAvailable, and a negative delta from racing
reads is clamped so the error message never prints a negative amount.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-project-automation github-project-automation Bot moved this to 🗃️ Inbox in Indexer Apr 27, 2026
@MoonBoi9001 MoonBoi9001 requested a review from tmigone April 27, 2026 11:14
@tmigone tmigone merged commit 7ca69d2 into tmigone/fix-overallocation Apr 28, 2026
3 checks passed
@tmigone tmigone deleted the mb9/over-allocation-helper-and-tests branch April 28, 2026 18:24
@github-project-automation github-project-automation Bot moved this from 🗃️ Inbox to 🚗 Merged in Indexer Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🚗 Merged

Development

Successfully merging this pull request may close these issues.

2 participants