Skip to content

Fix conviction aggregate roll-forward - #3060

Open
UnArbosFour wants to merge 9 commits into
mainfrom
fix/zero-lock-aggregates
Open

Fix conviction aggregate roll-forward#3060
UnArbosFour wants to merge 9 commits into
mainfrom
fix/zero-lock-aggregates

Conversation

@UnArbosFour

Copy link
Copy Markdown
Contributor

Summary

Fixes conviction-lock aggregate accounting and tightens subnet takeover eligibility.

Changes

  • Reworks aggregate roll-forward using detach–roll–recombine accounting.
  • Prevents sibling lock maturation from being skipped when one member is updated.
  • Prevents individual conviction from being counted twice after an aggregate-only roll.
  • Preserves dust cleanup, owner conviction, lock moves, and transfer behavior.
  • Requires the leading challenger hotkey to independently hold at least 10% of SubnetAlphaOut.
  • Prevents incumbent or unrelated lock buckets from supplying a challenger’s takeover quorum.
  • Adds regression coverage for both aggregate-accounting issues and takeover scenarios.

Testing

  • Full pallet suite: 1,400 passed, 0 failed, 9 ignored.
  • All active lock tests pass.
  • Formatting and diff checks pass.

… challengers to independently meet the 10% conviction threshold.
@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
subtensor Ready Ready Preview Aug 7, 2026 10:39pm

Request Review

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🛡️ AI Review — Skeptic (security review)

VERDICT: SAFE

VERY HIGH scrutiny (young account, one public repository), tempered by repository write access; two scoped UnArbosFive follow-up commits; no Gittensor association found; fix/zero-lock-aggregates → main.

The AI-review trust boundary is unchanged, and the runtime-affecting changes include the required spec_version bump. Static analysis found no security vulnerability in the aggregate rebuild migration, synchronized lock accounting, ownership transitions, takeover threshold, or lock-transfer paths.

Findings

No findings.

Conclusion

The migration reconstructs aggregates from canonical lock rows with saturating arithmetic, while the detach–roll–recombine flow keeps individual and aggregate state synchronized. No malicious behavior or security vulnerability was found.


🔍 AI Review — Auditor (domain review)

VERDICT: 👎

LIKELY Gittensor-associated contributor; young public account with repository write access and prior merged subtensor contributions, while runtime changes still receive full scrutiny.

The lock-accounting changes and regression tests appear coherent, and spec_version is bumped to 444. No overlapping PR addresses the same defect.

Description discrepancy

The PR body still omits the one-shot runtime migration that scans and rewrites every individual lock row, rebuilds five indexes/aggregate maps, and removes dust. This deployment impact should be documented.

Static analysis was sufficient; no runtime checks were needed.

Findings

Sev File Finding
HIGH pallets/subtensor/src/migrations/migrate_rebuild_conviction_aggregates.rs:48 Add try-runtime migration invariants inline
HIGH pallets/subtensor/src/migrations/migrate_rebuild_conviction_aggregates.rs:75 Bound the runtime-upgrade migration inline

Prior-comment reconciliation

  • b78c9398: not addressed — The migration still provides no try-runtime pre/post invariant checks.
  • bfcd2568: not addressed — Observed counts still do not bound the full lock iteration, allocation, five prefix clears, and rewrites.

Conclusion

The functional fix appears sound, but the migration remains structurally unbounded and lacks try-runtime invariant validation. Both migration-safety blockers must be resolved before merge.


📜 Previous run (superseded)
Sev File Finding Status
HIGH pallets/subtensor/src/migrations/migrate_rebuild_conviction_aggregates.rs:48 Add try-runtime migration invariants ➡️ Carried forward to current findings
The migration still provides no try-runtime pre/post invariant checks.
HIGH pallets/subtensor/src/migrations/migrate_rebuild_conviction_aggregates.rs:75 Bound the runtime-upgrade migration ➡️ Carried forward to current findings
Observed counts still do not bound the full lock iteration, allocation, five prefix clears, and rewrites.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: VULNERABLE

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment thread pallets/subtensor/src/staking/lock.rs Outdated
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: VULNERABLE

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

/// if it has become dust), then merged into its appropriate new aggregate.
/// This preserves earned conviction while establishing one common timestamp
/// for every individual and aggregate contribution.
pub fn migrate_rebuild_conviction_aggregates<T: Config>() -> Weight {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[HIGH] Add try-runtime migration invariants

This state-rewriting migration still has no pre_upgrade/post_upgrade checks. Add try-runtime validation that records canonical lock totals/counts before execution and verifies afterward that retained individual locks and all four rebuilt aggregate maps agree by lock class, dust rows are absent, and the reverse index exactly matches retained locks. Unit tests of selected fixtures do not validate the migration against arbitrary live state.

weight = weight.saturating_add(T::DbWeight::get().reads(3));

// Collect before rewriting Lock so mutation cannot disturb the iterator.
let locks: Vec<_> = Lock::<T>::iter().collect();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[HIGH] Bound the runtime-upgrade migration

Lock::iter().collect() remains unbounded, followed by five clear(u32::MAX, None) operations and rewrites proportional to all retained locks. The observed mainnet counts document current size but do not enforce an execution bound or protect against state growth before deployment. Use a staged/cursor-based migration with bounded work per block, or enforce a conservative hard bound before allocating and prove the complete worst-case weight fits the runtime-upgrade budget.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants