Skip to content

Feat/staking precompile coldkey netuid stake info#2848

Closed
fine135 wants to merge 2 commits into
RaoFoundation:devnet-readyfrom
bittensor-church:feat/staking-precompile-coldkey-netuid-stake-info
Closed

Feat/staking precompile coldkey netuid stake info#2848
fine135 wants to merge 2 commits into
RaoFoundation:devnet-readyfrom
bittensor-church:feat/staking-precompile-coldkey-netuid-stake-info

Conversation

@fine135

@fine135 fine135 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description

Adds getStakeInfoForColdkeyAndNetuid(bytes32 coldkey, uint16 netuid) as a view function to StakingPrecompileV2, allowing smart contracts to query the stake positions a coldkey holds on a given subnet. It returns each hotkey the coldkey stakes to together with its alpha stake, as StakeInfo[] ({ bytes32 hotkey; uint256 stake; }); hotkeys with zero stake on that subnet are omitted. The function enumerates StakingHotkeys and reads get_stake_for_hotkey_and_coldkey_on_subnet per hotkey — mirroring the per-subnet slice of the get_stake_info_for_coldkey runtime API — and explicitly records db_read_gas_cost for every storage read so callers are correctly charged when invoked from within a contract.

Also adds the corresponding StakeInfo struct and function to precompiles/src/solidity/stakingV2.sol, unit tests in precompiles/src/staking.rs, and bumps the runtime spec_version.

Related Issue(s)

  • N/A

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Breaking Change

N/A

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run ./scripts/fix_rust.sh to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screenshots (if applicable)

N/A

Additional Notes

The function follows the same pattern as the other view functions in StakingPrecompileV2 (e.g. getStake, getAlphaStakedValidators), charging gas per storage read via handle.record_db_reads::<R>(...) — one read for the StakingHotkeys index plus two per hotkey visited — so an oversized index reverts on gas exhaustion rather than doing unbounded work. netuid is a required parameter and only (hotkey, stake) is returned, since returning the fixed netuid would be redundant. The existing get_stake_info_for_coldkey runtime API is intentionally not reused: its StakeInfo fields are private, and it computes fields we don't need (emission, tao_emission, is_registered, ...), so a dedicated storage read is both necessary and cheaper.

fine135 added 2 commits July 9, 2026 22:09
Returns every hotkey a coldkey stakes to on a given subnet together with its alpha stake, as StakeInfo[] { bytes32 hotkey; uint256 stake; }; hotkeys with zero stake on that netuid are omitted.
@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

@fine135 is attempting to deploy a commit to the RaoFoundation Team on Vercel.

A member of the Team first needs to authorize it.

@UnArbosSix UnArbosSix closed this Jul 10, 2026
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