bittensor.utils.registration.async_pow#

This module provides async utilities for solving Proof-of-Work (PoW) challenges in Bittensor network.

Attributes#

Functions#

_block_solver(subtensor, wallet, num_processes, ...)

Shared code used by the Solvers to solve the POW solution.

_check_for_newest_block_and_update(subtensor, netuid, ...)

Check for the newest block and update block-related information and states across solvers if a new block is detected.

_get_block_with_retry(subtensor, netuid)

Gets the current block number, difficulty, and block hash from the substrate node.

_solve_for_difficulty_fast(subtensor, wallet, netuid)

Solves the POW for registration using multiprocessing.

_solve_for_difficulty_fast_cuda(subtensor, wallet, netuid)

Solves the registration fast using CUDA

create_pow_async(subtensor, wallet, netuid[, ...])

Creates a proof of work for the given subtensor and wallet.

Module Contents#

async bittensor.utils.registration.async_pow._block_solver(subtensor, wallet, num_processes, netuid, dev_id, tpb, update_interval, curr_block, curr_block_num, curr_diff, n_samples, alpha_, output_in_place, log_verbose, cuda)#

Shared code used by the Solvers to solve the POW solution.

Parameters:
async bittensor.utils.registration.async_pow._check_for_newest_block_and_update(subtensor, netuid, old_block_number, hotkey_bytes, curr_diff, curr_block, curr_block_num, update_curr_block_, check_block, solvers, curr_stats)#

Check for the newest block and update block-related information and states across solvers if a new block is detected.

Parameters:
  • subtensor (AsyncSubtensor) – The subtensor instance interface.

  • netuid (int) – The network UID for the blockchain.

  • old_block_number (int) – The previously known block number.

  • hotkey_bytes (bytes) – The bytes representation of the hotkey.

  • curr_diff (Array) – The current difficulty level.

  • curr_block (Array) – The current block information.

  • curr_block_num (Value) – The current block number.

  • update_curr_block (Callable) – Function to update current block information.

  • check_block (Lock) – Lock object for synchronizing block checking.

  • solvers (list[Solver]) – List of solvers to notify of new blocks.

  • curr_stats (RegistrationStatistics) – Current registration statistics to update.

  • update_curr_block_ (Callable)

Returns:

The updated block number which is the same as the new block

number if it was detected, otherwise the old block number.

Return type:

int

async bittensor.utils.registration.async_pow._get_block_with_retry(subtensor, netuid)#

Gets the current block number, difficulty, and block hash from the substrate node.

Parameters:
  • subtensor (bittensor.core.async_subtensor.AsyncSubtensor) – The subtensor object to use to get the block number, difficulty, and block hash.

  • netuid (int) – The netuid of the network to get the block number, difficulty, and block hash from.

Returns:

The current block number, difficulty of the subnet, block hash

Raises:
Return type:

tuple[int, int, str]

async bittensor.utils.registration.async_pow._solve_for_difficulty_fast(subtensor, wallet, netuid, output_in_place=True, num_processes=None, update_interval=None, n_samples=10, alpha_=0.8, log_verbose=False)#

Solves the POW for registration using multiprocessing.

Parameters:
  • subtensor (bittensor.core.async_subtensor.AsyncSubtensor) – The subtensor object to use to get the block number, difficulty, and block hash.

  • wallet (bittensor_wallet.Wallet) – wallet to use for registration.

  • netuid (int) – The netuid of the subnet to register to.

  • output_in_place (bool) – If true, prints the status in place. Otherwise, prints the status on a new line.

  • num_processes (Optional[int]) – Number of processes to use.

  • update_interval (Optional[int]) – Number of nonces to solve before updating block information.

  • n_samples (int) – The number of samples of the hash_rate to keep for the EWMA

  • alpha (float) – The alpha for the EWMA for the hash_rate calculation

  • log_verbose (bool) – If true, prints more verbose logging of the registration metrics.

  • alpha_ (float)

Return type:

Optional[bittensor.utils.registration.POWSolution]

Notes

The hash rate is calculated as an exponentially weighted moving average in order to make the measure more robust. We can also modify the update interval to do smaller blocks of work, while still updating the block information after a different number of nonces, to increase the transparency of the process while still keeping the speed.

async bittensor.utils.registration.async_pow._solve_for_difficulty_fast_cuda(subtensor, wallet, netuid, output_in_place=True, update_interval=50000, tpb=512, dev_id=0, n_samples=10, alpha_=0.8, log_verbose=False)#

Solves the registration fast using CUDA

Parameters:
  • subtensor (bittensor.core.async_subtensor.AsyncSubtensor) – The subtensor object to use to get the block number, difficulty, and block hash.

  • wallet (bittensor_wallet.Wallet) – The wallet to register

  • netuid (int) – The netuid of the subnet to register to.

  • output_in_place (bool) – If true, prints the output in place, otherwise prints to new lines

  • update_interval (int) – The number of nonces to try before checking for more blocks

  • tpb (int) – The number of threads per block. CUDA param that should match the GPU capability

  • dev_id (Union[list[int], int]) – The CUDA device IDs to execute the registration on, either a single device or a list of devices

  • n_samples (int) – The number of samples of the hash_rate to keep for the EWMA

  • alpha (float) – The alpha for the EWMA for the hash_rate calculation

  • log_verbose (bool) – If true, prints more verbose logging of the registration metrics.

  • alpha_ (float)

Return type:

Optional[bittensor.utils.registration.POWSolution]

Note

The hash rate is calculated as an exponentially weighted moving average in order to make the measure more robust.

async bittensor.utils.registration.async_pow.create_pow_async(subtensor, wallet, netuid, output_in_place=True, cuda=False, dev_id=0, tpb=256, num_processes=None, update_interval=None, log_verbose=False)#

Creates a proof of work for the given subtensor and wallet.

Parameters:
  • subtensor (bittensor.core.async_subtensor.AsyncSubtensor) – The subtensor object to use to get the block number, difficulty, and block hash.

  • wallet (bittensor_wallet.Wallet) – The wallet to create a proof of work for.

  • netuid (int) – The netuid for the subnet to create a proof of work for.

  • output_in_place (bool) – If true, prints the progress of the proof of work to the console in-place. Meaning the progress is printed on the same lines.

  • cuda (bool) – If true, uses CUDA to solve the proof of work.

  • dev_id (Union[list[int], int]) – The CUDA device id(s) to use. If cuda is true and dev_id is a list, then multiple CUDA devices will be used to solve the proof of work.

  • tpb (int) – The number of threads per block to use when solving the proof of work. Should be a multiple of 32.

  • num_processes (int) – The number of processes to use when solving the proof of work. If None, then the number of processes is equal to the number of CPU cores.

  • update_interval (int) – The number of nonces to run before checking for a new block.

  • log_verbose (bool) – If true, prints the progress of the proof of work more verbosely.

Returns:

The proof of work solution or None if the wallet is already registered or there is a different error.

Raises:

ValueError – If the subnet does not exist.

Return type:

bittensor.utils.registration.POWSolution

bittensor.utils.registration.async_pow.torch#