bittensor.utils.registration.pow#
This module provides utilities for solving Proof-of-Work (PoW) challenges in Bittensor network.
Attributes#
Classes#
A process that solves the registration PoW problem. |
|
A lazy-loading proxy for the torch module. |
|
A solution to the registration PoW problem. |
|
Statistics for a registration. |
|
Logs statistics for a registration. |
|
A process that solves the registration PoW problem. |
|
Functions#
|
Creates a proof of work for the given subtensor and wallet. |
Returns the number of CPUs in the system. |
|
|
Convert function operating on numpy Input&Output to legacy torch Input&Output API if use_torch() is True. |
|
|
|
Update the current block data with the provided block information and difficulty. |
Force the use of torch over numpy for certain operations. |
Module Contents#
- class bittensor.utils.registration.pow.CUDASolver(proc_num, num_proc, update_interval, finished_queue, solution_queue, stopEvent, curr_block, curr_block_num, curr_diff, check_block, limit, dev_id, tpb)[source]#
Bases:
_SolverBaseA process that solves the registration PoW problem.
- Parameters:
proc_num – The number of the process being created.
num_proc – The total number of processes running.
update_interval – The number of nonces to try to solve before checking for a new block.
finished_queue – The queue to put the process number when a process finishes each update_interval. Used for calculating the average time per update_interval across all processes.
solution_queue – The queue to put the solution the process has found during the pow solve.
stopEvent – The event to set by the main process when all the solver processes should stop. The solver process will check for the event after each update_interval. The solver process will stop when the event is set. Used to stop the solver processes when a solution is found.
curr_block – The array containing this process’s current block hash. The main process will set the array to the new block hash when a new block is finalized in the network. The solver process will get the new block hash from this array when newBlockEvent is set.
curr_block_num – The value containing this process’s current block number. The main process will set the value to the new block number when a new block is finalized in the network. The solver process will get the new block number from this value when newBlockEvent is set.
curr_diff – The array containing this process’s current difficulty. The main process will set the array to the new difficulty when a new block is finalized in the network. The solver process will get the new difficulty from this array when newBlockEvent is set.
check_block – The lock to prevent this process from getting the new block data while the main process is updating the data.
limit – The limit of the pow solve for a valid solution.
dev_id (int)
tpb (int)
- class bittensor.utils.registration.pow.LazyLoadedTorch[source]#
A lazy-loading proxy for the torch module.
- class bittensor.utils.registration.pow.POWSolution[source]#
A solution to the registration PoW problem.
- is_stale(subtensor)[source]#
Synchronous implementation. Returns True if the POW is stale.
This means the block the POW is solved for is within 3 blocks of the current block.
- Parameters:
subtensor (bittensor.core.subtensor.Subtensor)
- Return type:
- class bittensor.utils.registration.pow.RegistrationStatistics[source]#
Statistics for a registration.
- class bittensor.utils.registration.pow.RegistrationStatisticsLogger(console=None, output_in_place=True)[source]#
Logs statistics for a registration.
- console = None#
- classmethod get_status_message(stats, verbose=False)[source]#
Generates the status message based on registration statistics.
- Parameters:
stats (RegistrationStatistics)
verbose (bool)
- Return type:
- update(stats, verbose=False)[source]#
- Parameters:
stats (RegistrationStatistics)
verbose (bool)
- Return type:
None
- class bittensor.utils.registration.pow.Solver(proc_num, num_proc, update_interval, finished_queue, solution_queue, stopEvent, curr_block, curr_block_num, curr_diff, check_block, limit)[source]#
Bases:
_SolverBaseA process that solves the registration PoW problem.
- Parameters:
proc_num – The number of the process being created.
num_proc – The total number of processes running.
update_interval – The number of nonces to try to solve before checking for a new block.
finished_queue – The queue to put the process number when a process finishes each update_interval. Used for calculating the average time per update_interval across all processes.
solution_queue – The queue to put the solution the process has found during the pow solve.
stopEvent – The event to set by the main process when all the solver processes should stop. The solver process will check for the event after each update_interval. The solver process will stop when the event is set. Used to stop the solver processes when a solution is found.
curr_block – The array containing this process’s current block hash. The main process will set the array to the new block hash when a new block is finalized in the network. The solver process will get the new block hash from this array when newBlockEvent is set.
curr_block_num – The value containing this process’s current block number. The main process will set the value to the new block number when a new block is finalized in the network. The solver process will get the new block number from this value when newBlockEvent is set.
curr_diff – The array containing this process’s current difficulty. The main process will set the array to the new difficulty when a new block is finalized in the network. The solver process will get the new difficulty from this array when newBlockEvent is set.
check_block – The lock to prevent this process from getting the new block data while the main process is updating the data.
limit – The limit of the pow solve for a valid solution.
- class bittensor.utils.registration.pow.UsingSpawnStartMethod(force=False)[source]#
- Parameters:
force (bool)
- bittensor.utils.registration.pow.create_pow(subtensor, wallet, netuid, output_in_place=True, cuda=False, dev_id=0, tpb=256, num_processes=None, update_interval=None, log_verbose=False)[source]#
Creates a proof of work for the given subtensor and wallet.
- Parameters:
subtensor (bittensor.core.subtensor.Subtensor) – The Subtensor instance.
wallet (bittensor_wallet.Wallet) – The Bittensor Wallet instance.
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 (Optional[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 (Optional[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:
Optional[POWSolution]
- bittensor.utils.registration.pow.get_cpu_count()[source]#
Returns the number of CPUs in the system.
- Return type:
- bittensor.utils.registration.pow.legacy_torch_api_compat(func)[source]#
Convert function operating on numpy Input&Output to legacy torch Input&Output API if use_torch() is True.
- Parameters:
func – Function with numpy Input/Output to be decorated.
- Returns:
Decorated function.
- Return type:
decorated
- bittensor.utils.registration.pow.terminate_workers_and_wait_for_exit(workers)[source]#
- Parameters:
workers (list[Union[multiprocessing.Process, multiprocessing.queues.Queue]])
- Return type:
None
- bittensor.utils.registration.pow.torch#
- bittensor.utils.registration.pow.update_curr_block(curr_diff, curr_block, curr_block_num, block_number, block_bytes, diff, hotkey_bytes, lock)[source]#
Update the current block data with the provided block information and difficulty.
This function updates the current block and its difficulty in a thread-safe manner. It sets the current block number, hashes the block with the hotkey, updates the current block bytes, and packs the difficulty.
- Parameters:
curr_diff (multiprocessing.Array) – Shared array to store the current difficulty.
curr_block (multiprocessing.Array) – Shared array to store the current block data.
curr_block_num (multiprocessing.Value) – Shared value to store the current block number.
block_number (int) – The block number to set as the current block number.
block_bytes (bytes) – The block data bytes to be hashed with the hotkey.
diff (int) – The difficulty value to be packed into the current difficulty array.
hotkey_bytes (bytes) – The hotkey bytes used for hashing the block.
lock (multiprocessing.Lock) – A lock to ensure thread-safe updates.