Skip to content

Commit d3bcadd

Browse files
fix async reset_bonds
1 parent 6ae9f9e commit d3bcadd

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

bittensor/core/async_subtensor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,9 +1175,10 @@ async def get_last_commitment_bonds_reset_block(
11751175
)
11761176
return None
11771177
block = await get_last_bonds_reset(self, netuid, hotkey)
1178-
if block is None:
1179-
return None
1180-
return await decode_block(block)
1178+
try:
1179+
return decode_block(block)
1180+
except TypeError:
1181+
return ""
11811182

11821183
async def get_all_commitments(
11831184
self,

bittensor/core/chain_data/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Optional, Union, TYPE_CHECKING
55

66
from scalecodec.base import RuntimeConfiguration, ScaleBytes
7+
from async_substrate_interface.types import ScaleObj
78
from scalecodec.type_registry import load_type_registry_preset
89
from scalecodec.utils.ss58 import ss58_encode
910

@@ -148,7 +149,7 @@ def decode_block(data: bytes) -> int:
148149
Returns:
149150
int: The decoded block.
150151
"""
151-
return int(data.value) if isinstance(data, ScaleBytes) else data
152+
return int(data.value) if isinstance(data, ScaleObj) else data
152153

153154

154155
def decode_revealed_commitment(encoded_data) -> tuple[int, str]:

bittensor/core/extrinsics/asyncex/serving.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,15 @@ async def get_last_bonds_reset(
327327
netuid: int,
328328
hotkey: str,
329329
block: Optional[int] = None,
330+
block_hash: Optional[str] = None,
331+
reuse_block: bool = False,
330332
) -> bytes:
331333
"""Fetches the last bonds reset triggered at commitment from the blockchain for a given hotkey and netuid."""
332-
async with subtensor.substrate:
333-
block_hash = await subtensor.determine_block_hash(block)
334-
block = subtensor.substrate.query(
335-
module="Commitments",
336-
storage_function="LastBondsReset",
337-
params=[netuid, hotkey],
338-
block_hash=block_hash,
339-
)
334+
block_hash = await subtensor.determine_block_hash(block, block_hash, reuse_block)
335+
block = await subtensor.substrate.query(
336+
module="Commitments",
337+
storage_function="LastBondsReset",
338+
params=[netuid, hotkey],
339+
block_hash=block_hash,
340+
)
340341
return block

0 commit comments

Comments
 (0)