bittensor.chain_data

Contents

bittensor.chain_data#

This module provides data structures and functions for working with the Bittensor network, including neuron and subnet information, SCALE encoding/decoding, and custom RPC type registry.

Attributes#

Classes#

AxonInfo

ChainDataType

Create a collection of name/value pairs.

NeuronInfo

Dataclass for neuron metadata.

NeuronInfoLite

Dataclass for neuron metadata, but without the weights and bonds.

PrometheusInfo

Dataclass for prometheus info.

DelegateInfoLite

Dataclass for DelegateLiteInfo. This is a lighter version of DelegateInfo().

DelegateInfo

Dataclass for delegate information. For a lighter version of this class, see DelegateInfoLite().

StakeInfo

Dataclass for stake info.

SubnetInfo

Dataclass for subnet info.

SubnetHyperparameters

Dataclass for subnet hyperparameters.

IPInfo

Dataclass for associated IP Info.

ProposalVoteData

dict() -> new empty dictionary

ScheduledColdkeySwapInfo

Dataclass for scheduled coldkey swap information.

Functions#

from_scale_encoding(input_, type_name[, is_vec, is_option])

Decodes input_ data from SCALE encoding based on the specified type name and modifiers.

from_scale_encoding_using_type_string(input_, type_string)

Module Contents#

bittensor.chain_data.custom_rpc_type_registry#
class bittensor.chain_data.AxonInfo[source]#
version: int#
ip: str#
port: int#
ip_type: int#
hotkey: str#
coldkey: str#
protocol: int = 4#
placeholder1: int = 0#
placeholder2: int = 0#
property is_serving: bool#

True if the endpoint is serving.

Return type:

bool

ip_str()[source]#

Return the whole IP as string

Return type:

str

__eq__(other)[source]#
Parameters:

other (AxonInfo)

__str__()[source]#
__repr__()[source]#
to_string()[source]#

Converts the AxonInfo object to a string representation using JSON.

Return type:

str

classmethod from_string(json_string)[source]#

Creates an AxonInfo object from its string representation using JSON.

Parameters:

json_string (str) – The JSON string representation of the AxonInfo object.

Returns:

An instance of AxonInfo created from the JSON string. If decoding fails, returns a default AxonInfo object with default values.

Return type:

AxonInfo

Raises:
  • json.JSONDecodeError – If there is an error in decoding the JSON string.

  • TypeError – If there is a type error when creating the AxonInfo object.

  • ValueError – If there is a value error when creating the AxonInfo object.

classmethod from_neuron_info(neuron_info)[source]#

Converts a dictionary to an AxonInfo object.

Parameters:

neuron_info (dict) – A dictionary containing the neuron information.

Returns:

An instance of AxonInfo created from the dictionary.

Return type:

instance (AxonInfo)

to_parameter_dict()[source]#

Returns a torch tensor or dict of the subnet info, depending on the USE_TORCH flag set.

Return type:

Union[dict[str, Union[int, str]], bittensor.utils.registration.torch.nn.ParameterDict]

classmethod from_parameter_dict(parameter_dict)[source]#

Returns an axon_info object from a torch parameter_dict or a parameter dict.

Parameters:

parameter_dict (Union[dict[str, Any], bittensor.utils.registration.torch.nn.ParameterDict])

Return type:

AxonInfo

class bittensor.chain_data.ChainDataType(*args, **kwds)[source]#

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

NeuronInfo = 1#
SubnetInfo = 2#
DelegateInfo = 3#
NeuronInfoLite = 4#
DelegatedInfo = 5#
StakeInfo = 6#
IPInfo = 7#
SubnetHyperparameters = 8#
ScheduledColdkeySwapInfo = 9#
bittensor.chain_data.from_scale_encoding(input_, type_name, is_vec=False, is_option=False)[source]#

Decodes input_ data from SCALE encoding based on the specified type name and modifiers.

Parameters:
  • input (Union[List[int], bytes, ScaleBytes]) – The input_ data to decode.

  • type_name (ChainDataType) – The type of data being decoded.

  • is_vec (bool, optional) – Whether the data is a vector of the specified type. Default is False.

  • is_option (bool, optional) – Whether the data is an optional value of the specified type. Default is False.

  • input_ (Union[List[int], bytes, scalecodec.base.ScaleBytes])

