Skip to content

Commit 25767c2

Browse files
authored
Merge branch 'staging' into feat/thewhaleking/pyproject-toml
2 parents f977d58 + 560bf29 commit 25767c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2720
-438
lines changed

CHANGELOG.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,84 @@
11
# Changelog
22

3+
## 8.5.1 /2024-12-16
4+
5+
## What's Changed
6+
* 8.5.0 bugfixes by @thewhaleking in https://github.com/opentensor/bittensor/pull/2541
7+
* Removes substrate call in format_error_message by @thewhaleking in https://github.com/opentensor/bittensor/pull/2542
8+
* Remove torch from the weights calls by @thewhaleking in https://github.com/opentensor/bittensor/pull/2543
9+
* optional arg fix by @thewhaleking in https://github.com/opentensor/bittensor/pull/2544
10+
* async cr3 not implemented by @thewhaleking in https://github.com/opentensor/bittensor/pull/2545
11+
* Backmerge master to staging 851 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2546
12+
* Adds retry in CRv3 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2547
13+
14+
**Full Changelog**: https://github.com/opentensor/bittensor/compare/v8.5.0...v8.5.1
15+
16+
## 8.5.0 /2024-12-12
17+
18+
## What's Changed
19+
* add improved reveal-round params by @JohnReedV in https://github.com/opentensor/bittensor/pull/2509
20+
* fix: add default value to the get_block_number method in AsyncSubstrateInterface by @FLiotta in https://github.com/opentensor/bittensor/pull/2529
21+
* Mismatched "archive" index by @thewhaleking in https://github.com/opentensor/bittensor/pull/2530
22+
* Adds a factory function to create an initialised AsyncSubtensor object. by @thewhaleking in https://github.com/opentensor/bittensor/pull/2516
23+
* chore: fix some comments by @lvyaoting in https://github.com/opentensor/bittensor/pull/2515
24+
* Fixes E2E test chain buffer issues on devnet by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2531
25+
* Added e2e test for CRv3 + enhancements by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2532
26+
* Backmerge master to staging 850 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2535
27+
* Enhancement/adds total stake functions by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2537
28+
* Fixes get_current_block by @thewhaleking in https://github.com/opentensor/bittensor/pull/2536
29+
* [SDK] Add `commit reveal v3` logic (python part only) by @roman-opentensor in https://github.com/opentensor/bittensor/pull/2484
30+
31+
## New Contributors
32+
* @JohnReedV made their first contribution in https://github.com/opentensor/bittensor/pull/2509
33+
* @FLiotta made their first contribution in https://github.com/opentensor/bittensor/pull/2529
34+
* @lvyaoting made their first contribution in https://github.com/opentensor/bittensor/pull/2515
35+
36+
**Full Changelog**: https://github.com/opentensor/bittensor/compare/v8.4.5...v8.5.0
37+
38+
## 8.4.5 /2024-12-05
39+
40+
## What's Changed
41+
* Overrides copy and deep copy for the metagraph by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2523
42+
43+
**Full Changelog**: https://github.com/opentensor/bittensor/compare/v8.4.4...v8.4.5
44+
45+
## 8.4.4 /2024-12-05
46+
47+
## What's Changed
48+
* Removes the call that automatically sets everything to warning level debugging by @thewhaleking in https://github.com/opentensor/bittensor/pull/2508
49+
* Exit `set_weights` on success by @thewhaleking in https://github.com/opentensor/bittensor/pull/2511
50+
* `test_dendrite` test clean up by @thewhaleking in https://github.com/opentensor/bittensor/pull/2512
51+
* Adds --logging.info level so it can be set @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2510
52+
* Allows wallet to be created through configs in the axon if it is provided by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2510
53+
* Changes verbosity level of ClientConnectorError and TimeoutError in the dendrite to debug by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2510
54+
* Fixes behaviour of config initialization for axon, subtensor, logging and threadpool by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2510
55+
* metagraph sync fix by @thewhaleking in https://github.com/opentensor/bittensor/pull/2514
56+
* Remove metadata retrieval of custom errors from format_error_message by @thewhaleking in https://github.com/opentensor/bittensor/pull/2518
57+
* Backmerge master to staging for 8.4.4 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2519
58+
* Updates bt-decode to 0.4.0 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2520
59+
60+
**Full Changelog**: https://github.com/opentensor/bittensor/compare/v8.4.3...v8.4.4
61+
62+
## 8.4.3 /2024-12-02
63+
64+
## What's Changed
65+
66+
* Fix logging config parsing by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2500
67+
* Improve `submit_extrinsic` util by @thewhaleking in https://github.com/opentensor/bittensor/pull/2502
68+
* Backmerge master to staging for 843 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2505
69+
* WS ensure_connected socket catch by @thewhaleking in https://github.com/opentensor/bittensor/pull/2507
70+
71+
**Full Changelog**: https://github.com/opentensor/bittensor/compare/v8.4.2...v8.4.3
72+
73+
## 8.4.2 /2024-11-28
74+
75+
## What's Changed
76+
77+
* Fix submit_extrinsic timeout by @thewhaleking in https://github.com/opentensor/bittensor/pull/2497
78+
* Backmerge master to staging for 841 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2498
79+
80+
**Full Changelog**: https://github.com/opentensor/bittensor/compare/v8.4.1...v8.4.2
81+
382
## 8.4.1 /2024-11-27
483

