bittensor.mock.subtensor_mock

Contents

bittensor.mock.subtensor_mock#

Attributes#

Classes#

AxonServeCallParams

Axon serve chain call parameters.

PrometheusServeCallParams

Prometheus serve chain call parameters.

InfoDict

A Mapping is a generic container for associating key/value

AxonInfoDict

A Mapping is a generic container for associating key/value

PrometheusInfoDict

A Mapping is a generic container for associating key/value

MockSubtensorValue

MockMapResult

MockSystemState

dict() -> new empty dictionary

MockSubtensorState

dict() -> new empty dictionary

MockChainState

dict() -> new empty dictionary

MockSubtensor

A Mock Subtensor class for running tests.

Module Contents#

bittensor.mock.subtensor_mock.__GLOBAL_MOCK_STATE__#
class bittensor.mock.subtensor_mock.AxonServeCallParams[source]#

Bases: TypedDict

Axon serve chain call parameters.

Initialize self. See help(type(self)) for accurate signature.

version: int#
ip: int#
port: int#
ip_type: int#
netuid: int#
class bittensor.mock.subtensor_mock.PrometheusServeCallParams[source]#

Bases: TypedDict

Prometheus serve chain call parameters.

Initialize self. See help(type(self)) for accurate signature.

version: int#
ip: int#
port: int#
ip_type: int#
netuid: int#
bittensor.mock.subtensor_mock.BlockNumber#
class bittensor.mock.subtensor_mock.InfoDict[source]#

Bases: collections.abc.Mapping

A Mapping is a generic container for associating key/value pairs.

This class provides concrete generic implementations of all methods except for __getitem__, __iter__, and __len__.

classmethod default()[source]#
Abstractmethod:

__getitem__(key)[source]#
__setitem__(key, value)[source]#
__iter__()[source]#
__len__()[source]#
class bittensor.mock.subtensor_mock.AxonInfoDict[source]#

Bases: InfoDict

A Mapping is a generic container for associating key/value pairs.

This class provides concrete generic implementations of all methods except for __getitem__, __iter__, and __len__.

block: int#
version: int#
ip: int#
port: int#
ip_type: int#
protocol: int#
placeholder1: int#
placeholder2: int#
classmethod default()[source]#
class bittensor.mock.subtensor_mock.PrometheusInfoDict[source]#

Bases: InfoDict

A Mapping is a generic container for associating key/value pairs.

This class provides concrete generic implementations of all methods except for __getitem__, __iter__, and __len__.

block: int#
version: int#
ip: int#
port: int#
ip_type: int#
classmethod default()[source]#
class bittensor.mock.subtensor_mock.MockSubtensorValue[source]#
value: Any | None#
class bittensor.mock.subtensor_mock.MockMapResult(records=None)[source]#
Parameters:

records (Optional[List[Tuple[Union[Any, MockSubtensorValue], Union[Any, MockSubtensorValue]]]])

records: List[Tuple[MockSubtensorValue, MockSubtensorValue]] | None#
_records#
__iter__()[source]#
class bittensor.mock.subtensor_mock.MockSystemState[source]#

Bases: TypedDict

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

Initialize self. See help(type(self)) for accurate signature.

Account: Dict[str, Dict[int, int]]#
class bittensor.mock.subtensor_mock.MockSubtensorState[source]#

Bases: TypedDict

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

Initialize self. See help(type(self)) for accurate signature.

Rho: Dict[int, Dict[BlockNumber, int]]#
Kappa: Dict[int, Dict[BlockNumber, int]]#
Difficulty: Dict[int, Dict[BlockNumber, int]]#
ImmunityPeriod: Dict[int, Dict[BlockNumber, int]]#
ValidatorBatchSize: Dict[int, Dict[BlockNumber, int]]#
Active: Dict[int, Dict[BlockNumber, bool]]#
Stake: Dict[str, Dict[str, Dict[int, int]]]#
Delegates: Dict[str, Dict[int, float]]#
NetworksAdded: Dict[int, Dict[BlockNumber, bool]]#
class bittensor.mock.subtensor_mock.MockChainState[source]#

Bases: TypedDict

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

Initialize self. See help(type(self)) for accurate signature.

