Skip to content

feat(chain-extensions): add read-only WASM queries for subnet registration, coldkey lock, and stake availability#2768

Merged
open-junius merged 3 commits into
opentensor:devnet-readyfrom
silva-fj:feat/wasm-readonly-chain-extensions
Jun 23, 2026
Merged

feat(chain-extensions): add read-only WASM queries for subnet registration, coldkey lock, and stake availability#2768
open-junius merged 3 commits into
opentensor:devnet-readyfrom
silva-fj:feat/wasm-readonly-chain-extensions

Conversation

@silva-fj

@silva-fj silva-fj commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Description

Adds three new read-only chain extension functions so ink!/WASM smart contracts can query subtensor state that was previously inaccessible from contracts:

ID Function Input Output
34 get_subnet_registration_state (NetUid) SubnetRegistrationState { netuid, exists, registered_subnet_counter }
35 get_coldkey_lock (AccountId, NetUid) Option<ColdkeyLock { locked_mass, conviction_bits, last_update }>
36 get_stake_availability (AccountId, NetUid) StakeAvailability { netuid, total, locked, available }

These are additive (new function IDs 34–36) and read-only — no existing chain extension function or ABI is changed, so already-deployed contracts are unaffected.

Implementation

  • chain-extensions/src/types.rs — new FunctionId variants (34–36) and SCALE-encodable result structs (SubnetRegistrationState, ColdkeyLock, StakeAvailability), each frozen with #[freeze_struct(..)].
  • chain-extensions/src/lib.rs — dispatch handlers that decode inputs and write SCALE-encoded outputs.
  • pallets/subtensor/src/staking/lock.rsPallet::stake_availability changed from pub(crate) to pub so the chain extension can reuse it.
  • contract-tests/bittensor/lib.rs — ink! chain-extension bindings and contract message wrappers for the three new functions.
  • docs/wasm-contracts.md — documents the three new functions.

Type of Change

  • New feature (non-breaking change which adds functionality)

Breaking Change

None. The new functions are additive at new IDs and read-only; no existing function signature or ABI changes. (The pre-existing docs caveat about functions 16/17 argument order is unrelated and unchanged by this PR.)

@silva-fj silva-fj marked this pull request as ready for review June 22, 2026 08:20
Comment thread chain-extensions/src/types.rs Outdated
Comment thread chain-extensions/src/types.rs Outdated
open-junius
open-junius previously approved these changes Jun 22, 2026

@open-junius open-junius 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.

Looks good, left two trivial comments.

silva-fj added 3 commits June 22, 2026 15:53
…ation, coldkey lock, and stake availability

Adds three additive chain extension functions (IDs 34-36) for ink! contracts:
- get_subnet_registration_state -> SubnetRegistrationState
- get_coldkey_lock -> Option<ColdkeyLock>
- get_stake_availability -> StakeAvailability

Includes runtime handlers, encodable types (frozen via #[freeze_struct]),
ink! contract bindings, unit tests, and docs. Makes Pallet::stake_availability
public so the chain extension can reuse it.
@silva-fj silva-fj force-pushed the feat/wasm-readonly-chain-extensions branch from c3eb6ad to aadc739 Compare June 22, 2026 13:54
@open-junius open-junius added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Jun 22, 2026
@open-junius open-junius merged commit 13ffe76 into opentensor:devnet-ready Jun 23, 2026
426 of 432 checks passed
@open-junius open-junius mentioned this pull request Jun 25, 2026
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants