Skip to content

Commit ff7f215

Browse files
committed
Merge branch 'staging' into release/8.1.0
2 parents 538511c + e1d6b5c commit ff7f215

File tree

14 files changed

+144
-56
lines changed

14 files changed

+144
-56
lines changed

bittensor/__init__.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,6 @@
2222
from .utils.deprecated import *
2323

2424

25-
# Logging helpers.
26-
def trace(on: bool = True):
27-
"""
28-
Enables or disables trace logging.
29-
30-
Args:
31-
on (bool): If True, enables trace logging. If False, disables trace logging.
32-
"""
33-
logging.set_trace(on)
34-
35-
36-
def debug(on: bool = True):
37-
"""
38-
Enables or disables debug logging.
39-
40-
Args:
41-
on (bool): If True, enables debug logging. If False, disables debug logging.
42-
"""
43-
logging.set_debug(on)
44-
45-
4625
def __getattr__(name):
4726
if name == "version_split":
4827
warnings.warn(

bittensor/core/axon.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232
from typing import Any, Awaitable, Callable, Optional, Tuple
3333

3434
import uvicorn
35-
from bittensor_wallet import Wallet
35+
from bittensor_wallet import Wallet, Keypair
36+
3637
from fastapi import APIRouter, Depends, FastAPI
3738
from fastapi.responses import JSONResponse
3839
from fastapi.routing import serialize_response
3940
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
4041
from starlette.requests import Request
4142
from starlette.responses import Response
42-
from substrateinterface import Keypair
43+
4344

4445
from bittensor.core.chain_data import AxonInfo
4546
from bittensor.core.config import Config

bittensor/core/dendrite.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
from typing import Any, AsyncGenerator, Optional, Union, Type
2424

2525
import aiohttp
26-
from bittensor_wallet import Wallet
27-
from substrateinterface import Keypair
26+
from bittensor_wallet import Keypair, Wallet
2827

2928
from bittensor.core.axon import Axon
3029
from bittensor.core.chain_data import AxonInfo

bittensor/core/subtensor.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def __init__(
134134
network: Optional[str] = None,
135135
config: Optional["Config"] = None,
136136
_mock: bool = False,
137-
log_verbose: bool = True,
137+
log_verbose: bool = False,
138138
connection_timeout: int = 600,
139139
) -> None:
140140
"""
@@ -175,17 +175,18 @@ def __init__(
175175
logging.info(
176176
f"You are connecting to {self.network} network with endpoint {self.chain_endpoint}."
177177
)
178-
logging.warning(
178+
logging.debug(
179179
"We strongly encourage running a local subtensor node whenever possible. "
180180
"This increases decentralization and resilience of the network."
181181
)
182-
logging.warning(
182+
logging.debug(
183183
"In a future release, local subtensor will become the default endpoint. "
184184
"To get ahead of this change, please run a local subtensor node and point to it."
185185
)
186186

187187
self.log_verbose = log_verbose
188188
self._connection_timeout = connection_timeout
189+
self.substrate: "SubstrateInterface" = None
189190
self._get_substrate()
190191

191192
def __str__(self) -> str:
@@ -201,7 +202,8 @@ def __repr__(self) -> str:
201202

202203
def close(self):
203204
"""Cleans up resources for this subtensor instance like active websocket connection and active extensions."""
204-
self.substrate.close()
205+
if self.substrate:
206+
self.substrate.close()
205207

206208
def _get_substrate(self):
207209
"""Establishes a connection to the Substrate node using configured parameters."""
@@ -214,7 +216,7 @@ def _get_substrate(self):
214216
type_registry=settings.TYPE_REGISTRY,
215217
)
216218
if self.log_verbose:
217-
logging.info(
219+
logging.debug(
218220
f"Connected to {self.network} network and {self.chain_endpoint}."
219221
)
220222

@@ -223,14 +225,15 @@ def _get_substrate(self):
223225
except (AttributeError, TypeError, socket.error, OSError) as e:
224226
logging.warning(f"Error setting timeout: {e}")
225227

226-
except ConnectionRefusedError:
228+
except ConnectionRefusedError as error:
227229
logging.error(
228230
f"Could not connect to {self.network} network with {self.chain_endpoint} chain endpoint.",
229231
)
230232
logging.info(
231233
"You can check if you have connectivity by running this command: nc -vz localhost "
232-
f"{self.chain_endpoint.split(':')[2]}"
234+
f"{self.chain_endpoint}"
233235
)
236+
raise ConnectionRefusedError(error.args)
234237

235238
@staticmethod
236239
def config() -> "Config":

bittensor/utils/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
# DEALINGS IN THE SOFTWARE.
1717

1818
import hashlib
19-
from typing import List, Dict, Literal, Union, Optional, TYPE_CHECKING
19+
from typing import Literal, Union, Optional, TYPE_CHECKING
2020

2121
import scalecodec
22-
from substrateinterface import Keypair
22+
from bittensor_wallet import Keypair
2323
from substrateinterface.utils import ss58
2424

2525
from bittensor.core.settings import SS58_FORMAT
@@ -245,7 +245,7 @@ def _is_valid_ed25519_pubkey(public_key: Union[str, bytes]) -> bool:
245245
else:
246246
raise ValueError("public_key must be a string or bytes")
247247

248-
keypair = Keypair(public_key=public_key, ss58_format=SS58_FORMAT)
248+
keypair = Keypair(public_key=public_key)
249249

250250
ss58_addr = keypair.ss58_address
251251
return ss58_addr is not None

bittensor/utils/btlogging/loggingmachine.py

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,48 @@ class LoggingMachine(StateMachine, Logger):
6969
Debug = State()
7070
Trace = State()
7171
Disabled = State()
72+
Warning = State()
7273

7374
enable_default = (
7475
Debug.to(Default)
7576
| Trace.to(Default)
7677
| Disabled.to(Default)
7778
| Default.to(Default)
79+
| Warning.to(Default)
7880
)
7981

82+
enable_info = enable_default
83+
8084
enable_trace = (
81-
Default.to(Trace) | Debug.to(Trace) | Disabled.to(Trace) | Trace.to(Trace)
85+
Default.to(Trace)
86+
| Debug.to(Trace)
87+
| Disabled.to(Trace)
88+
| Trace.to(Trace)
89+
| Warning.to(Trace)
8290
)
8391

8492
enable_debug = (
85-
Default.to(Debug) | Trace.to(Debug) | Disabled.to(Debug) | Debug.to(Debug)
93+
Default.to(Debug)
94+
| Trace.to(Debug)
95+
| Disabled.to(Debug)
96+
| Debug.to(Debug)
97+
| Warning.to(Debug)
98+
)
99+
100+
enable_warning = (
101+
Default.to(Warning)
102+
| Trace.to(Warning)
103+
| Disabled.to(Warning)
104+
| Debug.to(Warning)
105+
| Warning.to(Warning)
86106
)
87107

88108
disable_trace = Trace.to(Default)
89109

90110
disable_debug = Debug.to(Default)
91111

112+
disable_warning = Warning.to(Default)
113+
92114
disable_logging = (
93115
Trace.to(Disabled)
94116
| Debug.to(Disabled)
@@ -301,16 +323,36 @@ def after_transition(self, event, state):
301323
# Default Logging
302324
def before_enable_default(self):
303325
"""Logs status before enable Default."""
304-
self._logger.info(f"Enabling default logging.")
326+
self._logger.info("Enabling default logging.")
305327
self._logger.setLevel(stdlogging.WARNING)
306328
for logger in all_loggers():
307329
if logger.name in self._primary_loggers:
308330
continue
309331
logger.setLevel(stdlogging.CRITICAL)
310332

333+
def before_enable_info(self):
334+
"""Logs status before enable Default."""
335+
self._logger.info("Enabling default logging.")
336+
self._logger.setLevel(stdlogging.INFO)
337+
for logger in all_loggers():
338+
if logger.name in self._primary_loggers:
339+
continue
340+
logger.setLevel(stdlogging.CRITICAL)
341+
311342
def after_enable_default(self):
312343
pass
313344

345+
def before_enable_warning(self):
346+
"""Logs status before enable Warning."""
347+
self._logger.info("Enabling warning.")
348+
self._stream_formatter.set_trace(True)
349+
for logger in all_loggers():
350+
logger.setLevel(stdlogging.WARNING)
351+
352+
def after_enable_warning(self):
353+
"""Logs status after enable Warning."""
354+
self._logger.info("Warning enabled.")
355+
314356
# Trace
315357
def before_enable_trace(self):
316358
"""Logs status before enable Trace."""
@@ -325,7 +367,7 @@ def after_enable_trace(self):
325367

326368
def before_disable_trace(self):
327369
"""Logs status before disable Trace."""
328-
self._logger.info(f"Disabling trace.")
370+
self._logger.info("Disabling trace.")
329371
self._stream_formatter.set_trace(False)
330372
self.enable_default()
331373

@@ -449,6 +491,25 @@ def set_trace(self, on: bool = True):
449491
if self.current_state_value == "Trace":
450492
self.disable_trace()
451493

494+
def set_warning(self, on: bool = True):
495+
"""Sets Warning state."""
496+
if on and not self.current_state_value == "Warning":
497+
self.enable_warning()
498+
elif not on:
499+
if self.current_state_value == "Warning":
500+
self.disable_warning()
501+
502+
def set_default(self):
503+
"""Sets Default state."""
504+
if not self.current_state_value == "Default":
505+
self.enable_default()
506+
507+
# as an option to be more obvious. `bittensor.logging.set_info()` is the same `bittensor.logging.set_default()`
508+
def set_info(self):
509+
"""Sets Default state."""
510+
if not self.current_state_value == "Default":
511+
self.enable_info()
512+
452513
def get_level(self) -> int:
453514
"""Returns Logging level."""
454515
return self._logger.level

bittensor/utils/deprecated.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
Keyfile,
4343
)
4444
from bittensor_wallet.wallet import display_mnemonic_msg, Wallet # noqa: F401
45-
from substrateinterface import Keypair # noqa: F401
45+
from bittensor_wallet import Keypair # noqa: F401
4646

4747
from bittensor.core import settings
4848
from bittensor.core.axon import Axon
@@ -112,6 +112,7 @@
112112
)
113113
from bittensor.utils.balance import Balance as Balance # noqa: F401
114114
from bittensor.utils.mock.subtensor_mock import MockSubtensor as MockSubtensor # noqa: F401
115+
from bittensor.utils.btlogging import logging
115116
from bittensor.utils.subnets import SubnetsAPI # noqa: F401
116117

117118
# Backwards compatibility with previous bittensor versions.
@@ -148,3 +149,35 @@
148149
# Makes the `bittensor.core.extrinsics` subpackage available as `bittensor.extrinsics` for backwards compatibility.
149150
extrinsics_subpackage = importlib.import_module("bittensor.core.extrinsics")
150151
sys.modules["bittensor.extrinsics"] = extrinsics_subpackage
152+
153+
154+
# Logging helpers.
155+
def trace(on: bool = True):
156+
"""
157+
Enables or disables trace logging.
158+
Args:
159+
on (bool): If True, enables trace logging. If False, disables trace logging.
160+
"""
161+
logging.set_trace(on)
162+
163+
164+
def debug(on: bool = True):
165+
"""
166+
Enables or disables debug logging.
167+
Args:
168+
on (bool): If True, enables debug logging. If False, disables debug logging.
169+
"""
170+
logging.set_debug(on)
171+
172+
173+
def warning(on: bool = True):
174+
"""
175+
Enables or disables warning logging.
176+
Args:
177+
on (bool): If True, enables warning logging. If False, disables warning logging and sets default (INFO) level.
178+
"""
179+
logging.set_warning(on)
180+
181+
182+
# set Warning logging level for bittensor SDK
183+
warning()

bittensor/utils/weight_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
from numpy.typing import NDArray
2828
from scalecodec import U16, ScaleBytes, Vec
29-
from substrateinterface import Keypair
29+
from bittensor_wallet import Keypair
3030

3131
from bittensor.utils.btlogging import logging
3232
from bittensor.utils.registration import legacy_torch_api_compat, torch, use_torch

requirements/prod.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ python-Levenshtein
2020
scalecodec==1.2.11
2121
substrate-interface~=1.7.9
2222
uvicorn
23-
bittensor-wallet==1.0.0
23+
bittensor-wallet==2.0.0

tests/e2e_tests/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ def local_chain(request):
4545

4646
# install neuron templates
4747
logging.info("downloading and installing neuron templates from github")
48-
templates_dir = clone_or_update_templates()
48+
# commit with subnet-template-repo changes for rust wallet
49+
templates_dir = clone_or_update_templates(
50+
"334d3da101279218b3a4c9d72a12d517f6e39be3"
51+
)
4952
install_templates(templates_dir)
5053

5154
timestamp = int(time.time())

0 commit comments

Comments
 (0)