Skip to content

fix(weights): include netuid in BatchWeightItemFailed event#2654

Open
RUNECTZ33 wants to merge 1 commit into
opentensor:devnet-readyfrom
RUNECTZ33:fix/batch-weight-item-failed-include-netuid
Open

fix(weights): include netuid in BatchWeightItemFailed event#2654
RUNECTZ33 wants to merge 1 commit into
opentensor:devnet-readyfrom
RUNECTZ33:fix/batch-weight-item-failed-include-netuid

Conversation

@RUNECTZ33
Copy link
Copy Markdown

Description

do_batch_commit_weights and do_batch_set_weights accept a list of (netuid, payload) pairs and forward each one to the per-item dispatch. When an item fails, the chain emits

Self::deposit_event(Event::BatchWeightItemFailed(err));

which carries the DispatchError but not the netuid that produced it. Downstream consumers (block explorers, validator monitors, indexers) watching a batch see that an item failed and what error variant fired, but cannot tell which subnet without re-deriving from iteration order — fragile across runtime upgrades and not available to event-only subscribers.

The call site already has netuid in scope at the time of emission, so plumbing it through is mechanical.

Fix

  1. Change event signature:
    BatchWeightItemFailed(NetUid, sp_runtime::DispatchError)
  2. Both emission sites in subnets/weights.rs now collect Vec<(NetUid, DispatchResult)> from the per-item map and emit BatchWeightItemFailed(netuid, err) for each failing item.
  3. Bumps spec_version 406 → 407.

Shape mirrors #2614 ("Add netuid to TransactionFeePaidWithAlpha event") which made the same observability improvement on a different event.

Tests

Adds two regression tests in pallets/subtensor/src/tests/weights.rs. The batch-event layer had no prior coverage (grep on the test tree for either event returned no hits).

  • test_batch_commit_weights_item_failure_event_includes_netuid — submits a 2-item batch where both items hit CommitRevealDisabled, asserts the emitted BatchWeightItemFailed events carry [netuid_a, netuid_b] in iteration order.
  • test_batch_set_weights_item_failure_event_includes_netuid — same shape for the set-path, using CommitRevealEnabled as the failure trigger.

Both pass locally:

SKIP_WASM_BUILD=1 cargo test -p pallet-subtensor --lib -- \
  tests::weights::test_batch_commit_weights_item_failure_event_includes_netuid \
  tests::weights::test_batch_set_weights_item_failure_event_includes_netuid
running 2 tests
test tests::weights::test_batch_commit_weights_item_failure_event_includes_netuid ... ok
test tests::weights::test_batch_set_weights_item_failure_event_includes_netuid ... ok
test result: ok. 2 passed; 0 failed

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Breaking Change

The event signature is extended by one positional argument. Consumers that decode events by position (Polkadot.js Apps, indexer libraries, off-chain workers) will need to update their parsers — same compatibility surface as #2614. No on-chain storage change; no migration required.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run ./scripts/fix_rust.sh to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix

Related

When `do_batch_commit_weights` / `do_batch_set_weights` process a
per-subnet weight batch, any item that fails currently emits

    BatchWeightItemFailed(DispatchError)

which carries the error but **not the netuid** that produced it.
Downstream consumers (block explorers, validator monitors, indexers)
that watch batch submissions cannot correlate failures → subnet
without re-deriving from iteration order, which is fragile across
runtime upgrades and not available to event-only subscribers.

Change the event signature to

    BatchWeightItemFailed(NetUid, DispatchError)

and thread the netuid through both emission sites by zipping
`(NetUid, DispatchResult)` tuples out of the per-item map.

Shape parallels opentensor#2614 (Add netuid to TransactionFeePaidWithAlpha
event) which made the same observability fix on a different event.

Adds two regression tests in `tests/weights.rs` covering both
emission paths; the dispatches were previously untested at the
batch-event layer. Bumps `spec_version` 406 → 407.
@open-junius open-junius added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label May 12, 2026
Copy link
Copy Markdown
Contributor

@open-junius open-junius left a comment

Choose a reason for hiding this comment

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

looks good to me

/// - **netuid**: The netuid of the batch item that failed.
/// - **error**: The dispatch error emitted by the failed item.
BatchWeightItemFailed(sp_runtime::DispatchError),
BatchWeightItemFailed(NetUid, sp_runtime::DispatchError),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's a breaking change for people relying on it. It needs to be announced @sam0x17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants