bittensor.core.chain_data

Contents

bittensor.core.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.

Submodules#

Attributes#

Classes#

AxonInfo

The AxonInfo class represents information about an axon endpoint in the Bittensor network. This includes

DelegateInfo

Dataclass for delegate information. For a lighter version of this class, see bittensor.core.chain_data.delegate_info_lite.

DelegateInfoLite

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

IPInfo

Dataclass representing IP information.

NeuronInfo

Represents the metadata of a neuron including keys, UID, stake, rankings, and other attributes.

NeuronInfoLite

NeuronInfoLite is a dataclass representing neuron metadata without weights and bonds.

PrometheusInfo

Dataclass representing information related to Prometheus.

ProposalVoteData

This TypedDict represents the data structure for a proposal vote in the Senate.

ScheduledColdkeySwapInfo

The ScheduledColdkeySwapInfo class is a dataclass representing information about scheduled cold key swaps.

StakeInfo

Dataclass for representing stake information linked to hotkey and coldkey pairs.

SubnetHyperparameters

This class represents the hyperparameters for a subnet.

SubnetInfo

Dataclass for subnet info.

Package Contents#

class bittensor.core.chain_data.AxonInfo[source]#

The AxonInfo class represents information about an axon endpoint in the Bittensor network. This includes properties such as IP address, ports, and relevant keys.

Variables:
  • version (int) – The version of the axon endpoint.

  • ip (str) – The IP address of the axon endpoint.

  • port (int) – The port number the axon endpoint uses.

  • ip_type (int) – The type of IP protocol (e.g., IPv4 or IPv6).

  • hotkey (str) – The hotkey associated with the axon endpoint.

  • coldkey (str) – The coldkey associated with the axon endpoint.

  • protocol (int) – The protocol version (default is 4).

  • placeholder1 (int) – Reserved field (default is 0).

  • placeholder2 (int) – Reserved field (default is 0).

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:
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.core.chain_data.DelegateInfo[source]#

Dataclass for delegate information. For a lighter version of this class, see bittensor.core.chain_data.delegate_info_lite.

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: tuple[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.core.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.core.chain_data.IPInfo[source]#

Dataclass representing IP information.

Variables:
  • ip (str) – The IP address as a string.

  • ip_type (int) – The type of the IP address (e.g., IPv4, IPv6).

  • protocol (int) – The protocol associated with the IP (e.g., TCP, UDP).

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]#

Creates a IPInfo instance from a parameter dictionary.

Parameters:

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

Return type:

IPInfo

class bittensor.core.chain_data.NeuronInfo[source]#

Represents the metadata of a neuron including keys, UID, stake, rankings, and other attributes.

Variables:
  • hotkey (str) – The hotkey associated with the neuron.

  • coldkey (str) – The coldkey associated with the neuron.

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

  • netuid (int) – The network unique identifier for the neuron.

  • active (int) – The active status of the neuron.

  • stake (Balance) – The balance staked to this neuron.

  • stake_dict (dict[str, Balance]) – A dictionary mapping coldkey to the amount staked.

  • total_stake (Balance) – The total amount of stake.

  • rank (float) – The rank score of the neuron.

  • emission (float) – The emission rate.

  • incentive (float) – The incentive value.

  • consensus (float) – The consensus score.

  • trust (float) – The trust score.

  • validator_trust (float) – The validation trust score.

  • dividends (float) – The dividends value.

  • last_update (int) – The timestamp of the last update.

  • validator_permit (bool) – Validator permit status.

  • weights (list[list[int]]) – List of weights associated with the neuron.

  • bonds (list[list[int]]) – List of bonds associated with the neuron.

  • pruning_score (int) – The pruning score of the neuron.

  • prometheus_info (Optional[PrometheusInfo]) – Information related to Prometheus.

  • axon_info (Optional[AxonInfo]) – Information related to Axon.

  • is_null (bool) – Indicator if this is a null neuron.

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: bittensor.core.chain_data.prometheus_info.PrometheusInfo | None = None#
axon_info: bittensor.core.chain_data.axon_info.AxonInfo | None = None#
is_null: bool = False#
classmethod from_weights_bonds_and_neuron_lite(neuron_lite, weights_as_dict, bonds_as_dict)[source]#

Creates an instance of NeuronInfo from NeuronInfoLite and dictionaries of weights and bonds.

Parameters:
  • neuron_lite (NeuronInfoLite) – A lite version of the neuron containing basic attributes.

  • weights_as_dict (dict[int, list[tuple[int, int]]]) – A dictionary where the key is the UID and the value is a list of weight tuples associated with the neuron.

  • bonds_as_dict (dict[int, list[tuple[int, int]]]) – A dictionary where the key is the UID and the value is a list of bond tuples associated with the neuron.

Returns:

An instance of NeuronInfo populated with the provided weights and bonds.

Return type:

NeuronInfo

static get_null_neuron()[source]#

Returns a null NeuronInfo instance.

Return type:

NeuronInfo

classmethod from_vec_u8(vec_u8)[source]#

Instantiates NeuronInfo from a byte vector.

Parameters:

vec_u8 (bytes)

Return type:

NeuronInfo

class bittensor.core.chain_data.NeuronInfoLite[source]#

NeuronInfoLite is a dataclass representing neuron metadata without weights and bonds.

Variables:
  • hotkey (str) – The hotkey string for the neuron.

  • coldkey (str) – The coldkey string for the neuron.

  • uid (int) – A unique identifier for the neuron.

  • netuid (int) – Network unique identifier for the neuron.

  • active (int) – Indicates whether the neuron is active.

  • stake (Balance) – The stake amount associated with the neuron.

  • stake_dict (dict) – Mapping of coldkey to the amount staked to this Neuron.

  • total_stake (Balance) – Total amount of the stake.

  • rank (float) – The rank of the neuron.

  • emission (float) – The emission value of the neuron.

  • incentive (float) – The incentive value of the neuron.

  • consensus (float) – The consensus value of the neuron.

  • trust (float) – Trust value of the neuron.

  • validator_trust (float) – Validator trust value of the neuron.

  • dividends (float) – Dividends associated with the neuron.

  • last_update (int) – Timestamp of the last update.

  • validator_permit (bool) – Indicates if the neuron has a validator permit.

  • prometheus_info (Optional[PrometheusInfo]) – Prometheus information associated with the neuron.

  • axon_info (Optional[AxonInfo]) – Axon information associated with the neuron.

  • pruning_score (int) – The pruning score of the neuron.

  • is_null (bool) – Indicates whether the neuron is null.

get_null_neuron()[source]#

Returns a NeuronInfoLite object representing a null neuron.

Return type:

NeuronInfoLite

list_from_vec_u8()[source]#

Decodes a bytes object into a list of NeuronInfoLite instances.

Parameters:

vec_u8 (bytes)

Return type:

list[NeuronInfoLite]

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: bittensor.core.chain_data.prometheus_info.PrometheusInfo | None#
axon_info: bittensor.core.chain_data.axon_info.AxonInfo | None#
pruning_score: int#
is_null: bool = False#
static get_null_neuron()[source]#

Returns a null NeuronInfoLite instance.

Return type:

NeuronInfoLite

classmethod list_from_vec_u8(vec_u8)[source]#

Decodes a bytes object into a list of NeuronInfoLite instances.

Parameters:

vec_u8 (bytes) – The bytes object to decode into NeuronInfoLite instances.

Returns:

A list of NeuronInfoLite instances decoded from the provided bytes object.

Return type:

list[NeuronInfoLite]

class bittensor.core.chain_data.PrometheusInfo[source]#

Dataclass representing information related to Prometheus.

Variables:
  • block (int) – The block number associated with the Prometheus data.

  • version (int) – The version of the Prometheus data.

  • ip (str) – The IP address associated with Prometheus.

  • port (int) – The port number for Prometheus.

  • ip_type (int) – The type of IP address (e.g., IPv4, IPv6).

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.core.chain_data.ProposalVoteData[source]#

Bases: TypedDict

This TypedDict represents the data structure for a proposal vote in the Senate.

Variables:
  • index (int) – The index of the proposal.

  • threshold (int) – The threshold required for the proposal to pass.

  • ayes (List[str]) – List of senators who voted ‘aye’.

  • nays (List[str]) – List of senators who voted ‘nay’.

  • end (int) – The ending timestamp of the voting period.

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

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

The ScheduledColdkeySwapInfo class is a dataclass representing information about scheduled cold key swaps.

Variables:
  • old_coldkey (str) – The old cold key before the swap.

  • new_coldkey (str) – The new cold key after the swap.

  • arbitration_block (int) – The block number at which the arbitration of the swap will take place.

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]]

class bittensor.core.chain_data.StakeInfo[source]#

Dataclass for representing stake information linked to hotkey and coldkey pairs.

Variables:
  • hotkey_ss58 (str) – The SS58 encoded hotkey address.

  • coldkey_ss58 (str) – The SS58 encoded coldkey address.

  • stake (Balance) – The stake associated with the hotkey-coldkey pair, represented as a Balance object.

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.core.chain_data.SubnetHyperparameters[source]#

This class represents the hyperparameters for a subnet.

Variables:
  • rho (int) – The rate of decay of some value.

  • kappa (int) – A constant multiplier used in calculations.

  • immunity_period (int) – The period during which immunity is active.

  • min_allowed_weights (int) – Minimum allowed weights.

  • max_weight_limit (float) – Maximum weight limit.

  • tempo (int) – The tempo or rate of operation.

  • min_difficulty (int) – Minimum difficulty for some operations.

  • max_difficulty (int) – Maximum difficulty for some operations.

  • weights_version (int) – The version number of the weights used.

  • weights_rate_limit (int) – Rate limit for processing weights.

  • adjustment_interval (int) – Interval at which adjustments are made.

  • activity_cutoff (int) – Activity cutoff threshold.

  • registration_allowed (bool) – Indicates if registration is allowed.

  • target_regs_per_interval (int) – Target number of registrations per interval.

  • min_burn (int) – Minimum burn value.

  • max_burn (int) – Maximum burn value.

  • bonds_moving_avg (int) – Moving average of bonds.

  • max_regs_per_block (int) – Maximum number of registrations per block.

  • serving_rate_limit (int) – Limit on the rate of service.

  • max_validators (int) – Maximum number of validators.

  • adjustment_alpha (int) – Alpha value for adjustments.

  • difficulty (int) – Difficulty level.

  • commit_reveal_weights_interval (int) – Interval for commit-reveal weights.

  • commit_reveal_weights_enabled (bool) – Flag indicating if commit-reveal weights are enabled.

  • alpha_high (int) – High value of alpha.

  • alpha_low (int) – Low value of alpha.

  • liquid_alpha_enabled (bool) – Flag indicating if liquid alpha is enabled.

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]#

Create a SubnetHyperparameters instance from a vector of bytes.

This method decodes the given vector of bytes using the bt_decode module and creates a new instance of SubnetHyperparameters with the decoded values.

Parameters:

vec_u8 (bytes) – A vector of bytes to decode into SubnetHyperparameters.

Returns:

An instance of SubnetHyperparameters if decoding is successful, None otherwise.

Return type:

Optional[SubnetHyperparameters]

class bittensor.core.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]#

Creates a SubnetInfo instance from a parameter dictionary.

Parameters:

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

Return type:

SubnetInfo

bittensor.core.chain_data.custom_rpc_type_registry#
bittensor.core.chain_data.ProposalCallData#