batch_set_weights

Call v216 → v277, v290 → 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>> Vec netuids: list of compact-encoded Subnet ID (u16, 0-65535)
1
weights
Vec<Vec<(Compact<u16>, Compact<u16>)>> Vec weights (Vec<Vec<(Compact<u16>, Compact<u16>)>>)
2
version_keys
Vec<Compact<u64>> Vec version_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 { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443

const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);

// Build batch_set_weights call (typed, named args)
const netuids = [] as [];
const weights = [] as [];
const version_keys = [] as [];

const tx = api.tx.SubtensorModule.batch_set_weights({
  netuids,
  weights,
  version_keys,
});

Version History

v216 block 4,510,996 3 args
v290 block 5,947,548 3 args Current

Runtime Info

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