batch_set_weights

Call v216 → current #80

Sets weights on multiple subnets in a single transaction.

View calls on chain

Click items to navigate. Pan and zoom to explore.

Used by: validatorsdevelopers

The Big Picture

If you validate on multiple subnets, batch_set_weights lets you update all of them in one transaction. Instead of paying fees and waiting for confirmation on each set_weights call, you bundle them together. This is especially valuable for validators operating across 5, 10, or more subnets - the gas savings compound significantly.

Why This Matters

Large validators often participate in many subnets. Setting weights individually means N transactions, N fees, N confirmation waits. Batching collapses this to one operation. Time saved, money saved, complexity reduced.

Example Scenario

You validate on subnets 1, 3, and 18. Instead of three set_weights calls, use batch_set_weights(netuids=[1,3,18], uids_list=[[5,12,23],[8,15],[2,7,9,14]], weights_list=[[0.3,0.4,0.3],[0.6,0.4],[0.2,0.3,0.3,0.2]]). One transaction updates all three subnets. One fee. One confirmation.

Common Questions

What if one subnet's weights fail validation?
Depends on implementation - typically the entire batch fails. Ensure all weight vectors are valid before submitting. Use batch for independent success/failure.
Is there a maximum number of subnets I can batch?
Limited by block weight/size. Practically, 10-20 subnets works. For very large operations, split into multiple batches.
Do rate limits apply per-subnet or to the batch?
Per-subnet. Each subnet's rate limit is checked independently. If any subnet is rate-limited, that part of the batch fails.

Use Cases

  • Multi-subnet validators updating all weights at once
  • Cross-subnet validation operations
  • Efficient weight updates for large validator operations
  • Synchronized weight setting across related subnets

From Chain Metadata

Allows a hotkey to set weights for multiple netuids as a batch.

Input Parameters

#NameTypeDescription
0
netuids
Vec<Compact<u16>> Vecnetuids (Vec<Compact<u16>>)
1
weights
Vec<Vec<(Compact<u16>, Compact<u16>)>> Vecweights (Vec<Vec<(Compact<u16>, Compact<u16>)>>)
2
version_keys
Vec<Compact<u64>> Vecversion_keys (Vec<Compact<u64>>)

Permissions

Origin
Signed
Required Role

Permission data inferred from metadata. May be incomplete.

Requirements

  • Validator registered on all target subnets
  • Valid weight vectors for each subnet
  • Rate limits not exceeded

Effects

Storage Modified

Postconditions

  • Weights updated on all specified subnets

Side Effects

  • More gas-efficient than multiple set_weights

Possible Errors

Code Examples

import { ApiPromise, WsProvider } from "@polkadot/api";
import { stringCamelCase } from "@polkadot/util";

const provider = new WsProvider("wss://entrypoint-finney.opentensor.ai:443");
const api = await ApiPromise.create({ provider });

// Build batch_set_weights call
const netuids = 1;
const weights = 0;
const version_keys = 0;

const call = api.tx[stringCamelCase("SubtensorModule")][stringCamelCase("batch_set_weights")](
  netuids,
  weights,
  version_keys
);

Runtime Info

View Source
Pallet Index
7
Call Index
80
First Version
v216
Current Version
v393