Skip to content

Subnet Mechanism logic#3056

Merged
basfroman merged 41 commits intostagingfrom
feat/roman/sub-subnet
Sep 22, 2025
Merged

Subnet Mechanism logic#3056
basfroman merged 41 commits intostagingfrom
feat/roman/sub-subnet

Conversation

@basfroman
Copy link
Collaborator

@basfroman basfroman commented Sep 13, 2025

Usage:

Note

  • Let's imagine that subnet 14 has two subnet mechanisms.
  • All previously existing methods that now accept an additional mechid parameter continue to function identically to before when called with the default value mechid=0.
  • The behavior and outcome of these methods — including underlying extrinsic calls — remain unchanged whether the mechid argument is explicitly provided or omitted (i.e., defaults to 0).
  • In the following examples, we only consider the case where mechid needs to be passed to transmit or receive data from a subnet mechanism other than 0.
  • All extrinsiscs and methods are implemented for use in sync and async code.

- set_weights

Note

As before, set_weights works with the commit_reveal_enabled hyperparameter enabled and disabled.

import bittensor as bt

subtensor = bt.Subtensor(network="finney")
my_wallet = bt.Wallet("my_wallet")

netuid = 14
mechid = 1
uids = [0, 1, 2, 3]
weights = [1, 2, 1, 6]

success, message = subtensor.set_weights(
    wallet=my_wallet,
    netuid=netuid,
    mechid=mechid,
    uids=uids,
    weights=weights,
)

- commit_weights

import bittensor as bt

subtensor = bt.Subtensor(network="finney")
my_wallet = bt.Wallet("my_wallet")

netuid = 14
mechid = 1
uids = [0, 1, 2, 3]
weights = [1, 2, 1, 6]
salt = [25, 110, 271, 125]

success, message = subtensor.commit_weights(
    wallet=my_wallet,
    netuid=netuid,
    mechid=mechid,
    salt=salt,
    uids=uids,
    weights=weights,
)

- reveal_weights

import bittensor as bt

subtensor = bt.Subtensor(network="finney")
my_wallet = bt.Wallet("my_wallet")

netuid = 14
mechid = 1
uids = [0, 1, 2, 3]
weights = [1, 2, 1, 6]
salt = [25, 110, 271, 125]

success, message = subtensor.reveal_weights(
    wallet=my_wallet,
    netuid=netuid,
    mechid=mechid,
    salt=salt,
    uids=uids,
    weights=weights,
)

- get_mechanism_count

Important

A new method

