# trim-null-subnet-batch (/docs/tx/trim-null-subnet-batch)

Cancels pending weight commits before moving UIDs, then removes at most
the runtime's batch size (currently 64). A large legacy commit backlog
can produce a cleanup-only batch. Read `NullPruningTarget` and
`SubnetworkN` after inclusion: a successful transaction does not imply
the final target has been reached. Continue with the same target until
the pending target is absent. Each batch is owner-authorized and respects
the admin freeze window. Only the first batch starts the trimming cooldown;
changing the target is a new operation. Survivor UID values can change.

| Signer    | Origin       | Pallet     | Wraps                                                                                      |
| --------- | ------------ | ---------- | ------------------------------------------------------------------------------------------ |
| `coldkey` | subnet owner | AdminUtils | [`AdminUtils.sudo_trim_null_uids_batch`](/code/pallets/admin-utils/src/lib.rs#L2136-L2162) |

## Parameters [#parameters]

| Parameter | Type    | Required | Description                                    |
| --------- | ------- | -------- | ---------------------------------------------- |
| `netuid`  | integer | yes      | Null subnet owned by the signer.               |
| `target`  | integer | yes      | Final UID count, shared by every continuation. |

Address parameters (`--hotkey`, `--coldkey`, `--dest`, ...) accept a raw ss58
address, an address-book or proxy-book name, or a local wallet/hotkey name.

## CLI [#cli]

Preview with `--dry-run` (shows fee, effects, and policy result without
submitting), then submit:

```bash
btcli tx trim-null-subnet-batch \
  --netuid <int> \
  --target <int> --dry-run
btcli tx trim-null-subnet-batch \
  --netuid <int> \
  --target <int> -w my_coldkey
```

## Python [#python]

```python
import bittensor as bt
from bittensor.wallet import Wallet

wallet = Wallet(name="my_coldkey", hotkey="my_hotkey")
intent = bt.TrimNullSubnetBatch(netuid=1, target=64)

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](/docs/concepts/client).) Or build the intent by op name, as
an agent would:

```python
result = sub.execute_tool("trim_null_subnet_batch", {...}, wallet)
```

## On-chain implementation [#on-chain-implementation]

`AdminUtils.sudo_trim_null_uids_batch` — [`pallets/admin-utils/src/lib.rs#L2138`](/code/pallets/admin-utils/src/lib.rs#L2136-L2162):

```rust
#[pallet::call_index(112)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::sudo_trim_null_uids_batch().max(<T as pallet::Config>::WeightInfo::sudo_trim_null_uids_batch_many_mechanisms()))]
pub fn sudo_trim_null_uids_batch(
    origin: OriginFor<T>,
    netuid: NetUid,
    target: u16,
) -> DispatchResult {
    let continuing = pallet_subtensor::NullPruningTarget::<T>::get(netuid) == Some(target);
    let limits: &[TransactionType] = if continuing {
        &[]
    } else {
        &[TransactionType::MaxUidsTrimming]
    };
    let maybe_owner = pallet_subtensor::Pallet::<T>::ensure_sn_owner_or_root_with_limits(
        origin, netuid, limits,
    )?;
    pallet_subtensor::Pallet::<T>::ensure_admin_window_open(netuid)?;
    pallet_subtensor::Pallet::<T>::trim_null_uids_batch(netuid, target)?;
    if !continuing {
        pallet_subtensor::Pallet::<T>::record_owner_rl(
            maybe_owner,
            netuid,
            &[TransactionType::MaxUidsTrimming],
        );
    }
    Ok(())
}
```

Every file is browsable under [/code](/code) exactly as built into the runtime, or as plain text under `/code/raw/<path>` (index: [`/code/index.json`](/code/index.json)).