Returns:

The decoded data as a dictionary, or None if the decoding fails.

Return type:

Optional[Dict]

bittensor.chain_data.from_scale_encoding_using_type_string(input_, type_string)[source]#
Parameters:
  • input_ (Union[List[int], bytes, scalecodec.base.ScaleBytes])

  • type_string (str)

Return type:

Optional[Dict]

class bittensor.chain_data.NeuronInfo[source]#

Dataclass for neuron metadata.

hotkey: str#
coldkey: str#
uid: int#
netuid: int#
active: int#
stake: bittensor.utils.balance.Balance#
stake_dict: Dict[str, bittensor.utils.balance.Balance]#
total_stake: bittensor.utils.balance.Balance#
rank: float#
emission: float#
incentive: float#
consensus: float#
trust: float#
validator_trust: float#
dividends: float#
last_update: int#
validator_permit: bool#
weights: List[List[int]]#
bonds: List[List[int]]#
pruning_score: int#
prometheus_info: PrometheusInfo | None = None#
axon_info: AxonInfo | None = None#
is_null: bool = False#
classmethod fix_decoded_values(neuron_info_decoded)[source]#

Fixes the values of the NeuronInfo object.

Parameters:

neuron_info_decoded (Any)

Return type:

NeuronInfo

classmethod from_vec_u8(vec_u8)[source]#

Returns a NeuronInfo object from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

NeuronInfo

classmethod list_from_vec_u8(vec_u8)[source]#

Returns a list of NeuronInfo objects from a vec_u8

Parameters:

vec_u8 (List[int])

Return type:

List[NeuronInfo]

static get_null_neuron()[source]#
Return type:

NeuronInfo

classmethod from_weights_bonds_and_neuron_lite(neuron_lite, weights_as_dict, bonds_as_dict)[source]#
Parameters:
Return type:

NeuronInfo

class bittensor.chain_data.NeuronInfoLite[source]#

Dataclass for neuron metadata, but without the weights and bonds.

hotkey: str#
coldkey: str#
uid: int#
netuid: int#
active: int#
stake: bittensor.utils.balance.Balance#
stake_dict: Dict[str, bittensor.utils.balance.Balance]#
total_stake: bittensor.utils.balance.Balance#
rank: float#
emission: float#
incentive: float#
consensus: float#
trust: float#
validator_trust: float#
dividends: float#
last_update: int#
validator_permit: bool#
prometheus_info: PrometheusInfo | None#
axon_info: NeuronInfoLite.axon_info#
pruning_score: int#
is_null: bool = False#
classmethod fix_decoded_values(neuron_info_decoded)[source]#

Fixes the values of the NeuronInfoLite object.

Parameters:

neuron_info_decoded (Any)

Return type:

NeuronInfoLite

classmethod from_vec_u8(vec_u8)[source]#

Returns a NeuronInfoLite object from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

NeuronInfoLite

classmethod list_from_vec_u8(vec_u8)[source]#

Returns a list of NeuronInfoLite objects from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

List[NeuronInfoLite]

static get_null_neuron()[source]#
Return type:

NeuronInfoLite

class bittensor.chain_data.PrometheusInfo[source]#

Dataclass for prometheus info.

block: int#
version: int#
ip: str#
port: int#
ip_type: int#
classmethod fix_decoded_values(prometheus_info_decoded)[source]#

Returns a PrometheusInfo object from a prometheus_info_decoded dictionary.

Parameters:

prometheus_info_decoded (Dict)

Return type:

PrometheusInfo

class bittensor.chain_data.DelegateInfoLite[source]#

Dataclass for DelegateLiteInfo. This is a lighter version of DelegateInfo().

Parameters:
  • delegate_ss58 (str) – Hotkey of the delegate for which the information is being fetched.

  • take (float) – Take of the delegate as a percentage.

  • nominators (int) – Count of the nominators of the delegate.

  • owner_ss58 (str) – Coldkey of the owner.

  • registrations (list[int]) – List of subnets that the delegate is registered on.

  • validator_permits (list[int]) – List of subnets that the delegate is allowed to validate on.

  • return_per_1000 (int) – Return per 1000 TAO, for the delegate over a day.

  • total_daily_return (int) – Total daily return of the delegate.

