bittensor.core.extrinsics.async_weights#

This module provides functionality for setting weights on the Bittensor network.

Functions#

_do_commit_weights(subtensor, wallet, netuid, commit_hash)

Internal method to send a transaction to the Bittensor blockchain, committing the hash of a neuron's weights.

_do_set_weights(subtensor, wallet, uids, vals, netuid)

Internal method to send a transaction to the Bittensor blockchain, setting weights

commit_weights_extrinsic(subtensor, wallet, netuid, ...)

Commits a hash of the neuron's weights to the Bittensor blockchain using the provided wallet.

set_weights_extrinsic(subtensor, wallet, netuid, uids, ...)

Sets the given weights and values on chain for wallet hotkey account.

Module Contents#

async bittensor.core.extrinsics.async_weights._do_commit_weights(subtensor, wallet, netuid, commit_hash, wait_for_inclusion=False, wait_for_finalization=False)#

Internal method to send a transaction to the Bittensor blockchain, committing the hash of a neuron’s weights. This method constructs and submits the transaction, handling retries and blockchain communication.

Parameters:
  • subtensor (bittensor.core.subtensor.Subtensor) – The subtensor instance used for blockchain interaction.

  • wallet (bittensor_wallet.Wallet) – The wallet associated with the neuron committing the weights.

  • netuid (int) – The unique identifier of the subnet.

  • commit_hash (str) – The hash of the neuron’s weights to be committed.

  • wait_for_inclusion (bool) – Waits for the transaction to be included in a block.

  • wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain.

Returns:

A tuple containing a success flag and an optional error message.

Return type:

tuple[bool, Optional[str]]

This method ensures that the weight commitment is securely recorded on the Bittensor blockchain, providing a verifiable record of the neuron’s weight distribution at a specific point in time.

async bittensor.core.extrinsics.async_weights._do_set_weights(subtensor, wallet, uids, vals, netuid, version_key=version_as_int, wait_for_inclusion=False, wait_for_finalization=False)#

Internal method to send a transaction to the Bittensor blockchain, setting weights for specified neurons. This method constructs and submits the transaction, handling retries and blockchain communication.

Parameters:
  • subtensor (subtensor.core.async_subtensor.AsyncSubtensor) – Async Subtensor instance.

  • wallet (bittensor.wallet) – The wallet associated with the neuron setting the weights.

  • uids (List[int]) – List of neuron UIDs for which weights are being set.

  • vals (List[int]) – List of weight values corresponding to each UID.

  • netuid (int) – Unique identifier for the network.

  • version_key (int, optional) – Version key for compatibility with the network.

  • wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.

  • wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.

Returns:

A tuple containing a success flag and an optional error message.

Return type:

Tuple[bool, Optional[str]]

This method is vital for the dynamic weighting mechanism in Bittensor, where neurons adjust their trust in other neurons based on observed performance and contributions.

async bittensor.core.extrinsics.async_weights.commit_weights_extrinsic(subtensor, wallet, netuid, commit_hash, wait_for_inclusion=False, wait_for_finalization=False)#

Commits a hash of the neuron’s weights to the Bittensor blockchain using the provided wallet. This function is a wrapper around the do_commit_weights method.

Parameters:
  • subtensor (bittensor.core.subtensor.Subtensor) – The subtensor instance used for blockchain interaction.

  • wallet (bittensor_wallet.Wallet) – The wallet associated with the neuron committing the weights.

  • netuid (int) – The unique identifier of the subnet.

  • commit_hash (str) – The hash of the neuron’s weights to be committed.

  • wait_for_inclusion (bool) – Waits for the transaction to be included in a block.

  • wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain.

Returns:

True if the weight commitment is successful, False otherwise. And msg, a string value describing the success or potential error.

Return type:

tuple[bool, str]

This function provides a user-friendly interface for committing weights to the Bittensor blockchain, ensuring proper error handling and user interaction when required.

async bittensor.core.extrinsics.async_weights.set_weights_extrinsic(subtensor, wallet, netuid, uids, weights, version_key=0, wait_for_inclusion=False, wait_for_finalization=False)#

Sets the given weights and values on chain for wallet hotkey account.

Parameters:
  • subtensor (bittensor.subtensor) – Bittensor subtensor object.

  • wallet (bittensor.wallet) – Bittensor wallet object.

  • netuid (int) – The netuid of the subnet to set weights for.

  • uids (Union[NDArray[np.int64], torch.LongTensor, list]) – The uint64 uids of destination neurons.

  • weights (Union[NDArray[np.float32], torch.FloatTensor, list]) – The weights to set. These must be float s and correspond to the passed uid s.

  • version_key (int) – The version key of the validator.

  • wait_for_inclusion (bool) – If set, waits for the extrinsic to enter a block before returning true, or returns false if the extrinsic fails to enter the block within the timeout.

  • wait_for_finalization (bool) – If set, waits for the extrinsic to be finalized on the chain before returning true, or returns false if the extrinsic fails to be finalized within the timeout.

Returns:

Flag is true if extrinsic was finalized or included in the block. If we did not wait for finalization / inclusion, the response is true.

Return type:

success (bool)