```py
import bittensor as bt

subtensor = bt.Subtensor(network="finney")

netuid = 14
mechanism_count = subtensor.get_mechanism_count(netuid=netuid)

- get_mechanism_emission_split

Important

A new method

import bittensor as bt

subtensor = bt.Subtensor(network="finney")

netuid = 14

percentages = subtensor.get_mechanism_emission_split(
    netuid=netuid,
)

- bonds

import bittensor as bt

subtensor = bt.Subtensor(network="finney")

netuid = 14
mechid = 1

bonds = subtensor.bonds(
    netuid=netuid,
    mechid=mechid,
    field_indices=field_indices,
)

- get_all_metagraphs_info

Important

Got a new parameter all_mechanisms: bool = False

import bittensor as bt

subtensor = bt.Subtensor(network="finney")

all_metagraphs = subtensor.get_all_mechagraphs_info()

# or 

all_metagraphs_with_mechanisms = subtensor.get_all_mechagraphs_info(all_mechanisms=True)

- get_metagraph_info

Important

A very important update without breaking changes to backward compatibility

import bittensor as bt

netuid = 14
mechid = 1
field_indices = [0, 1, 74]  # as and example of indices

subtensor = bt.Subtensor(network="finney")

# get MetagraphInfo for subnet 14, mechanism 0
meta_info = subtensor.get_metagraph_info(
    netuid=netuid
)

# get MetagraphInfo for subnet 14, mechanism 0  with required fields
meta_info_with_indices = subtensor.get_metagraph_info(
    netuid=netuid,
    field_indices=field_indices,
)

# get MetagraphInfo for subnet 14, mechanism 1
meta_info_for_specified_mech = subtensor.get_metagraph_info(
    netuid=netuid,
    mechid=mechid,
)

# get MetagraphInfo for subnet 14, mechanism 1 with required fields
meta_info_with_specified_mech_and_with_indices = subtensor.get_metagraph_info(
    netuid=netuid,
    mechid=mechid,
    field_indices=field_indices,
)

- get_timelocked_weight_commits

import bittensor as bt

subtensor = bt.Subtensor(network="finney")

netuid = 14
mechids = [0, 1]

for mechid in mechids
    timelocked_weight_commits = subtensor.get_timelocked_weight_commits(
        netuid=netuid,
        mechid=mechid,
    )
    print(timelocked_weight_commits)

- metagraph

Important

A very important update without breaking changes to backward compatibility.
Method got new parameter mechid. By default is 0.
Metagraph class has a new fields:

  • mechid: int - 0 by default
  • mechanisms_emissions_split: list[int] - calculated after metagraph initialization, updated upon sync
  • mechanism_count: int - calculated after metagraph initialization, updated upon sync
import bittensor as bt

subtensor = bt.Subtensor(network="finney")

netuid = 14
mechid = 1

# support existing call
meta = subtensor.metagraph(
    netuid=netuid
)

# gets the metagraph data for specific subnet mechanism
mech_meta = subtensor.metagraph(
    netuid=netuid,
    mechid=mechid
)

- weights

import bittensor as bt

subtensor = bt.Subtensor(network="finney")

netuid = 14
mechids = [0, 1]

for mechid in mechids
    weights = subtensor.weights(
        netuid=netuid,
        mechid=mechid,
    )
    print(netuid, mechid, weights)

- sudo_set_mechanism_count_extrinsic

Important

sudo extrinsic

import bittensor as bt
from bittensor.core.extrinsics.sudo import sudo_set_mechanism_count_extrinsic

subtensor = bt.Subtensor(network="finney")
my_wallet = bt.Wallet("sudo_or_sn_owner")

netuid = 14
mech_count = 2

success, message = sudo_set_mechanism_count_extrinsic(
    subtensor=subtensor,
    wallet=my_wallet,
    netuid=netuid,
    mech_count=mech_count,
)

- sudo_set_mechanism_emission_split_extrinsic

Important

sudo extrinsic

import bittensor as bt
from bittensor.core.extrinsics.sudo import sudo_set_mechanism_emission_split_extrinsic

subtensor = bt.Subtensor(network="finney")
my_wallet = bt.Wallet("sudo_or_sn_owner")

netuid = 14
maybe_split = [20, 80]

success, message = sudo_set_mechanism_emission_split_extrinsic(
    subtensor=subtensor,
    wallet=my_wallet,
    netuid=netuid,
    maybe_split=maybe_split,
)

Subtensor class has new methods:

  • get_mechanism_count
  • get_mechanism_emission_split
  • is_in_admin_freeze_window

Next subtensor methods has additional parameter mechid (by default is 0):

  • bonds
  • commit_weights
  • get_metagraph_info
  • get_all_metagraphs_info # has a new parameter all_mechanisms
  • get_timelocked_weight_commits
  • reveal_weights
  • set_weights
  • weights

Bittensor SDK has a new extrinsics:

  • commit_mechanism_weights_extrinsic
  • commit_timelocked_mechanism_weights_extrinsic
  • reveal_mechanism_weights_extrinsic
  • set_mechanism_weights_extrinsic

sudo extrinsics (for sudo or SN owners only)

  • sudo_set_admin_freez_window_extrinsic
  • sudo_set_mechanism_count_extrinsic
  • sudo_set_mechanism_emission_split_extrinsic

To maintain backward compatibility we will keep the following extrinsics, but passibly they will be removed in SDKv10:

  • set_weights_extrinsic
  • commit_weights_extrinsic
  • reveal_weights_extrinsic
  • commit_reveal_v3_extrinsic

Chain Storages that received an updated storage_index instead of just netuid:

  • Incentive
  • LastUpdate
  • Weights
  • Bonds
  • WeightCommits
  • TimelockedWeightCommits
  • CRV3WeightCommits (will be deprecated)
  • CRV3WeightCommitsV2 (will be deprecated)

Related:

Fixed bug:

  • retries never increased in case of error in subtensor.commit_weights and subtensor.reveal_weights

@basfroman basfroman self-assigned this Sep 13, 2025
@basfroman basfroman linked an issue Sep 13, 2025 that may be closed by this pull request
@basfroman basfroman changed the title [WIP] Sub-Subnet logic Sub-Subnet logic Sep 16, 2025
@basfroman basfroman added feature new feature added and removed do not merge do not review yet labels Sep 16, 2025
@basfroman basfroman requested a review from a team September 16, 2025 01:16
ibraheem-abe
ibraheem-abe previously approved these changes Sep 19, 2025
Copy link
Contributor

@ibraheem-abe ibraheem-abe left a comment

Choose a reason for hiding this comment

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

Nice work on the backwards compatibility 👍

ibraheem-abe
ibraheem-abe previously approved these changes Sep 19, 2025
@basfroman basfroman added the subtensor-localnet:testnet Run e2e tests based on subtensor-localnet:testnet docker image. label Sep 21, 2025
thewhaleking
thewhaleking previously approved these changes Sep 22, 2025
Copy link
Contributor

@thewhaleking thewhaleking left a comment

Choose a reason for hiding this comment

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

Not sure I understand the "Parameters" change. Very inconsistent. In this file, we have:
Parameters: 9
Arguments: 119

Args: 1

This PR is very hard to review because the majority of code changes have nothing to do with the PR.

Copy link
Contributor

@MichaelTrestman MichaelTrestman left a comment

Choose a reason for hiding this comment

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

I did not do a thorough code review but can verify that the scripts covered in the docs work with the SDK, behaving appropriately under core use cases.

Co-authored-by: BD Himes <37844818+thewhaleking@users.noreply.github.com>
basfroman and others added 2 commits September 22, 2025 12:44
the same just more obvious, but longer

Co-authored-by: BD Himes <37844818+thewhaleking@users.noreply.github.com>
@basfroman basfroman merged commit 96c75e1 into staging Sep 22, 2025
232 checks passed
@basfroman basfroman deleted the feat/roman/sub-subnet branch September 22, 2025 20:21
@ibraheem-abe ibraheem-abe mentioned this pull request Sep 25, 2025
basfroman added a commit that referenced this pull request Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature new feature added subtensor-localnet:testnet Run e2e tests based on subtensor-localnet:testnet docker image.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Subnet Mechanisms logic

4 participants