From 4b15803a22a8e5d21d8adf463d60e25984a78c1e Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Thu, 3 Apr 2025 04:04:26 +0100 Subject: [PATCH 01/20] add reset_bonds flag --- bittensor/core/extrinsics/asyncex/serving.py | 8 +++++++- bittensor/core/extrinsics/serving.py | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bittensor/core/extrinsics/asyncex/serving.py b/bittensor/core/extrinsics/asyncex/serving.py index 6fd5410838..92fa8c6dd9 100644 --- a/bittensor/core/extrinsics/asyncex/serving.py +++ b/bittensor/core/extrinsics/asyncex/serving.py @@ -236,6 +236,7 @@ async def publish_metadata( wait_for_inclusion: bool = False, wait_for_finalization: bool = True, period: Optional[int] = None, + reset_bonds: bool = False, ) -> bool: """ Publishes metadata on the Bittensor network using the specified wallet and network identifier. @@ -256,6 +257,7 @@ async def publish_metadata( period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If the transaction is not included in a block within that number of blocks, it will expire and be rejected. You can think of it as an expiration date for the transaction. + reset_bonds (bool, optional): If ``True``, the function will reset the bonds for the neuron. Defaults to ``False``. Returns: bool: ``True`` if the metadata was successfully published (and finalized if specified). ``False`` otherwise. @@ -269,13 +271,17 @@ async def publish_metadata( logging.error(unlock.message) return False + fields = [{f"{data_type}": data}] + if reset_bonds: + fields.append({"ResetBondsFlag": b""}) + async with subtensor.substrate as substrate: call = await substrate.compose_call( call_module="Commitments", call_function="set_commitment", call_params={ "netuid": netuid, - "info": {"fields": [[{f"{data_type}": data}]]}, + "info": {"fields": [fields]}, }, ) diff --git a/bittensor/core/extrinsics/serving.py b/bittensor/core/extrinsics/serving.py index 88da8997bc..0fad53627a 100644 --- a/bittensor/core/extrinsics/serving.py +++ b/bittensor/core/extrinsics/serving.py @@ -233,6 +233,7 @@ def publish_metadata( wait_for_inclusion: bool = False, wait_for_finalization: bool = True, period: Optional[int] = None, + reset_bonds: bool = False, ) -> bool: """ Publishes metadata on the Bittensor network using the specified wallet and network identifier. @@ -253,6 +254,7 @@ def publish_metadata( period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If the transaction is not included in a block within that number of blocks, it will expire and be rejected. You can think of it as an expiration date for the transaction. + reset_bonds (bool, optional): If ``True``, the function will reset the bonds for the neuron. Defaults to ``False``. Returns: bool: ``True`` if the metadata was successfully published (and finalized if specified). ``False`` otherwise. @@ -266,12 +268,16 @@ def publish_metadata( logging.error(unlock.message) return False + fields = [{f"{data_type}": data}] + if reset_bonds: + fields.append({"ResetBondsFlag": b""}) + call = subtensor.substrate.compose_call( call_module="Commitments", call_function="set_commitment", call_params={ "netuid": netuid, - "info": {"fields": [[{f"{data_type}": data}]]}, + "info": {"fields": [fields]}, }, ) From a614c21bacb60e3c0213d8be16b67cee6a76baef Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Fri, 4 Apr 2025 21:05:13 +0100 Subject: [PATCH 02/20] add get_last_commitment_bonds_reset_block --- bittensor/core/extrinsics/serving.py | 13 +++++++++++++ bittensor/core/subtensor.py | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/bittensor/core/extrinsics/serving.py b/bittensor/core/extrinsics/serving.py index 0fad53627a..e2d1e71c75 100644 --- a/bittensor/core/extrinsics/serving.py +++ b/bittensor/core/extrinsics/serving.py @@ -306,3 +306,16 @@ def get_metadata( block_hash=subtensor.determine_block_hash(block), ) return commit_data + + +def get_last_bonds_reset( + subtensor: "Subtensor", netuid: int, hotkey: str, block: Optional[int] = None +) -> bytes: + """Fetches the last bonds reset triggered at commitment from the blockchain for a given hotkey and netuid.""" + block = subtensor.substrate.query( + module="Commitments", + storage_function="LastBondsReset", + params=[netuid, hotkey], + block_hash=subtensor.determine_block_hash(block), + ) + return block diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index a612793f5a..b761a3ce69 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -57,6 +57,7 @@ set_root_weights_extrinsic, ) from bittensor.core.extrinsics.serving import ( + get_last_bonds_reset, publish_metadata, get_metadata, serve_axon_extrinsic, @@ -891,6 +892,29 @@ def get_commitment(self, netuid: int, uid: int, block: Optional[int] = None) -> except TypeError: return "" + def get_last_commitment_bonds_reset_block( + self, netuid: int, uid: int + ) -> Optional[int]: + """ + Retrieves the last block number when the bonds reset were triggered by publish_metadata for a specific neuron. + Arguments: + netuid (int): The unique identifier of the subnetwork. + uid (int): The unique identifier of the neuron. + Returns: + Optional[int]: The block number when the bonds were last reset, or None if not found. + """ + + metagraph = self.metagraph(netuid) + try: + hotkey = metagraph.hotkeys[uid] # type: ignore + except IndexError: + logging.error( + "Your uid is not in the hotkeys. Please double-check your UID." + ) + return None + block = get_last_bonds_reset(self, netuid, hotkey) + return block.value + def get_all_commitments( self, netuid: int, block: Optional[int] = None ) -> dict[str, str]: From b6519607aaa03ccaee66366c887aa6a1e26c5c7b Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 3 Jun 2025 07:36:07 +0100 Subject: [PATCH 03/20] rebase and fix --- bittensor/core/chain_data/utils.py | 12 ++++++++++++ bittensor/core/subtensor.py | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bittensor/core/chain_data/utils.py b/bittensor/core/chain_data/utils.py index 9915b51c1f..272cbca1b9 100644 --- a/bittensor/core/chain_data/utils.py +++ b/bittensor/core/chain_data/utils.py @@ -140,6 +140,18 @@ def decode_metadata(metadata: dict) -> str: return bytes(bytes_tuple).decode() +def decode_block(data: bytes) -> int: + """ + Decode the block data from the given input if it is not None. + Arguments: + data (bytes): The block data to decode. + Returns: + int: The decoded block. + """ + + return int.from_bytes(block) + + def decode_revealed_commitment(encoded_data) -> tuple[int, str]: """ Decode the revealed commitment data from the given input if it is not None. diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index b761a3ce69..b28ad5e74f 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -30,6 +30,7 @@ ) from bittensor.core.chain_data.chain_identity import ChainIdentity from bittensor.core.chain_data.utils import ( + decode_block, decode_metadata, decode_revealed_commitment, decode_revealed_commitment_with_hotkey, @@ -913,7 +914,9 @@ def get_last_commitment_bonds_reset_block( ) return None block = get_last_bonds_reset(self, netuid, hotkey) - return block.value + if block is None: + return None + return decode_block(block) def get_all_commitments( self, netuid: int, block: Optional[int] = None From 0ffe5b9838fbc6a155df6c1a46ca63ddc8ada047 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Tue, 3 Jun 2025 14:49:50 +0100 Subject: [PATCH 04/20] tests --- bittensor/core/async_subtensor.py | 27 ++++++++++++++++++++ bittensor/core/chain_data/utils.py | 3 +-- bittensor/core/extrinsics/asyncex/serving.py | 18 +++++++++++++ bittensor/core/subtensor_api/commitments.py | 3 +++ bittensor/core/subtensor_api/utils.py | 3 +++ tests/unit_tests/test_subtensor.py | 27 ++++++++++++++++++++ 6 files changed, 79 insertions(+), 2 deletions(-) diff --git a/bittensor/core/async_subtensor.py b/bittensor/core/async_subtensor.py index 77ec7afd47..f3b044f838 100644 --- a/bittensor/core/async_subtensor.py +++ b/bittensor/core/async_subtensor.py @@ -32,6 +32,7 @@ from bittensor.core.chain_data.chain_identity import ChainIdentity from bittensor.core.chain_data.delegate_info import DelegatedInfo from bittensor.core.chain_data.utils import ( + decode_block, decode_metadata, decode_revealed_commitment, decode_revealed_commitment_with_hotkey, @@ -55,6 +56,7 @@ root_register_extrinsic, ) from bittensor.core.extrinsics.asyncex.serving import ( + get_last_bonds_reset, publish_metadata, get_metadata, ) @@ -1152,6 +1154,31 @@ async def get_commitment( except TypeError: return "" + async def get_last_commitment_bonds_reset_block( + self, netuid: int, uid: int + ) -> Optional[int]: + """ + Retrieves the last block number when the bonds reset were triggered by publish_metadata for a specific neuron. + Arguments: + netuid (int): The unique identifier of the subnetwork. + uid (int): The unique identifier of the neuron. + Returns: + Optional[int]: The block number when the bonds were last reset, or None if not found. + """ + + metagraph = await self.metagraph(netuid) + try: + hotkey = metagraph.hotkeys[uid] # type: ignore + except IndexError: + logging.error( + "Your uid is not in the hotkeys. Please double-check your UID." + ) + return None + block = await get_last_bonds_reset(self, netuid, hotkey) + if block is None: + return None + return await decode_block(block) + async def get_all_commitments( self, netuid: int, diff --git a/bittensor/core/chain_data/utils.py b/bittensor/core/chain_data/utils.py index 272cbca1b9..235365ffcd 100644 --- a/bittensor/core/chain_data/utils.py +++ b/bittensor/core/chain_data/utils.py @@ -148,8 +148,7 @@ def decode_block(data: bytes) -> int: Returns: int: The decoded block. """ - - return int.from_bytes(block) + return int(data.value) if isinstance(data, ScaleBytes) else data def decode_revealed_commitment(encoded_data) -> tuple[int, str]: diff --git a/bittensor/core/extrinsics/asyncex/serving.py b/bittensor/core/extrinsics/asyncex/serving.py index 92fa8c6dd9..2ac0d47411 100644 --- a/bittensor/core/extrinsics/asyncex/serving.py +++ b/bittensor/core/extrinsics/asyncex/serving.py @@ -320,3 +320,21 @@ async def get_metadata( reuse_block_hash=reuse_block, ) return commit_data + + +async def get_last_bonds_reset( + subtensor: "AsyncSubtensor", + netuid: int, + hotkey: str, + block: Optional[int] = None, +) -> bytes: + """Fetches the last bonds reset triggered at commitment from the blockchain for a given hotkey and netuid.""" + async with subtensor.substrate: + block_hash = await subtensor.determine_block_hash(block) + block = subtensor.substrate.query( + module="Commitments", + storage_function="LastBondsReset", + params=[netuid, hotkey], + block_hash=block_hash, + ) + return block diff --git a/bittensor/core/subtensor_api/commitments.py b/bittensor/core/subtensor_api/commitments.py index 2e594ba6db..cce99d7bb6 100644 --- a/bittensor/core/subtensor_api/commitments.py +++ b/bittensor/core/subtensor_api/commitments.py @@ -11,6 +11,9 @@ def __init__(self, subtensor: Union["_Subtensor", "_AsyncSubtensor"]): self.get_all_commitments = subtensor.get_all_commitments self.get_all_revealed_commitments = subtensor.get_all_revealed_commitments self.get_commitment = subtensor.get_commitment + self.get_last_commitment_bonds_reset_block = ( + subtensor.get_last_commitment_bonds_reset_block + ) self.get_current_weight_commit_info = subtensor.get_current_weight_commit_info self.get_revealed_commitment = subtensor.get_revealed_commitment self.get_revealed_commitment_by_hotkey = ( diff --git a/bittensor/core/subtensor_api/utils.py b/bittensor/core/subtensor_api/utils.py index 0ddd28bcc7..1b5470ae31 100644 --- a/bittensor/core/subtensor_api/utils.py +++ b/bittensor/core/subtensor_api/utils.py @@ -40,6 +40,9 @@ def add_legacy_methods(subtensor: "SubtensorApi"): subtensor.get_children = subtensor._subtensor.get_children subtensor.get_children_pending = subtensor._subtensor.get_children_pending subtensor.get_commitment = subtensor._subtensor.get_commitment + subtensor.get_last_commitment_bonds_reset_block = ( + subtensor._subtensor.get_last_commitment_bonds_reset_block + ) subtensor.get_current_block = subtensor._subtensor.get_current_block subtensor.get_current_weight_commit_info = ( subtensor._subtensor.get_current_weight_commit_info diff --git a/tests/unit_tests/test_subtensor.py b/tests/unit_tests/test_subtensor.py index 11fa933425..21480f533c 100644 --- a/tests/unit_tests/test_subtensor.py +++ b/tests/unit_tests/test_subtensor.py @@ -1813,6 +1813,33 @@ def test_get_commitment(subtensor, mocker): assert result == expected_result +def test_get_last_commitment_bonds_reset_block(subtensor, mocker): + """Successful get_last_commitment_bonds_reset_block call.""" + # Preps + fake_netuid = 1 + fake_uid = 2 + fake_hotkey = "hotkey" + expected_result = 3 + + mocked_get_last_bonds_reset = mocker.patch.object( + subtensor_module, "get_last_bonds_reset" + ) + mocked_get_last_bonds_reset.return_value = expected_result + + mocked_metagraph = mocker.MagicMock() + subtensor.metagraph = mocked_metagraph + mocked_metagraph.return_value.hotkeys = {fake_uid: fake_hotkey} + + # Call + result = subtensor.get_last_commitment_bonds_reset_block( + netuid=fake_netuid, uid=fake_uid + ) + + # Assertions + mocked_get_last_bonds_reset.assert_called_once() + assert result == expected_result + + def test_min_allowed_weights(subtensor, mocker): """Successful min_allowed_weights call.""" fake_netuid = 1 From 34d157ac099604f884509a5dc914347154b97001 Mon Sep 17 00:00:00 2001 From: andreea-popescu-reef <160024917+andreea-popescu-reef@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:30:08 +0800 Subject: [PATCH 05/20] Update bittensor/core/extrinsics/asyncex/serving.py Co-authored-by: BD Himes <37844818+thewhaleking@users.noreply.github.com> --- bittensor/core/extrinsics/asyncex/serving.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/core/extrinsics/asyncex/serving.py b/bittensor/core/extrinsics/asyncex/serving.py index 2ac0d47411..b1469ed869 100644 --- a/bittensor/core/extrinsics/asyncex/serving.py +++ b/bittensor/core/extrinsics/asyncex/serving.py @@ -257,7 +257,7 @@ async def publish_metadata( period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If the transaction is not included in a block within that number of blocks, it will expire and be rejected. You can think of it as an expiration date for the transaction. - reset_bonds (bool, optional): If ``True``, the function will reset the bonds for the neuron. Defaults to ``False``. + reset_bonds (bool): If ``True``, the function will reset the bonds for the neuron. Defaults to ``False``. Returns: bool: ``True`` if the metadata was successfully published (and finalized if specified). ``False`` otherwise. From 6ae9f9e5ebe88512d1a98100f2e026d4c0c9dcec Mon Sep 17 00:00:00 2001 From: andreea-popescu-reef <160024917+andreea-popescu-reef@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:30:16 +0800 Subject: [PATCH 06/20] Update bittensor/core/extrinsics/serving.py Co-authored-by: BD Himes <37844818+thewhaleking@users.noreply.github.com> --- bittensor/core/extrinsics/serving.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/core/extrinsics/serving.py b/bittensor/core/extrinsics/serving.py index e2d1e71c75..e88698e6cc 100644 --- a/bittensor/core/extrinsics/serving.py +++ b/bittensor/core/extrinsics/serving.py @@ -254,7 +254,7 @@ def publish_metadata( period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If the transaction is not included in a block within that number of blocks, it will expire and be rejected. You can think of it as an expiration date for the transaction. - reset_bonds (bool, optional): If ``True``, the function will reset the bonds for the neuron. Defaults to ``False``. + reset_bonds (bool): If ``True``, the function will reset the bonds for the neuron. Defaults to ``False``. Returns: bool: ``True`` if the metadata was successfully published (and finalized if specified). ``False`` otherwise. From d3bcaddae7d17d2d6c33e76f24a133bab9924865 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Mon, 16 Jun 2025 07:43:43 +0100 Subject: [PATCH 07/20] fix async reset_bonds --- bittensor/core/async_subtensor.py | 7 ++++--- bittensor/core/chain_data/utils.py | 3 ++- bittensor/core/extrinsics/asyncex/serving.py | 17 +++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/bittensor/core/async_subtensor.py b/bittensor/core/async_subtensor.py index f3b044f838..d101b8a5bd 100644 --- a/bittensor/core/async_subtensor.py +++ b/bittensor/core/async_subtensor.py @@ -1175,9 +1175,10 @@ async def get_last_commitment_bonds_reset_block( ) return None block = await get_last_bonds_reset(self, netuid, hotkey) - if block is None: - return None - return await decode_block(block) + try: + return decode_block(block) + except TypeError: + return "" async def get_all_commitments( self, diff --git a/bittensor/core/chain_data/utils.py b/bittensor/core/chain_data/utils.py index 235365ffcd..c7c83e2569 100644 --- a/bittensor/core/chain_data/utils.py +++ b/bittensor/core/chain_data/utils.py @@ -4,6 +4,7 @@ from typing import Optional, Union, TYPE_CHECKING from scalecodec.base import RuntimeConfiguration, ScaleBytes +from async_substrate_interface.types import ScaleObj from scalecodec.type_registry import load_type_registry_preset from scalecodec.utils.ss58 import ss58_encode @@ -148,7 +149,7 @@ def decode_block(data: bytes) -> int: Returns: int: The decoded block. """ - return int(data.value) if isinstance(data, ScaleBytes) else data + return int(data.value) if isinstance(data, ScaleObj) else data def decode_revealed_commitment(encoded_data) -> tuple[int, str]: diff --git a/bittensor/core/extrinsics/asyncex/serving.py b/bittensor/core/extrinsics/asyncex/serving.py index b1469ed869..924cfbb858 100644 --- a/bittensor/core/extrinsics/asyncex/serving.py +++ b/bittensor/core/extrinsics/asyncex/serving.py @@ -327,14 +327,15 @@ async def get_last_bonds_reset( netuid: int, hotkey: str, block: Optional[int] = None, + block_hash: Optional[str] = None, + reuse_block: bool = False, ) -> bytes: """Fetches the last bonds reset triggered at commitment from the blockchain for a given hotkey and netuid.""" - async with subtensor.substrate: - block_hash = await subtensor.determine_block_hash(block) - block = subtensor.substrate.query( - module="Commitments", - storage_function="LastBondsReset", - params=[netuid, hotkey], - block_hash=block_hash, - ) + block_hash = await subtensor.determine_block_hash(block, block_hash, reuse_block) + block = await subtensor.substrate.query( + module="Commitments", + storage_function="LastBondsReset", + params=[netuid, hotkey], + block_hash=block_hash, + ) return block From 8f3e366205c10cfc4b9f23041811db9cf11ee2e0 Mon Sep 17 00:00:00 2001 From: andreea-popescu-reef <160024917+andreea-popescu-reef@users.noreply.github.com> Date: Wed, 18 Jun 2025 17:48:01 +0800 Subject: [PATCH 08/20] Update bittensor/core/extrinsics/serving.py Co-authored-by: Roman <167799377+basfroman@users.noreply.github.com> --- bittensor/core/extrinsics/serving.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bittensor/core/extrinsics/serving.py b/bittensor/core/extrinsics/serving.py index e88698e6cc..f1b1113f1b 100644 --- a/bittensor/core/extrinsics/serving.py +++ b/bittensor/core/extrinsics/serving.py @@ -312,10 +312,9 @@ def get_last_bonds_reset( subtensor: "Subtensor", netuid: int, hotkey: str, block: Optional[int] = None ) -> bytes: """Fetches the last bonds reset triggered at commitment from the blockchain for a given hotkey and netuid.""" - block = subtensor.substrate.query( + return subtensor.substrate.query( module="Commitments", storage_function="LastBondsReset", params=[netuid, hotkey], block_hash=subtensor.determine_block_hash(block), ) - return block From 1b36211b18897b7bdca1a18e9395cdd8e2c04146 Mon Sep 17 00:00:00 2001 From: andreea-popescu-reef <160024917+andreea-popescu-reef@users.noreply.github.com> Date: Wed, 18 Jun 2025 17:48:37 +0800 Subject: [PATCH 09/20] Update bittensor/core/subtensor_api/commitments.py Co-authored-by: Roman <167799377+basfroman@users.noreply.github.com> --- bittensor/core/subtensor_api/commitments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/core/subtensor_api/commitments.py b/bittensor/core/subtensor_api/commitments.py index cce99d7bb6..6bdbb7f9f3 100644 --- a/bittensor/core/subtensor_api/commitments.py +++ b/bittensor/core/subtensor_api/commitments.py @@ -11,10 +11,10 @@ def __init__(self, subtensor: Union["_Subtensor", "_AsyncSubtensor"]): self.get_all_commitments = subtensor.get_all_commitments self.get_all_revealed_commitments = subtensor.get_all_revealed_commitments self.get_commitment = subtensor.get_commitment + self.get_current_weight_commit_info = subtensor.get_current_weight_commit_info self.get_last_commitment_bonds_reset_block = ( subtensor.get_last_commitment_bonds_reset_block ) - self.get_current_weight_commit_info = subtensor.get_current_weight_commit_info self.get_revealed_commitment = subtensor.get_revealed_commitment self.get_revealed_commitment_by_hotkey = ( subtensor.get_revealed_commitment_by_hotkey From 0b07bafec507428065a3c9d129551dbe5a726de5 Mon Sep 17 00:00:00 2001 From: andreea-popescu-reef <160024917+andreea-popescu-reef@users.noreply.github.com> Date: Wed, 18 Jun 2025 17:48:54 +0800 Subject: [PATCH 10/20] Update bittensor/core/subtensor_api/utils.py Co-authored-by: Roman <167799377+basfroman@users.noreply.github.com> --- bittensor/core/subtensor_api/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/core/subtensor_api/utils.py b/bittensor/core/subtensor_api/utils.py index 1b5470ae31..dc01a8ae64 100644 --- a/bittensor/core/subtensor_api/utils.py +++ b/bittensor/core/subtensor_api/utils.py @@ -40,10 +40,10 @@ def add_legacy_methods(subtensor: "SubtensorApi"): subtensor.get_children = subtensor._subtensor.get_children subtensor.get_children_pending = subtensor._subtensor.get_children_pending subtensor.get_commitment = subtensor._subtensor.get_commitment + subtensor.get_current_block = subtensor._subtensor.get_current_block subtensor.get_last_commitment_bonds_reset_block = ( subtensor._subtensor.get_last_commitment_bonds_reset_block ) - subtensor.get_current_block = subtensor._subtensor.get_current_block subtensor.get_current_weight_commit_info = ( subtensor._subtensor.get_current_weight_commit_info ) From dbe6ae6407e72205b2d73598a3106553b4a57264 Mon Sep 17 00:00:00 2001 From: andreea-popescu-reef <160024917+andreea-popescu-reef@users.noreply.github.com> Date: Wed, 18 Jun 2025 17:49:20 +0800 Subject: [PATCH 11/20] Update bittensor/core/subtensor.py Co-authored-by: Roman <167799377+basfroman@users.noreply.github.com> --- bittensor/core/subtensor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index b28ad5e74f..b5bba2cd06 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -898,9 +898,11 @@ def get_last_commitment_bonds_reset_block( ) -> Optional[int]: """ Retrieves the last block number when the bonds reset were triggered by publish_metadata for a specific neuron. + Arguments: netuid (int): The unique identifier of the subnetwork. uid (int): The unique identifier of the neuron. + Returns: Optional[int]: The block number when the bonds were last reset, or None if not found. """ From 8f6a3f767f6411986464d0f86c402df712df8133 Mon Sep 17 00:00:00 2001 From: andreea-popescu-reef <160024917+andreea-popescu-reef@users.noreply.github.com> Date: Wed, 18 Jun 2025 17:49:28 +0800 Subject: [PATCH 12/20] Update bittensor/core/subtensor.py Co-authored-by: Roman <167799377+basfroman@users.noreply.github.com> --- bittensor/core/subtensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index b5bba2cd06..8c17457198 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -909,7 +909,7 @@ def get_last_commitment_bonds_reset_block( metagraph = self.metagraph(netuid) try: - hotkey = metagraph.hotkeys[uid] # type: ignore + hotkey = metagraph.hotkeys[uid] except IndexError: logging.error( "Your uid is not in the hotkeys. Please double-check your UID." From 80957e419a9b8057fe39419054b92ad53130790d Mon Sep 17 00:00:00 2001 From: andreea-popescu-reef <160024917+andreea-popescu-reef@users.noreply.github.com> Date: Wed, 18 Jun 2025 17:49:44 +0800 Subject: [PATCH 13/20] Update bittensor/core/extrinsics/serving.py Co-authored-by: Roman <167799377+basfroman@users.noreply.github.com> --- bittensor/core/extrinsics/serving.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/core/extrinsics/serving.py b/bittensor/core/extrinsics/serving.py index f1b1113f1b..f80ddaf749 100644 --- a/bittensor/core/extrinsics/serving.py +++ b/bittensor/core/extrinsics/serving.py @@ -254,7 +254,7 @@ def publish_metadata( period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If the transaction is not included in a block within that number of blocks, it will expire and be rejected. You can think of it as an expiration date for the transaction. - reset_bonds (bool): If ``True``, the function will reset the bonds for the neuron. Defaults to ``False``. + reset_bonds (bool): If `True`, the function will reset the bonds for the neuron. Defaults to `False`. Returns: bool: ``True`` if the metadata was successfully published (and finalized if specified). ``False`` otherwise. From 7bb2df112606a8517bd201ad822e3a3f90586db3 Mon Sep 17 00:00:00 2001 From: andreea-popescu-reef <160024917+andreea-popescu-reef@users.noreply.github.com> Date: Wed, 18 Jun 2025 17:49:55 +0800 Subject: [PATCH 14/20] Update bittensor/core/async_subtensor.py Co-authored-by: Roman <167799377+basfroman@users.noreply.github.com> --- bittensor/core/async_subtensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/core/async_subtensor.py b/bittensor/core/async_subtensor.py index d101b8a5bd..53a4ca2a3b 100644 --- a/bittensor/core/async_subtensor.py +++ b/bittensor/core/async_subtensor.py @@ -1168,7 +1168,7 @@ async def get_last_commitment_bonds_reset_block( metagraph = await self.metagraph(netuid) try: - hotkey = metagraph.hotkeys[uid] # type: ignore + hotkey = metagraph.hotkeys[uid] except IndexError: logging.error( "Your uid is not in the hotkeys. Please double-check your UID." From 0b473933a3a282879b59ac8ab11eee66ad64f170 Mon Sep 17 00:00:00 2001 From: andreea-popescu-reef <160024917+andreea-popescu-reef@users.noreply.github.com> Date: Wed, 18 Jun 2025 17:50:08 +0800 Subject: [PATCH 15/20] Update bittensor/core/chain_data/utils.py Co-authored-by: Roman <167799377+basfroman@users.noreply.github.com> --- bittensor/core/chain_data/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bittensor/core/chain_data/utils.py b/bittensor/core/chain_data/utils.py index c7c83e2569..95d4eb21f0 100644 --- a/bittensor/core/chain_data/utils.py +++ b/bittensor/core/chain_data/utils.py @@ -144,8 +144,10 @@ def decode_metadata(metadata: dict) -> str: def decode_block(data: bytes) -> int: """ Decode the block data from the given input if it is not None. + Arguments: data (bytes): The block data to decode. + Returns: int: The decoded block. """ From ca3c9f4c41d059d91d23fe3f1f4f6dbfe744e36d Mon Sep 17 00:00:00 2001 From: andreea-popescu-reef <160024917+andreea-popescu-reef@users.noreply.github.com> Date: Wed, 18 Jun 2025 17:50:17 +0800 Subject: [PATCH 16/20] Update bittensor/core/extrinsics/asyncex/serving.py Co-authored-by: Roman <167799377+basfroman@users.noreply.github.com> --- bittensor/core/extrinsics/asyncex/serving.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/core/extrinsics/asyncex/serving.py b/bittensor/core/extrinsics/asyncex/serving.py index 924cfbb858..5fa46554d0 100644 --- a/bittensor/core/extrinsics/asyncex/serving.py +++ b/bittensor/core/extrinsics/asyncex/serving.py @@ -257,7 +257,7 @@ async def publish_metadata( period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If the transaction is not included in a block within that number of blocks, it will expire and be rejected. You can think of it as an expiration date for the transaction. - reset_bonds (bool): If ``True``, the function will reset the bonds for the neuron. Defaults to ``False``. + reset_bonds (bool): If `True`, the function will reset the bonds for the neuron. Defaults to `False`. Returns: bool: ``True`` if the metadata was successfully published (and finalized if specified). ``False`` otherwise. From bf9c0e1e9192a778204933b3eb6c38e90b8bb47a Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 18 Jun 2025 10:58:34 +0100 Subject: [PATCH 17/20] better docstring --- bittensor/core/extrinsics/serving.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bittensor/core/extrinsics/serving.py b/bittensor/core/extrinsics/serving.py index f80ddaf749..09903d763e 100644 --- a/bittensor/core/extrinsics/serving.py +++ b/bittensor/core/extrinsics/serving.py @@ -311,7 +311,18 @@ def get_metadata( def get_last_bonds_reset( subtensor: "Subtensor", netuid: int, hotkey: str, block: Optional[int] = None ) -> bytes: - """Fetches the last bonds reset triggered at commitment from the blockchain for a given hotkey and netuid.""" + """ + Fetches the last bonds reset triggered at commitment from the blockchain for a given hotkey and netuid. + + Args: + subtensor (bittensor.core.subtensor.Subtensor): Subtensor instance object. + netuid (int): The network uid to fetch from. + hotkey (str): The hotkey of the neuron for which to fetch the last bonds reset. + block (Optional[int]): The block number to query. If ``None``, the latest block is used. + + Returns: + bytes: The last bonds reset data for the specified hotkey and netuid. + """ return subtensor.substrate.query( module="Commitments", storage_function="LastBondsReset", From 77d73cf312a779804bb0bb635a631fefc87ad628 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 18 Jun 2025 11:03:14 +0100 Subject: [PATCH 18/20] ruff --- bittensor/core/chain_data/utils.py | 4 ++-- bittensor/core/subtensor_api/utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bittensor/core/chain_data/utils.py b/bittensor/core/chain_data/utils.py index 95d4eb21f0..58e35bba34 100644 --- a/bittensor/core/chain_data/utils.py +++ b/bittensor/core/chain_data/utils.py @@ -144,10 +144,10 @@ def decode_metadata(metadata: dict) -> str: def decode_block(data: bytes) -> int: """ Decode the block data from the given input if it is not None. - + Arguments: data (bytes): The block data to decode. - + Returns: int: The decoded block. """ diff --git a/bittensor/core/subtensor_api/utils.py b/bittensor/core/subtensor_api/utils.py index dc01a8ae64..a6cb401d09 100644 --- a/bittensor/core/subtensor_api/utils.py +++ b/bittensor/core/subtensor_api/utils.py @@ -40,7 +40,7 @@ def add_legacy_methods(subtensor: "SubtensorApi"): subtensor.get_children = subtensor._subtensor.get_children subtensor.get_children_pending = subtensor._subtensor.get_children_pending subtensor.get_commitment = subtensor._subtensor.get_commitment - subtensor.get_current_block = subtensor._subtensor.get_current_block + subtensor.get_current_block = subtensor._subtensor.get_current_block subtensor.get_last_commitment_bonds_reset_block = ( subtensor._subtensor.get_last_commitment_bonds_reset_block ) From 79318aa1a4f8ed290aeaa002a0cfe211e29135d8 Mon Sep 17 00:00:00 2001 From: zyzniewski-reef Date: Fri, 27 Jun 2025 08:31:39 +0200 Subject: [PATCH 19/20] Update bittensor/core/async_subtensor.py Co-authored-by: Roman <167799377+basfroman@users.noreply.github.com> --- bittensor/core/async_subtensor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bittensor/core/async_subtensor.py b/bittensor/core/async_subtensor.py index 53a4ca2a3b..6a199844f7 100644 --- a/bittensor/core/async_subtensor.py +++ b/bittensor/core/async_subtensor.py @@ -1159,9 +1159,11 @@ async def get_last_commitment_bonds_reset_block( ) -> Optional[int]: """ Retrieves the last block number when the bonds reset were triggered by publish_metadata for a specific neuron. + Arguments: netuid (int): The unique identifier of the subnetwork. uid (int): The unique identifier of the neuron. + Returns: Optional[int]: The block number when the bonds were last reset, or None if not found. """ From a78a0381cd9cc9789a862b88b636d644b0bcbed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBy=C5=BAniewski?= Date: Fri, 27 Jun 2025 09:31:37 +0200 Subject: [PATCH 20/20] ruff --- bittensor/core/async_subtensor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bittensor/core/async_subtensor.py b/bittensor/core/async_subtensor.py index bdb3c71f82..0c42aebd8a 100644 --- a/bittensor/core/async_subtensor.py +++ b/bittensor/core/async_subtensor.py @@ -1178,11 +1178,11 @@ async def get_last_commitment_bonds_reset_block( ) -> Optional[int]: """ Retrieves the last block number when the bonds reset were triggered by publish_metadata for a specific neuron. - + Arguments: netuid (int): The unique identifier of the subnetwork. uid (int): The unique identifier of the neuron. - + Returns: Optional[int]: The block number when the bonds were last reset, or None if not found. """