System: MockSystemState#
SubtensorModule: MockSubtensorState#
class bittensor.mock.subtensor_mock.MockSubtensor(*args, **kwargs)[source]#

Bases: bittensor.subtensor.Subtensor

A Mock Subtensor class for running tests. This should mock only methods that make queries to the chain. e.g. We mock Subtensor.query_subtensor instead of all query methods.

This class will also store a local (mock) state of the chain.

Initializes a Subtensor interface for interacting with the Bittensor blockchain.

Note

Currently subtensor defaults to the finney network. This will change in a future release.

We strongly encourage users to run their own local subtensor node whenever possible. This increases decentralization and resilience of the network. In a future release, local subtensor will become the default and the fallback to finney removed. Please plan ahead for this change. We will provide detailed instructions on how to run a local subtensor node in the documentation in a subsequent release.

Parameters:
  • network (str, optional) – The network name to connect to (e.g., finney, local). This can also be the chain endpoint (e.g., wss://entrypoint-finney.opentensor.ai:443) and will be correctly parsed into the network and chain endpoint. If not specified, defaults to the main Bittensor network.

  • config (bittensor.config, optional) – Configuration object for the subtensor. If not provided, a default configuration is used.

  • _mock (bool, optional) – If set to True, uses a mocked connection for testing purposes.

This initialization sets up the connection to the specified Bittensor network, allowing for various blockchain operations such as neuron registration, stake management, and setting weights.

chain_state: MockChainState#
block_number: int#
classmethod reset()[source]#
Return type:

None

setup()[source]#
Return type:

None

__dict__#
get_block_hash(block_id)[source]#

Retrieves the hash of a specific block on the Bittensor blockchain. The block hash is a unique identifier representing the cryptographic hash of the block’s content, ensuring its integrity and immutability.

Parameters:

block_id (int) – The block number for which the hash is to be retrieved.

Returns:

The cryptographic hash of the specified block.

Return type:

str

The block hash is a fundamental aspect of blockchain technology, providing a secure reference to each block’s data. It is crucial for verifying transactions, ensuring data consistency, and maintaining the trustworthiness of the blockchain.

create_subnet(netuid)[source]#
Parameters:

netuid (int)

Return type:

None

set_difficulty(netuid, difficulty)[source]#
Parameters:
  • netuid (int)

  • difficulty (int)

Return type:

None

_register_neuron(netuid, hotkey, coldkey)[source]#
Parameters:
Return type:

int

static _convert_to_balance(balance)[source]#
Parameters:

balance (Union[bittensor.utils.balance.Balance, float, int])

Return type:

bittensor.utils.balance.Balance

force_register_neuron(netuid, hotkey, coldkey, stake=Balance(0), balance=Balance(0))[source]#

Force register a neuron on the mock chain, returning the UID.

Parameters:
Return type:

int

force_set_balance(ss58_address, balance=Balance(0))[source]#
Returns:

(success, err_msg)

Return type:

Tuple[bool, Optional[str]]

Parameters:
sudo_force_set_balance#
do_block_step()[source]#
Return type:

None

_handle_type_default(name, params)[source]#
Parameters:
Return type:

object

commit(wallet, netuid, data)[source]#

Commits arbitrary data to the Bittensor network by publishing metadata.

Parameters:
  • wallet (bittensor.wallet) – The wallet associated with the neuron committing the data.

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

  • data (str) – The data to be committed to the network.

Return type:

None

get_commitment(netuid, uid, block=None)[source]#

Retrieves the on-chain commitment for a specific neuron in the Bittensor network.

Parameters:
  • netuid (int) – The unique identifier of the subnetwork.

  • uid (int) – The unique identifier of the neuron.

  • block (Optional[int]) – The block number to retrieve the commitment from. If None, the latest block is used. Default is None.

Returns:

The commitment data as a string.

Return type:

str

query_subtensor(name, block=None, params=[])[source]#

Queries named storage from the Subtensor module on the Bittensor blockchain. This function is used to retrieve specific data or parameters from the blockchain, such as stake, rank, or other neuron-specific attributes.

Parameters:
  • name (str) – The name of the storage function to query.

  • block (Optional[int]) – The blockchain block number at which to perform the query.

  • params (Optional[List[object]], optional) – A list of parameters to pass to the query function.

Returns:

An object containing the requested data.

Return type:

query_response (ScaleType)

This query function is essential for accessing detailed information about the network and its neurons, providing valuable insights into the state and dynamics of the Bittensor ecosystem.

query_map_subtensor(name, block=None, params=[])[source]#

Note: Double map requires one param

Parameters:
  • name (str)

  • block (Optional[int])

  • params (Optional[List[object]])

Return type:

Optional[MockMapResult]

query_constant(module_name, constant_name, block=None)[source]#

Retrieves a constant from the specified module on the Bittensor blockchain. This function is used to access fixed parameters or values defined within the blockchain’s modules, which are essential for understanding the network’s configuration and rules.

Parameters:
  • module_name (str) – The name of the module containing the constant.

  • constant_name (str) – The name of the constant to retrieve.

  • block (Optional[int]) – The blockchain block number at which to query the constant.

Returns:

The value of the constant if found, None otherwise.

Return type:

Optional[ScaleType]

Constants queried through this function can include critical network parameters such as inflation rates, consensus rules, or validation thresholds, providing a deeper understanding of the Bittensor network’s operational parameters.

get_current_block()[source]#

Returns the current block number on the Bittensor blockchain. This function provides the latest block number, indicating the most recent state of the blockchain.

Returns:

The current chain block number.

Return type:

int

Knowing the current block number is essential for querying real-time data and performing time-sensitive operations on the blockchain. It serves as a reference point for network activities and data synchronization.

get_balance(address, block=None)[source]#

Retrieves the token balance of a specific address within the Bittensor network. This function queries the blockchain to determine the amount of Tao held by a given account.

Parameters:
  • address (str) – The Substrate address in ss58 format.

  • block (int, optional) – The blockchain block number at which to perform the query.

Returns:

The account balance at the specified block, represented as a Balance object.

Return type:

Balance

This function is important for monitoring account holdings and managing financial transactions within the Bittensor ecosystem. It helps in assessing the economic status and capacity of network participants.

get_balances(block=None)[source]#

Retrieves the token balances of all accounts within the Bittensor network as of a specific blockchain block. This function provides a comprehensive view of the token distribution among different accounts.

Parameters:

block (int, optional) – The blockchain block number at which to perform the query.

Returns:

A dictionary mapping each account’s ss58 address to its balance.

Return type:

Dict[str, Balance]

This function is valuable for analyzing the overall economic landscape of the Bittensor network, including the distribution of financial resources and the financial status of network participants.

neuron_for_uid(uid, netuid, block=None)[source]#

Retrieves detailed information about a specific neuron identified by its unique identifier (UID) within a specified subnet (netuid) of the Bittensor network. This function provides a comprehensive view of a neuron’s attributes, including its stake, rank, and operational status.

Parameters:
  • uid (int) – The unique identifier of the neuron.

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

  • block (Optional[int], optional) – The blockchain block number for the query.

Returns:

Detailed information about the neuron if found, None otherwise.

Return type:

NeuronInfo

This function is crucial for analyzing individual neurons’ contributions and status within a specific subnet, offering insights into their roles in the network’s consensus and validation mechanisms.

neurons(netuid, block=None)[source]#

Retrieves a list of all neurons within a specified subnet of the Bittensor network. This function provides a snapshot of the subnet’s neuron population, including each neuron’s attributes and network interactions.

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

  • block (Optional[int], optional) – The blockchain block number for the query.

Returns:

A list of NeuronInfo objects detailing each neuron’s characteristics in the subnet.

Return type:

List[NeuronInfo]

Understanding the distribution and status of neurons within a subnet is key to comprehending the network’s decentralized structure and the dynamics of its consensus and governance processes.

static _get_most_recent_storage(storage, block_number=None)[source]#
Parameters:
  • storage (Dict[BlockNumber, Any])

  • block_number (Optional[int])

Return type:

Any

_get_axon_info(netuid, hotkey, block=None)[source]#
Parameters:
  • netuid (int)

  • hotkey (str)

  • block (Optional[int])

Return type:

AxonInfoDict

_get_prometheus_info(netuid, hotkey, block=None)[source]#
Parameters:
  • netuid (int)

  • hotkey (str)

  • block (Optional[int])

Return type:

PrometheusInfoDict

_neuron_subnet_exists(uid, netuid, block=None)[source]#
Parameters:
  • uid (int)

  • netuid (int)

  • block (Optional[int])

Return type:

Optional[bittensor.chain_data.NeuronInfo]

neuron_for_uid_lite(uid, netuid, block=None)[source]#

Retrieves a lightweight version of information about a neuron in a specific subnet, identified by its UID. The ‘lite’ version focuses on essential attributes such as stake and network activity.

Parameters:
  • uid (int) – The unique identifier of the neuron.

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

  • block (Optional[int], optional) – The blockchain block number for the query.

Returns:

A simplified version of neuron information if found, None otherwise.

Return type:

Optional[NeuronInfoLite]

This function is useful for quick and efficient analyses of neuron status and activities within a subnet without the need for comprehensive data retrieval.

neurons_lite(netuid, block=None)[source]#

Retrieves a list of neurons in a ‘lite’ format from a specific subnet of the Bittensor network. This function provides a streamlined view of the neurons, focusing on key attributes such as stake and network participation.

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

  • block (Optional[int], optional) – The blockchain block number for the query.

Returns:

A list of simplified neuron information for the subnet.

Return type:

List[NeuronInfoLite]

This function offers a quick overview of the neuron population within a subnet, facilitating efficient analysis of the network’s decentralized structure and neuron dynamics.

_do_delegation(wallet, delegate_ss58, amount, wait_for_inclusion=True, wait_for_finalization=False)[source]#

Delegates a specified amount of stake to a delegate’s hotkey.

This method sends a transaction to add stake to a delegate’s hotkey and retries the call up to three times with exponential backoff in case of failures.

Parameters:
  • wallet (bittensor.wallet) – The wallet from which the stake will be delegated.

  • delegate_ss58 (str) – The SS58 address of the delegate’s hotkey.

  • amount (Balance) – The amount of stake to be delegated.

  • wait_for_inclusion (bool, optional) – Whether to wait for the transaction to be included in a block. Default is True.

  • wait_for_finalization (bool, optional) – Whether to wait for the transaction to be finalized. Default is False.

Returns:

True if the delegation is successful, False otherwise.

Return type:

bool

_do_undelegation(wallet, delegate_ss58, amount, wait_for_inclusion=True, wait_for_finalization=False)[source]#

Removes a specified amount of stake from a delegate’s hotkey.

This method sends a transaction to remove stake from a delegate’s hotkey and retries the call up to three times with exponential backoff in case of failures.

Parameters:
  • wallet (bittensor.wallet) – The wallet from which the stake will be removed.

  • delegate_ss58 (str) – The SS58 address of the delegate’s hotkey.

  • amount (Balance) – The amount of stake to be removed.

  • wait_for_inclusion (bool, optional) – Whether to wait for the transaction to be included in a block. Default is True.

  • wait_for_finalization (bool, optional) – Whether to wait for the transaction to be finalized. Default is False.

Returns:

True if the undelegation is successful, False otherwise.

Return type:

bool

_do_nominate(wallet, wait_for_inclusion=True, wait_for_finalization=False)[source]#

Nominates the wallet’s hotkey to become a delegate.

This method sends a transaction to nominate the wallet’s hotkey to become a delegate and retries the call up to three times with exponential backoff in case of failures.

Parameters:
  • wallet (bittensor.wallet) – The wallet whose hotkey will be nominated.

  • wait_for_inclusion (bool, optional) – Whether to wait for the transaction to be included in a block. Default is True.

  • wait_for_finalization (bool, optional) – Whether to wait for the transaction to be finalized. Default is False.

Returns:

True if the nomination is successful, False otherwise.

Return type:

bool

get_transfer_fee(wallet, dest, value)[source]#

Calculates the transaction fee for transferring tokens from a wallet to a specified destination address. This function simulates the transfer to estimate the associated cost, taking into account the current network conditions and transaction complexity.

Parameters:
  • wallet (bittensor.wallet) – The wallet from which the transfer is initiated.

  • dest (str) – The SS58 address of the destination account.

  • value (Union[Balance, float, int]) – The amount of tokens to be transferred, specified as a Balance object, or in Tao (float) or Rao (int) units.

Returns:

The estimated transaction fee for the transfer, represented as a Balance object.

Return type:

Balance

Estimating the transfer fee is essential for planning and executing token transactions, ensuring that the wallet has sufficient funds to cover both the transfer amount and the associated costs. This function provides a crucial tool for managing financial operations within the Bittensor network.

_do_transfer(wallet, dest, transfer_balance, wait_for_inclusion=True, wait_for_finalization=False)[source]#

Sends a transfer extrinsic to the chain.

Parameters:
  • wallet (bittensor.wallet()) – Wallet object.

  • dest (str) – Destination public key address.

  • transfer_balance (Balance()) – Amount to transfer.

  • wait_for_inclusion (bool) – If true, waits for inclusion.

  • wait_for_finalization (bool) – If true, waits for finalization.

Returns:

True if transfer was successful. block_hash (str): Block hash of the transfer. On success and if wait_for_ finalization/inclusion is

True.

error (str): Error message if transfer failed.

Return type:

success (bool)

_do_pow_register(netuid, wallet, pow_result, wait_for_inclusion=False, wait_for_finalization=True)[source]#

Sends a (POW) register extrinsic to the chain.

Parameters:
  • netuid (int) – The subnet to register on.

  • wallet (bittensor.wallet) – The wallet to register.

  • pow_result (POWSolution) – The PoW result to register.

  • wait_for_inclusion (bool) – If True, waits for the extrinsic to be included in a block. Default to False.

  • wait_for_finalization (bool) – If True, waits for the extrinsic to be finalized. Default to True.

Returns:

True if the extrinsic was included in a block. error (Optional[str]): None on success or not waiting for inclusion/finalization, otherwise the error

message.

Return type:

success (bool)

_do_burned_register(netuid, wallet, wait_for_inclusion=False, wait_for_finalization=True)[source]#

Performs a burned register extrinsic call to the Subtensor chain.

This method sends a registration transaction to the Subtensor blockchain using the burned register mechanism. It retries the call up to three times with exponential backoff in case of failures.

Parameters:
  • netuid (int) – The network unique identifier to register on.

  • wallet (bittensor.wallet) – The wallet to be registered.

  • wait_for_inclusion (bool) – Whether to wait for the transaction to be included in a block. Default is False.

  • wait_for_finalization (bool) – Whether to wait for the transaction to be finalized. Default is True.

Returns:

A tuple containing a boolean indicating success or failure, and an optional error message.

Return type:

Tuple[bool, Optional[str]]

_do_stake(wallet, hotkey_ss58, amount, wait_for_inclusion=True, wait_for_finalization=False)[source]#

Sends a stake extrinsic to the chain.

Parameters:
  • wallet (bittensor.wallet()) – Wallet object that can sign the extrinsic.

  • hotkey_ss58 (str) – Hotkey ss58 address to stake to.

  • amount (Balance()) – Amount to stake.

  • wait_for_inclusion (bool) – If true, waits for inclusion before returning.

  • wait_for_finalization (bool) – If true, waits for finalization before returning.

Returns:

True if the extrinsic was successful.

Return type:

success (bool)

Raises:

StakeError – If the extrinsic failed.

_do_unstake(wallet, hotkey_ss58, amount, wait_for_inclusion=True, wait_for_finalization=False)[source]#

Sends an unstake extrinsic to the chain.

Parameters:
  • wallet (bittensor.wallet()) – Wallet object that can sign the extrinsic.

  • hotkey_ss58 (str) – Hotkey ss58 address to unstake from.

  • amount (Balance()) – Amount to unstake.

  • wait_for_inclusion (bool) – If true, waits for inclusion before returning.

  • wait_for_finalization (bool) – If true, waits for finalization before returning.

Returns:

True if the extrinsic was successful.

Return type:

success (bool)

Raises:

StakeError – If the extrinsic failed.

static min_required_stake()[source]#

As the minimum required stake may change, this method allows us to dynamically update the amount in the mock without updating the tests

get_minimum_required_stake()[source]#

Returns the minimum required stake for nominators in the Subtensor network.

This method retries the substrate call up to three times with exponential backoff in case of failures.

Returns:

The minimum required stake as a Balance object.

Return type:

Balance

Raises:

Exception – If the substrate call fails after the maximum number of retries.

get_delegate_by_hotkey(hotkey_ss58, block=None)[source]#

Retrieves detailed information about a delegate neuron based on its hotkey. This function provides a comprehensive view of the delegate’s status, including its stakes, nominators, and reward distribution.

Parameters:
  • hotkey_ss58 (str) – The SS58 address of the delegate’s hotkey.

  • block (Optional[int], optional) – The blockchain block number for the query.

Returns:

Detailed information about the delegate neuron, None if not found.

Return type:

Optional[DelegateInfo]

This function is essential for understanding the roles and influence of delegate neurons within the Bittensor network’s consensus and governance structures.

get_delegates(block=None)[source]#

Retrieves a list of all delegate neurons within the Bittensor network. This function provides an overview of the neurons that are actively involved in the network’s delegation system.

Analyzing the delegate population offers insights into the network’s governance dynamics and the distribution of trust and responsibility among participating neurons.

Parameters:

block (Optional[int], optional) – The blockchain block number for the query.

Returns:

A list of DelegateInfo objects detailing each delegate’s characteristics.

Return type:

List[DelegateInfo]

get_delegated(coldkey_ss58, block=None)[source]#

Returns the list of delegates that a given coldkey is staked to.

Parameters:
  • coldkey_ss58 (str)

  • block (Optional[int])

Return type:

List[Tuple[bittensor.chain_data.DelegateInfo, bittensor.utils.balance.Balance]]

get_all_subnets_info(block=None)[source]#

Retrieves detailed information about all subnets within the Bittensor network. This function provides comprehensive data on each subnet, including its characteristics and operational parameters.

Parameters:

block (Optional[int], optional) – The blockchain block number for the query.

Returns:

A list of SubnetInfo objects, each containing detailed information about a subnet.

Return type:

List[SubnetInfo]

Gaining insights into the subnets’ details assists in understanding the network’s composition, the roles of different subnets, and their unique features.

get_subnet_info(netuid, block=None)[source]#

Retrieves detailed information about a specific subnet within the Bittensor network. This function provides key data on the subnet, including its operational parameters and network status.

Parameters:
  • netuid (int) – The network UID of the subnet to query.

  • block (Optional[int], optional) – The blockchain block number for the query.

Returns:

Detailed information about the subnet, or None if not found.

Return type:

Optional[SubnetInfo]

This function is essential for neurons and stakeholders interested in the specifics of a particular subnet, including its governance, performance, and role within the broader network.

_do_serve_prometheus(wallet, call_params, wait_for_inclusion=False, wait_for_finalization=True)[source]#

Sends a serve prometheus extrinsic to the chain. :param wallet: Wallet object. :type wallet: bittensor.wallet() :param call_params: Prometheus serve call parameters. :type call_params: PrometheusServeCallParams() :param wait_for_inclusion: If true, waits for inclusion. :type wait_for_inclusion: bool :param wait_for_finalization: If true, waits for finalization. :type wait_for_finalization: bool

Returns:

True if serve prometheus was successful. error (Optional[str]()): Error message if serve prometheus failed, None otherwise.

Return type:

success (bool)

Parameters:
_do_set_weights(wallet, netuid, uids, vals, version_key, wait_for_inclusion=False, wait_for_finalization=True)[source]#

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:
  • 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.

_do_serve_axon(wallet, call_params, wait_for_inclusion=False, wait_for_finalization=True)[source]#

Internal method to submit a serve axon transaction to the Bittensor blockchain. This method creates and submits a transaction, enabling a neuron’s Axon to serve requests on the network.

Parameters:
  • wallet (bittensor.wallet) – The wallet associated with the neuron.

  • call_params (AxonServeCallParams) – Parameters required for the serve axon call.

  • 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 function is crucial for initializing and announcing a neuron’s Axon service on the network, enhancing the decentralized computation capabilities of Bittensor.