Transactions
set-weights
Set validator weights, auto-selecting plaintext or commit-reveal.
The one entry point validators need for scoring miners: it conforms the
weights to the subnet's hyperparameters (max-weight clip, u16 quantization,
minimum weight count) and submits via whichever path the subnet runs — a
plain set_weights when commit-reveal is off, or a timelock-encrypted
commit (auto-revealed by the chain at the drand reveal round) when it is on.
Signed by the hotkey, which must be registered on the subnet. Before
signing it preflights registration and the rate limit, so those failures
are caught fast with the same error the chain would return; the rate-limit
error says how many blocks to wait. The chain additionally enforces checks
that are not preflighted: the hotkey must hold the minimum stake to set
weights, must hold a validator permit to set non-self weights (the subnet
owner is exempt), and version_key must not be older than the subnet's
required version. Prefer this over commit_weights/reveal_weights
unless you specifically need to force one path.
| Signer | Origin | Pallet | Wraps |
|---|---|---|---|
hotkey | signed account (pallet role may apply) | SubtensorModule | SubtensorModule.set_mechanism_weights, SubtensorModule.commit_timelocked_mechanism_weights |
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
netuid | integer | yes | Subnet whose miners the weights score. |
uids | array of integer | no | Miner UIDs being weighted, as a list parallel to weights. Omit when weights is given as a uid-to-weight mapping. |
weights | array of number | no | Relative weight per miner: either a JSON object mapping uid to weight, or a list parallel to uids. Values are relative, not absolute; they are clipped to the subnet's max-weight limit, normalized, and quantized before submission. |
mechid | integer | no | Mechanism index within the subnet. 0 is the default (and for most subnets the only) mechanism. |
version_key | integer | no | Weights version key checked against the subnet's required version. Leave 0 unless the subnet owner requires a specific value. |
Address parameters (--hotkey, --coldkey, --dest, ...) accept a raw ss58
address, an address-book or proxy-book name, or a local wallet/hotkey name.
CLI
Preview with --dry-run (shows fee, effects, and policy result without
submitting), then submit:
btcli tx set-weights \
--netuid <int> --dry-run
btcli tx set-weights \
--netuid <int> -w my_coldkeyPython
import bittensor as bt
from bittensor.wallet import Wallet
wallet = Wallet(name="my_coldkey", hotkey="my_hotkey")
intent = bt.SetWeights(netuid=1)
sub = bt.Subtensor()
plan = sub.plan(intent, wallet) # fee, effects, policy — no submission
result = sub.execute(intent, wallet)
if not result.success:
print(result.error.code, result.error.remediation)(bt.Subtensor is also the async client — async with bt.Subtensor() as client:
— see The client.) Or build the intent by op name, as
an agent would:
result = sub.execute_tool("set_weights", {...}, wallet)On-chain implementation
SubtensorModule.set_mechanism_weights — pallets/subtensor/src/macros/dispatches.rs#L130:
#[pallet::call_index(119)]
#[pallet::weight((<T as Config>::WeightInfo::set_mechanism_weights(dests.len() as u32), DispatchClass::Normal, Pays::No))]
pub fn set_mechanism_weights(
origin: OriginFor<T>,
netuid: NetUid,
mecid: MechId,
dests: Vec<u16>,
weights: Vec<u16>,
version_key: u64,
) -> DispatchResult {
if Self::get_commit_reveal_weights_enabled(netuid) {
Err(Error::<T>::CommitRevealEnabled.into())
} else {
Self::do_set_mechanism_weights(origin, netuid, mecid, dests, weights, version_key)
}
}Delegates to get_commit_reveal_weights_enabled, do_set_mechanism_weights.
SubtensorModule.commit_timelocked_mechanism_weights — pallets/subtensor/src/macros/dispatches.rs#L1852:
#[pallet::call_index(118)]
#[pallet::weight((<T as Config>::WeightInfo::commit_timelocked_mechanism_weights(), DispatchClass::Normal, Pays::No))]
pub fn commit_timelocked_mechanism_weights(
origin: OriginFor<T>,
netuid: NetUid,
mecid: MechId,
commit: BoundedVec<u8, ConstU32<MAX_CRV3_COMMIT_SIZE_BYTES>>,
reveal_round: u64,
commit_reveal_version: u16,
) -> DispatchResult {
Self::do_commit_timelocked_mechanism_weights(
origin,
netuid,
mecid,
commit,
reveal_round,
commit_reveal_version,
)
}Delegates to do_commit_timelocked_mechanism_weights.
Every file is browsable under /code exactly as built into the runtime, or as plain text under /code/raw/<path> (index: /code/index.json).