delegate_ss58: str#
take: float#
nominators: int#
owner_ss58: str#
registrations: list[int]#
validator_permits: list[int]#
return_per_1000: int#
total_daily_return: int#
class bittensor.chain_data.DelegateInfo[source]#

Dataclass for delegate information. For a lighter version of this class, see DelegateInfoLite().

Parameters:
  • hotkey_ss58 (str) – Hotkey of the delegate for which the information is being fetched.

  • total_stake (int) – Total stake of the delegate.

  • nominators (list[Tuple[str, int]]) – List of nominators of the delegate and their stake.

  • take (float) – Take of the delegate as a percentage.

  • owner_ss58 (str) – Coldkey of the owner.

  • registrations (list[int]) – List of subnets that the delegate is registered on.

  • validator_permits (list[int]) – List of subnets that the delegate is allowed to validate on.

  • return_per_1000 (int) – Return per 1000 TAO, for the delegate over a day.

  • total_daily_return (int) – Total daily return of the delegate.

hotkey_ss58: str#
total_stake: bittensor.utils.balance.Balance#
nominators: List[Tuple[str, bittensor.utils.balance.Balance]]#
owner_ss58: str#
take: float#
validator_permits: List[int]#
registrations: List[int]#
return_per_1000: bittensor.utils.balance.Balance#
total_daily_return: bittensor.utils.balance.Balance#
classmethod fix_decoded_values(decoded)[source]#

Fixes the decoded values.

Parameters:

decoded (Any)

Return type:

DelegateInfo

classmethod from_vec_u8(vec_u8)[source]#

Returns a DelegateInfo object from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

Optional[DelegateInfo]

classmethod list_from_vec_u8(vec_u8)[source]#

Returns a list of DelegateInfo objects from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

List[DelegateInfo]

classmethod delegated_list_from_vec_u8(vec_u8)[source]#

Returns a list of Tuples of DelegateInfo objects, and Balance, from a vec_u8.

This is the list of delegates that the user has delegated to, and the amount of stake delegated.

Parameters:

vec_u8 (List[int])

Return type:

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

class bittensor.chain_data.StakeInfo[source]#

Dataclass for stake info.

hotkey_ss58: str#
coldkey_ss58: str#
stake: bittensor.utils.balance.Balance#
classmethod fix_decoded_values(decoded)[source]#

Fixes the decoded values.

Parameters:

decoded (Any)

Return type:

StakeInfo

classmethod from_vec_u8(vec_u8)[source]#

Returns a StakeInfo object from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

Optional[StakeInfo]

classmethod list_of_tuple_from_vec_u8(vec_u8)[source]#

Returns a list of StakeInfo objects from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

Dict[str, List[StakeInfo]]

classmethod list_from_vec_u8(vec_u8)[source]#

Returns a list of StakeInfo objects from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

List[StakeInfo]

class bittensor.chain_data.SubnetInfo[source]#

Dataclass for subnet info.

netuid: int#
rho: int#
kappa: int#
difficulty: int#
immunity_period: int#
max_allowed_validators: int#
min_allowed_weights: int#
max_weight_limit: float#
scaling_law_power: float#
subnetwork_n: int#
max_n: int#
blocks_since_epoch: int#
tempo: int#
modality: int#
connection_requirements: Dict[str, float]#
emission_value: float#
burn: bittensor.utils.balance.Balance#
owner_ss58: str#
classmethod from_vec_u8(vec_u8)[source]#

Returns a SubnetInfo object from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

Optional[SubnetInfo]

classmethod list_from_vec_u8(vec_u8)[source]#

Returns a list of SubnetInfo objects from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

List[SubnetInfo]

classmethod fix_decoded_values(decoded)[source]#

Returns a SubnetInfo object from a decoded SubnetInfo dictionary.

Parameters:

decoded (Dict)

Return type:

SubnetInfo

to_parameter_dict()[source]#

Returns a torch tensor or dict of the subnet info.

Return type:

Union[dict[str, Any], bittensor.utils.registration.torch.nn.ParameterDict]

