Feat/staking precompile coldkey netuid stake info#2848
Closed
fine135 wants to merge 2 commits into
Closed
Conversation
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.
|
@fine135 is attempting to deploy a commit to the RaoFoundation Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
getStakeInfoForColdkeyAndNetuid(bytes32 coldkey, uint16 netuid)as a view function toStakingPrecompileV2, 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, asStakeInfo[]({ bytes32 hotkey; uint256 stake; }); hotkeys with zero stake on that subnet are omitted. The function enumeratesStakingHotkeysand readsget_stake_for_hotkey_and_coldkey_on_subnetper hotkey — mirroring the per-subnet slice of theget_stake_info_for_coldkeyruntime API — and explicitly recordsdb_read_gas_costfor every storage read so callers are correctly charged when invoked from within a contract.Also adds the corresponding
StakeInfostruct and function toprecompiles/src/solidity/stakingV2.sol, unit tests inprecompiles/src/staking.rs, and bumps the runtimespec_version.Related Issue(s)
Type of Change
Breaking Change
N/A
Checklist
./scripts/fix_rust.shto ensure my code is formatted and linted correctlyScreenshots (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 viahandle.record_db_reads::<R>(...)— one read for theStakingHotkeysindex plus two per hotkey visited — so an oversized index reverts on gas exhaustion rather than doing unbounded work.netuidis a required parameter and only(hotkey, stake)is returned, since returning the fixed netuid would be redundant. The existingget_stake_info_for_coldkeyruntime API is intentionally not reused: itsStakeInfofields 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.