Skip to content

Fix(rewards): apply collateral in repo allocation#1272

Open
Desel72 wants to merge 7 commits into
entrius:testfrom
Desel72:fix/repo-allocation-collateral
Open

Fix(rewards): apply collateral in repo allocation#1272
Desel72 wants to merge 7 commits into
entrius:testfrom
Desel72:fix/repo-allocation-collateral

Conversation

@Desel72
Copy link
Copy Markdown
Contributor

@Desel72 Desel72 commented May 14, 2026

Summary

Applies finalized open-PR collateral when collecting repo-local PR allocation scores, so contributors with collateral are allocated from merged earned_score - same-repo collateral_score clamped at zero.

This keeps no-collateral allocation proportional to merged PR scores while making repo-bounded emission allocation agree with the collateral-adjusted scoring output.

Related Issues

Fixes #1266

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Other (describe below)

Testing

  • Tests added/updated
  • Manually tested
uv run pytest tests/validator/test_blend_emission_pools.py -q
uv run ruff check gittensor/validator/emission_allocation.py tests/validator/test_blend_emission_pools.py
uv run ruff format --check gittensor/validator/emission_allocation.py tests/validator/test_blend_emission_pools.py

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Changes are documented (if applicable)

@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label May 14, 2026
Copy link
Copy Markdown
Collaborator

@anderdc anderdc left a comment

Choose a reason for hiding this comment

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

Premise is correct — collateral currently has no effect on emissions; blend_emission_pools is the only weight input and it never reads the collateral-adjusted score. But the fix re-derives that score instead of reading the one finalization already computed.

finalize_miner_scores() stores the collateral-adjusted, clamped, per-repo PR score on evaluation.repo_evaluations[repo].total_score (scoring.py:166max(0.0, total_score - total_collateral_score)). _collect_repo_pr_scores now re-sums merged_prs[].earned_score minus open_prs[].collateral_score and re-clamps — a second copy of that formula. That is the divergence #1266 reports, recreated one layer down: the next time collateral handling changes in scoring.py, the allocator silently drifts again.

Blocker — gittensor/validator/emission_allocation.py, _collect_repo_pr_scores (lines 121-127): use evaluation.repo_evaluations.get(repo_name) and its .total_score instead of re-summing and re-clamping. It is already collateral-adjusted, clamped, repo-local, and PR-only (issue discovery writes separate repo_eval fields), and finalize_miner_scores() runs before blend_emission_pools(), so it is populated.

Blocker — tests/validator/test_blend_emission_pools.py: populate repo_evaluations on the fixtures (or run finalize_miner_scores() first, as #1266's repro describes) so the regression exercises the real finalize -> blend path.

@Desel72 Desel72 force-pushed the fix/repo-allocation-collateral branch from 5e9a8dc to ab01ffc Compare May 22, 2026 21:51
@anderdc anderdc changed the title fix(rewards): apply collateral in repo allocation Fix(rewards): apply collateral in repo allocation May 23, 2026
@Desel72
Copy link
Copy Markdown
Contributor Author

Desel72 commented May 23, 2026

Hi. @anderdc Could you plz review my PR again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Repo allocation ignores open-PR collateral deductions

2 participants