584
## What's Changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.4.1
1+
8.5.1

bittensor/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@
1717

1818
import warnings
1919

20-
from .core.settings import __version__, version_split, DEFAULTS
20+
from .core.settings import __version__, version_split, DEFAULTS, DEFAULT_NETWORK
21+
from .core.async_subtensor import AsyncSubtensor
2122
from .utils.btlogging import logging
2223
from .utils.deprecated import *
2324

2425

26+
async def async_subtensor(network: str = DEFAULT_NETWORK) -> AsyncSubtensor:
27+
"""
28+
Creates an initialised AsyncSubtensor object.
29+
"""
30+
async with AsyncSubtensor(network=network) as subtensor_:
31+
return subtensor_
32+
33+
2534
def __getattr__(name):
2635
if name == "version_split":
2736
warnings.warn(

bittensor/core/async_subtensor.py

Lines changed: 83 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
SubnetHyperparameters,
2323
decode_account_id,
2424
)
25+
from bittensor.core.extrinsics.async_commit_reveal import commit_reveal_v3_extrinsic
2526
from bittensor.core.extrinsics.async_registration import register_extrinsic
2627
from bittensor.core.extrinsics.async_root import (
2728
set_root_weights_extrinsic,
@@ -236,7 +237,7 @@ async def get_current_block(self) -> int:
236237
237238
Knowing the current block number is essential for querying real-time data and performing time-sensitive operations on the blockchain. It serves as a reference point for network activities and data synchronization.
238239
"""
239-
return await self.substrate.get_block_number()
240+
return await self.substrate.get_block_number(None)
240241

241242
async def get_block_hash(self, block_id: Optional[int] = None):
242243
"""
@@ -1184,11 +1185,9 @@ async def sign_and_send_extrinsic(
11841185
if await response.is_success:
11851186
return True, ""
11861187
else:
1187-
return False, format_error_message(
1188-
await response.error_message, substrate=self.substrate
1189-
)
1188+
return False, format_error_message(await response.error_message)
11901189
except SubstrateRequestException as e:
1191-
return False, format_error_message(e, substrate=self.substrate)
1190+
return False, format_error_message(e)
11921191

11931192
async def get_children(self, hotkey: str, netuid: int) -> tuple[bool, list, str]:
11941193
"""
@@ -1218,7 +1217,7 @@ async def get_children(self, hotkey: str, netuid: int) -> tuple[bool, list, str]
12181217
else:
12191218
return True, [], ""
12201219
except SubstrateRequestException as e:
1221-
return False, [], format_error_message(e, self.substrate)
1220+
return False, [], format_error_message(e)
12221221

12231222
async def get_subnet_hyperparameters(
12241223
self, netuid: int, block_hash: Optional[str] = None, reuse_block: bool = False
@@ -1429,6 +1428,34 @@ async def blocks_since_last_update(self, netuid: int, uid: int) -> Optional[int]
14291428
call = await self.get_hyperparameter(param_name="LastUpdate", netuid=netuid)
14301429
return None if call is None else await self.get_current_block() - int(call[uid])
14311430

1431+
async def commit_reveal_enabled(
1432+
self, netuid: int, block_hash: Optional[str] = None
1433+
) -> bool:
1434+
"""
1435+
Check if commit-reveal mechanism is enabled for a given network at a specific block.
1436+
1437+
Arguments:
1438+
netuid (int): The network identifier for which to check the commit-reveal mechanism.
1439+
block_hash (Optional[str]): The block hash of block at which to check the parameter (default is None, which implies the current block).
1440+
1441+
Returns:
1442+
(bool): Returns the integer value of the hyperparameter if available; otherwise, returns None.
1443+
"""
1444+
call = await self.get_hyperparameter(
1445+
param_name="CommitRevealWeightsEnabled",
1446+
block_hash=block_hash,
1447+
netuid=netuid,
1448+
)
1449+
return True if call is True else False
1450+
1451+
async def get_subnet_reveal_period_epochs(
1452+
self, netuid: int, block_hash: Optional[str] = None
1453+
) -> int:
1454+
"""Retrieve the SubnetRevealPeriodEpochs hyperparameter."""
1455+
return await self.get_hyperparameter(
1456+
param_name="RevealPeriodEpochs", block_hash=block_hash, netuid=netuid
1457+
)
1458+
14321459
# Extrinsics =======================================================================================================
14331460

14341461
async def transfer(
@@ -1570,20 +1597,31 @@ async def set_weights(
15701597
15711598
This function is crucial in shaping the network's collective intelligence, where each neuron's learning and contribution are influenced by the weights it sets towards others【81†source】.
15721599
"""
1573-
uid = await self.get_uid_for_hotkey_on_subnet(
1574-
wallet.hotkey.ss58_address, netuid
1575-
)
15761600
retries = 0
15771601
success = False
1578-
message = "No attempt made. Perhaps it is too soon to set weights!"
1579-
while retries < max_retries and await self.blocks_since_last_update(
1580-
netuid, uid
1581-
) > await self.weights_rate_limit(netuid):
1582-
try:
1602+
if (
1603+
uid := await self.get_uid_for_hotkey_on_subnet(
1604+
wallet.hotkey.ss58_address, netuid
1605+
)
1606+
) is None:
1607+
return (
1608+
False,
1609+
f"Hotkey {wallet.hotkey.ss58_address} not registered in subnet {netuid}",
1610+
)
1611+
1612+
if (await self.commit_reveal_enabled(netuid=netuid)) is True:
1613+
# go with `commit reveal v3` extrinsic
1614+
message = "No attempt made. Perhaps it is too soon to commit weights!"
1615+
while (
1616+
await self.blocks_since_last_update(netuid, uid)
1617+
> await self.weights_rate_limit(netuid)
1618+
and retries < max_retries
1619+
and success is False
1620+
):
15831621
logging.info(
1584-
f"Setting weights for subnet #[blue]{netuid}[/blue]. Attempt [blue]{retries + 1} of {max_retries}[/blue]."
1622+
f"Committing weights for subnet #{netuid}. Attempt {retries + 1} of {max_retries}."
15851623
)
1586-
success, message = await set_weights_extrinsic(
1624+
success, message = await commit_reveal_v3_extrinsic(
15871625
subtensor=self,
15881626
wallet=wallet,
15891627
netuid=netuid,
@@ -1593,12 +1631,37 @@ async def set_weights(
15931631
wait_for_inclusion=wait_for_inclusion,
15941632
wait_for_finalization=wait_for_finalization,
15951633
)
1596-
except Exception as e:
1597-
logging.error(f"Error setting weights: {e}")
1598-
finally:
15991634
retries += 1
1635+
return success, message
1636+
else:
1637+
# go with classic `set weights extrinsic`
1638+
message = "No attempt made. Perhaps it is too soon to set weights!"
1639+
while (
1640+
retries < max_retries
1641+
and await self.blocks_since_last_update(netuid, uid)
1642+
> await self.weights_rate_limit(netuid)
1643+
and success is False
1644+
):
1645+
try:
1646+
logging.info(
1647+
f"Setting weights for subnet #[blue]{netuid}[/blue]. Attempt [blue]{retries + 1} of {max_retries}[/blue]."
1648+
)
1649+
success, message = await set_weights_extrinsic(
1650+
subtensor=self,
1651+
wallet=wallet,
1652+
netuid=netuid,
1653+
uids=uids,
1654+
weights=weights,
1655+
version_key=version_key,
1656+
wait_for_inclusion=wait_for_inclusion,
1657+
wait_for_finalization=wait_for_finalization,
1658+
)
1659+
except Exception as e:
1660+
logging.error(f"Error setting weights: {e}")
1661+
finally:
1662+
retries += 1
16001663

1601-
return success, message
1664+
return success, message
16021665

16031666
async def root_set_weights(
16041667
self,

bittensor/core/axon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def __init__(
341341
self.config = config # type: ignore
342342

343343
# Get wallet or use default.
344-
self.wallet = wallet or Wallet()
344+
self.wallet = wallet or Wallet(config=self.config)
345345

346346
# Build axon objects.
347347
self.uuid = str(uuid.uuid1())
@@ -594,7 +594,7 @@ def config(cls) -> "Config":
594594
"""
595595
parser = argparse.ArgumentParser()
596596
Axon.add_args(parser) # Add specific axon-related arguments
597-
return Config(parser, args=[])
597+
return Config(parser)
598598

599599
@classmethod
600600
def help(cls):

bittensor/core/dendrite.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ def log_exception(self, exception: Exception):
241241
"""
242242
error_id = str(uuid.uuid4())
243243
error_type = exception.__class__.__name__
244-
logging.error(f"{error_type}#{error_id}: {exception}")
244+
if isinstance(exception, (aiohttp.ClientConnectorError, asyncio.TimeoutError)):
245+
logging.debug(f"{error_type}#{error_id}: {exception}")
246+
else:
247+
logging.error(f"{error_type}#{error_id}: {exception}")
245248

246249
def process_error_message(
247250
self,

bittensor/core/errors.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717

1818
from __future__ import annotations
1919

20-
from bittensor.core.synapse import Synapse
20+
from typing import Optional, TYPE_CHECKING
2121

22+
from substrateinterface.exceptions import SubstrateRequestException
2223

23-
class ChainError(BaseException):
24+
if TYPE_CHECKING:
25+
from bittensor.core.synapse import Synapse
26+
27+
28+
class ChainError(SubstrateRequestException):
2429
"""Base error for any chain related errors."""
2530

2631

@@ -81,7 +86,9 @@ class InvalidRequestNameError(Exception):
8186

8287

8388
class SynapseException(Exception):
84-
def __init__(self, message="Synapse Exception", synapse: "Synapse" | None = None):
89+
def __init__(
90+
self, message="Synapse Exception", synapse: Optional["Synapse"] = None
91+
):
8592
self.message = message
8693
self.synapse = synapse
8794
super().__init__(self.message)
@@ -123,7 +130,7 @@ class SynapseDendriteNoneException(SynapseException):
123130
def __init__(
124131
self,
125132
message="Synapse Dendrite is None",
126-
synapse: "Synapse" | None = None,
133+
synapse: Optional["Synapse"] = None,
127134
):
128135
self.message = message
129136
super().__init__(self.message, synapse)

0 commit comments

Comments
 (0)