classmethod from_parameter_dict(parameter_dict)[source]#
Parameters:

parameter_dict (Union[dict[str, Any], bittensor.utils.registration.torch.nn.ParameterDict])

Return type:

SubnetInfo

class bittensor.chain_data.SubnetHyperparameters[source]#

Dataclass for subnet hyperparameters.

rho: int#
kappa: int#
immunity_period: int#
min_allowed_weights: int#
max_weight_limit: float#
tempo: int#
min_difficulty: int#
max_difficulty: int#
weights_version: int#
weights_rate_limit: int#
adjustment_interval: int#
activity_cutoff: int#
registration_allowed: bool#
target_regs_per_interval: int#
min_burn: int#
max_burn: int#
bonds_moving_avg: int#
max_regs_per_block: int#
serving_rate_limit: int#
max_validators: int#
adjustment_alpha: int#
difficulty: int#
commit_reveal_weights_interval: int#
commit_reveal_weights_enabled: bool#
alpha_high: int#
alpha_low: int#
liquid_alpha_enabled: bool#
classmethod from_vec_u8(vec_u8)[source]#

Returns a SubnetHyperparameters object from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

Optional[SubnetHyperparameters]

classmethod list_from_vec_u8(vec_u8)[source]#

Returns a list of SubnetHyperparameters objects from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

List[SubnetHyperparameters]

classmethod fix_decoded_values(decoded)[source]#

Returns a SubnetInfo object from a decoded SubnetInfo dictionary.

Parameters:

decoded (Dict)

Return type:

SubnetHyperparameters

to_parameter_dict()[source]#

Returns a torch tensor or dict of the subnet hyperparameters.

Return type:

Union[dict[str, Union[int, float, bool]], bittensor.utils.registration.torch.nn.ParameterDict]

classmethod from_parameter_dict(parameter_dict)[source]#
Parameters:

parameter_dict (Union[dict[str, Any], bittensor.utils.registration.torch.nn.ParameterDict])

Return type:

SubnetHyperparameters

class bittensor.chain_data.IPInfo[source]#

Dataclass for associated IP Info.

ip: str#
ip_type: int#
protocol: int#
encode()[source]#

Returns a dictionary of the IPInfo object that can be encoded.

Return type:

Dict[str, Any]

classmethod from_vec_u8(vec_u8)[source]#

Returns a IPInfo object from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

Optional[IPInfo]

classmethod list_from_vec_u8(vec_u8)[source]#

Returns a list of IPInfo objects from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

List[IPInfo]

classmethod fix_decoded_values(decoded)[source]#

Returns a SubnetInfo object from a decoded IPInfo dictionary.

Parameters:

decoded (Dict)

Return type:

IPInfo

to_parameter_dict()[source]#

Returns a torch tensor or dict of the subnet IP info.

Return type:

Union[dict[str, Union[str, int]], bittensor.utils.registration.torch.nn.ParameterDict]

classmethod from_parameter_dict(parameter_dict)[source]#
Parameters:

parameter_dict (Union[dict[str, Any], bittensor.utils.registration.torch.nn.ParameterDict])

Return type:

IPInfo

class bittensor.chain_data.ProposalVoteData[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.

index: int#
threshold: int#
ayes: List[str]#
nays: List[str]#
end: int#
bittensor.chain_data.ProposalCallData#
class bittensor.chain_data.ScheduledColdkeySwapInfo[source]#

Dataclass for scheduled coldkey swap information.

old_coldkey: str#
new_coldkey: str#
arbitration_block: int#
classmethod fix_decoded_values(decoded)[source]#

Fixes the decoded values.

Parameters:

decoded (Any)

Return type:

ScheduledColdkeySwapInfo

classmethod from_vec_u8(vec_u8)[source]#

Returns a ScheduledColdkeySwapInfo object from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

Optional[ScheduledColdkeySwapInfo]

classmethod list_from_vec_u8(vec_u8)[source]#

Returns a list of ScheduledColdkeySwapInfo objects from a vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

List[ScheduledColdkeySwapInfo]

classmethod decode_account_id_list(vec_u8)[source]#

Decodes a list of AccountIds from vec_u8.

Parameters:

vec_u8 (List[int])

Return type:

Optional[List[str]]