Add TotalAlphaStaked counter per netuid - #3085
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| let previous = TotalHotkeyAlpha::<T>::get(&self.hotkey, self.netuid); | ||
| let value = AlphaBalance::from(value); | ||
| TotalAlphaStaked::<T>::mutate(self.netuid, |total| { |
There was a problem hiding this comment.
[MEDIUM] Stake mutations add unaccounted database I/O
This shared path now adds a TotalHotkeyAlpha read plus a TotalAlphaStaked read/write to every affected staking operation, but the PR does not update or regenerate the corresponding dispatch weights. Repeated calls can therefore consume more database resources than the block weight system charges. Regenerate the affected benchmarks/weights and include the resulting weight changes.
🛡️ AI Review — Skeptic (security review)VERDICT: VULNERABLE VERY HIGH scrutiny (47-day-old account and one public repo), tempered by repository write access and substantive merged contributions; release-448 target, no Gittensor association found. The prior weight-accounting concern remains after the latest merge commit. Findings
Prior-comment reconciliation
ConclusionThe aggregate accounting appears internally consistent, but ordinary stake mutations remain undercharged for the newly added storage I/O. 📜 Previous run (superseded)
# 🔍 AI Review — Auditor (domain review) has not yet run on this PR. |
|
🔄 AI review updated — Skeptic: VULNERABLE |
…ounting-staking-total
| let previous = TotalHotkeyAlpha::<T>::get(&self.hotkey, self.netuid); | ||
| let value = AlphaBalance::from(value); | ||
| TotalAlphaStaked::<T>::mutate(self.netuid, |total| { |
There was a problem hiding this comment.
[MEDIUM] Stake mutations add unaccounted database I/O
set_shared_value now adds a TotalHotkeyAlpha read plus a TotalAlphaStaked read/write to every shared-pool mutation. The PR adjusts cleanup metering, but does not regenerate or conservatively update the weights of the many extrinsics that reach this method. Those calls can therefore consume more block resources than they declare. Regenerate the affected benchmarks/weights, or explicitly add the new database costs to every reachable weighted path.
|
🔄 AI review updated — Skeptic: VULNERABLE |
Co-authored-by: Cursor <cursoragent@cursor.com> #3085 added TotalAlphaStaked storage, so the SDK read, stub, query page, and catalogs can ship again. Regenerated docs for the merged limit-order and staking changes.
Description
Adds
TotalAlphaStaked, an O(1) per-subnet aggregate of all alpha currently staked across hotkeys.The maintained invariant is:
Changes
TotalAlphaStaked, keyed bynetuid.TotalHotkeyAlphachanges through the shared staking pool logic.TotalHotkeyAlphaentries.448.Motivation
Consumers currently need to iterate over every
TotalHotkeyAlphaentry to determine the total alpha staked on a subnet. Maintaining this aggregate makes that value directly queryable while preserving the existing per-hotkey accounting as the source of truth.Type of Change
Breaking Change
None.
Testing
Added invariant-based coverage for:
The tests compare
TotalAlphaStakedagainst the sum of allTotalHotkeyAlphaentries for the relevant subnet.Additional Notes
Zero-valued
TotalAlphaStakedentries are permitted. Subnet dissolution explicitly removes the entry along with the subnet’s other state.