Skip to content

Commit bab874c

Browse files
Merge pull request #2446 from opentensor/feat/roman/bittensor-console
BittensorConsole class
2 parents 336fb6c + 308ffcb commit bab874c

16 files changed

+223
-128
lines changed

bittensor/core/async_subtensor.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ def __init__(self, network: str = DEFAULT_NETWORK):
132132
self.network = "custom"
133133
else:
134134
logging.info(
135-
f"Network not specified or not valid. Using default chain endpoint: <blue>{NETWORK_MAP[DEFAULTS.subtensor.network]}</blue>."
135+
f"Network not specified or not valid. Using default chain endpoint: [blue]{NETWORK_MAP[DEFAULTS.subtensor.network]}[/blue]."
136136
)
137137
logging.info(
138-
"You can set this for commands with the <blue>--network</blue> flag, or by setting this in the config."
138+
"You can set this for commands with the [blue]--network[/blue] flag, or by setting this in the config."
139139
)
140140
self.chain_endpoint = NETWORK_MAP[DEFAULTS.subtensor.network]
141141
self.network = DEFAULTS.subtensor.network
@@ -152,19 +152,19 @@ def __str__(self):
152152

153153
async def __aenter__(self):
154154
logging.info(
155-
f"<magenta>Connecting to Substrate:</magenta> <blue>{self}</blue><magenta>...</magenta>"
155+
f"[magenta]Connecting to Substrate:[/magenta] [blue]{self}[/blue][magenta]...[/magenta]"
156156
)
157157
try:
158158
async with self.substrate:
159159
return self
160160
except TimeoutException:
161161
logging.error(
162-
f"<red>Error</red>: Timeout occurred connecting to substrate. Verify your chain and network settings: {self}"
162+
f"[red]Error[/red]: Timeout occurred connecting to substrate. Verify your chain and network settings: {self}"
163163
)
164164
raise ConnectionError
165165
except (ConnectionRefusedError, ssl.SSLError) as error:
166166
logging.error(
167-
f"<red>Error</red>: Connection refused when connecting to substrate. "
167+
f"[red]Error[/red]: Connection refused when connecting to substrate. "
168168
f"Verify your chain and network settings: {self}. Error: {error}"
169169
)
170170
raise ConnectionError
@@ -533,7 +533,7 @@ async def get_transfer_fee(
533533
)
534534
except Exception as e:
535535
logging.error(
536-
f":cross_mark: <red>Failed to get payment info: </red>{e}"
536+
f":cross_mark: [red]Failed to get payment info: [/red]{e}"
537537
)
538538
payment_info = {"partialFee": int(2e7)} # assume 0.02 Tao
539539

@@ -1408,7 +1408,7 @@ async def register(
14081408
`True` if registration was successful, otherwise `False`.
14091409
"""
14101410
logging.info(
1411-
f"Registering on netuid <blue>0</blue> on network: <blue>{self.network}</blue>"
1411+
f"Registering on netuid [blue]0[/blue] on network: [blue]{self.network}[/blue]"
14121412
)
14131413

14141414
# Check current recycle amount
@@ -1431,7 +1431,7 @@ async def register(
14311431
# Check balance is sufficient
14321432
if balance < current_recycle:
14331433
logging.error(
1434-
f"<red>Insufficient balance {balance} to register neuron. Current recycle is {current_recycle} TAO</red>."
1434+
f"[red]Insufficient balance {balance} to register neuron. Current recycle is {current_recycle} TAO[/red]."
14351435
)
14361436
return False
14371437

@@ -1509,7 +1509,7 @@ async def set_weights(
15091509
) > await self.weights_rate_limit(netuid):
15101510
try:
15111511
logging.info(
1512-
f"Setting weights for subnet #<blue>{netuid}</blue>. Attempt <blue>{retries + 1} of {max_retries}</blue>."
1512+
f"Setting weights for subnet #[blue]{netuid}[/blue]. Attempt [blue]{retries + 1} of {max_retries}[/blue]."
15131513
)
15141514
success, message = await set_weights_extrinsic(
15151515
subtensor=self,
@@ -1547,7 +1547,7 @@ async def root_set_weights(
15471547
"""
15481548
netuids_ = np.array(netuids, dtype=np.int64)
15491549
weights_ = np.array(weights, dtype=np.float32)
1550-
logging.info(f"Setting weights in network: <blue>{self.network}</blue>")
1550+
logging.info(f"Setting weights in network: [blue]{self.network}[/blue]")
15511551
# Run the set weights operation.
15521552
return await set_root_weights_extrinsic(
15531553
subtensor=self,

bittensor/core/extrinsics/async_registration.py

+13-15
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ async def register_extrinsic(
132132
logging.debug("Checking subnet status")
133133
if not await subtensor.subnet_exists(netuid):
134134
logging.error(
135-
f":cross_mark: <red>Failed error:</red> subnet <blue>{netuid}</blue> does not exist."
135+
f":cross_mark: [red]Failed error:[/red] subnet [blue]{netuid}[/blue] does not exist."
136136
)
137137
return False
138138

139139
logging.info(
140-
f":satellite: <magenta>Checking Account on subnet</magenta> <blue>{netuid}</blue> <magenta>...</magenta>"
140+
f":satellite: [magenta]Checking Account on subnet[/magenta] [blue]{netuid}[/blue] [magenta]...[/magenta]"
141141
)
142142
neuron = await subtensor.get_neuron_for_pubkey_and_subnet(
143143
hotkey_ss58=wallet.hotkey.ss58_address,
@@ -146,7 +146,7 @@ async def register_extrinsic(
146146

147147
if not neuron.is_null:
148148
logging.debug(
149-
f"Wallet <green>{wallet}</green> is already registered on subnet <blue>{neuron.netuid}</blue> with uid<blue>{neuron.uid}</blue>."
149+
f"Wallet [green]{wallet}[/green] is already registered on subnet [blue]{neuron.netuid}[/blue] with uid[blue]{neuron.uid}[/blue]."
150150
)
151151
return True
152152

@@ -163,7 +163,7 @@ async def register_extrinsic(
163163

164164
while True:
165165
logging.info(
166-
f":satellite: <magenta>Registering...</magenta> <blue>({attempts}/{max_allowed_attempts})</blue>"
166+
f":satellite: [magenta]Registering...[/magenta] [blue]({attempts}/{max_allowed_attempts})[/blue]"
167167
)
168168
# Solve latest POW.
169169
if cuda:
@@ -201,13 +201,13 @@ async def register_extrinsic(
201201
)
202202
if is_registered:
203203
logging.error(
204-
f":white_heavy_check_mark: <green>Already registered on netuid:</green> <blue>{netuid}</blue>"
204+
f":white_heavy_check_mark: [green]Already registered on netuid:[/green] [blue]{netuid}[/blue]"
205205
)
206206
return True
207207

208208
# pow successful, proceed to submit pow to chain for registration
209209
else:
210-
logging.info(":satellite: <magenta>Submitting POW...</magenta>")
210+
logging.info(":satellite: [magenta]Submitting POW...[/magenta]")
211211
# check if pow result is still valid
212212
while not await pow_result.is_stale_async(subtensor=subtensor):
213213
result: tuple[bool, Optional[str]] = await _do_pow_register(
@@ -226,11 +226,10 @@ async def register_extrinsic(
226226

227227
if "HotKeyAlreadyRegisteredInSubNet" in err_msg:
228228
logging.info(
229-
f":white_heavy_check_mark: <green>Already Registered on subnet:</green> <blue>{netuid}</blue>."
229+
f":white_heavy_check_mark: [green]Already Registered on subnet:[/green] [blue]{netuid}[/blue]."
230230
)
231231
return True
232-
233-
logging.error(f":cross_mark: <red>Failed</red>: {err_msg}")
232+
logging.error(f":cross_mark: [red]Failed[/red]: {err_msg}")
234233
await asyncio.sleep(0.5)
235234

236235
# Successful registration, final check for neuron and pubkey
@@ -241,29 +240,28 @@ async def register_extrinsic(
241240
)
242241
if is_registered:
243242
logging.success(
244-
":white_heavy_check_mark: <green>Registered</green>"
243+
":white_heavy_check_mark: [green]Registered[/green]"
245244
)
246245
return True
247246
else:
248247
# neuron not found, try again
249248
logging.error(
250-
":cross_mark: <red>Unknown error. Neuron not found.</red>"
249+
":cross_mark: [red]Unknown error. Neuron not found.[/red]"
251250
)
252251
continue
253252
else:
254253
# Exited loop because pow is no longer valid.
255-
logging.error("<red>POW is stale.</red>")
254+
logging.error("[red]POW is stale.[/red]")
256255
# Try again.
257256
# continue
258257

259258
if attempts < max_allowed_attempts:
260259
# Failed registration, retry pow
261260
attempts += 1
262261
logging.error(
263-
f":satellite: <magenta>Failed registration, retrying pow ...</magenta> <blue>({attempts}/{max_allowed_attempts})</blue>"
262+
f":satellite: [magenta]Failed registration, retrying pow ...[/magenta] [blue]({attempts}/{max_allowed_attempts})[/blue]"
264263
)
265-
continue
266264
else:
267265
# Failed to register after max attempts.
268-
logging.error("<red>No more attempts.</red>")
266+
logging.error("[red]No more attempts.[/red]")
269267
return False

bittensor/core/extrinsics/async_root.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@ async def root_register_extrinsic(
6767
return False
6868

6969
logging.debug(
70-
f"Checking if hotkey (<blue>{wallet.hotkey_str}</blue>) is registered on root."
70+
f"Checking if hotkey ([blue]{wallet.hotkey_str}[/blue]) is registered on root."
7171
)
7272
is_registered = await subtensor.is_hotkey_registered(
7373
netuid=netuid, hotkey_ss58=wallet.hotkey.ss58_address
7474
)
7575
if is_registered:
7676
logging.error(
77-
":white_heavy_check_mark: <green>Already registered on root network.</green>"
77+
":white_heavy_check_mark: [green]Already registered on root network.[/green]"
7878
)
7979
return True
8080

81-
logging.info(":satellite: <magenta>Registering to root network...</magenta>")
81+
logging.info(":satellite: [magenta]Registering to root network...[/magenta]")
8282
call = await subtensor.substrate.compose_call(
8383
call_module="SubtensorModule",
8484
call_function="root_register",
@@ -92,7 +92,7 @@ async def root_register_extrinsic(
9292
)
9393

9494
if not success:
95-
logging.error(f":cross_mark: <red>Failed error:</red> {err_msg}")
95+
logging.error(f":cross_mark: [red]Failed error:[/red] {err_msg}")
9696
time.sleep(0.5)
9797
return False
9898

@@ -105,12 +105,12 @@ async def root_register_extrinsic(
105105
)
106106
if uid is not None:
107107
logging.info(
108-
f":white_heavy_check_mark: <green>Registered with UID</green> <blue>{uid}</blue>."
108+
f":white_heavy_check_mark: [green]Registered with UID[/green] [blue]{uid}[/blue]."
109109
)
110110
return True
111111
else:
112112
# neuron not found, try again
113-
logging.error(":cross_mark: <red>Unknown error. Neuron not found.</red>")
113+
logging.error(":cross_mark: [red]Unknown error. Neuron not found.[/red]")
114114
return False
115115

116116

@@ -234,11 +234,11 @@ async def set_root_weights_extrinsic(
234234
logging.info("Normalizing weights")
235235
formatted_weights = normalize_max_weight(x=weights, limit=max_weight_limit)
236236
logging.info(
237-
f"Raw weights -> Normalized weights: <blue>{weights}</blue> -> <green>{formatted_weights}</green>"
237+
f"Raw weights -> Normalized weights: [blue]{weights}[/blue] -> [green]{formatted_weights}[/green]"
238238
)
239239

240240
try:
241-
logging.info(":satellite: <magenta>Setting root weights...<magenta>")
241+
logging.info(":satellite: [magenta]Setting root weights...[magenta]")
242242
weight_uids, weight_vals = convert_weights_and_uids_for_emit(netuids, weights)
243243

244244
success, error_message = await _do_set_root_weights(
@@ -255,14 +255,14 @@ async def set_root_weights_extrinsic(
255255
return True
256256

257257
if success is True:
258-
logging.info(":white_heavy_check_mark: <green>Finalized</green>")
258+
logging.info(":white_heavy_check_mark: [green]Finalized[/green]")
259259
return True
260260
else:
261261
fmt_err = error_message
262-
logging.error(f":cross_mark: <red>Failed error:</red> {fmt_err}")
262+
logging.error(f":cross_mark: [red]Failed error:[/red] {fmt_err}")
263263
return False
264264

265265
except SubstrateRequestException as e:
266266
fmt_err = format_error_message(e, subtensor.substrate)
267-
logging.error(f":cross_mark: <red>Failed error:</red> {fmt_err}")
267+
logging.error(f":cross_mark: [red]Failed error:[/red] {fmt_err}")
268268
return False

bittensor/core/extrinsics/async_transfer.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async def transfer_extrinsic(
9898
# Validate destination address.
9999
if not is_valid_bittensor_address_or_public_key(destination):
100100
logging.error(
101-
f":cross_mark: <red>Invalid destination SS58 address</red>: {destination}"
101+
f":cross_mark: [red]Invalid destination SS58 address[/red]: {destination}"
102102
)
103103
return False
104104
logging.info(f"Initiating transfer on network: {subtensor.network}")
@@ -109,7 +109,7 @@ async def transfer_extrinsic(
109109

110110
# Check balance.
111111
logging.info(
112-
f":satellite: <magenta>Checking balance and fees on chain </magenta> <blue>{subtensor.network}</blue>"
112+
f":satellite: [magenta]Checking balance and fees on chain [/magenta] [blue]{subtensor.network}[/blue]"
113113
)
114114
# check existential deposit and fee
115115
logging.debug("Fetching existential and fee")
@@ -135,13 +135,13 @@ async def transfer_extrinsic(
135135
return False
136136

137137
if account_balance < (amount + fee + existential_deposit):
138-
logging.error(":cross_mark: <red>Not enough balance</red>")
139-
logging.error(f"\t\tBalance:\t<blue>{account_balance}</blue>")
140-
logging.error(f"\t\tAmount:\t<blue>{amount}</blue>")
141-
logging.error(f"\t\tFor fee:\t<blue>{fee}</blue>")
138+
logging.error(":cross_mark: [red]Not enough balance[/red]")
139+
logging.error(f"\t\tBalance:\t[blue]{account_balance}[/blue]")
140+
logging.error(f"\t\tAmount:\t[blue]{amount}[/blue]")
141+
logging.error(f"\t\tFor fee:\t[blue]{fee}[/blue]")
142142
return False
143143

144-
logging.info(":satellite: <magenta>Transferring...</magenta")
144+
logging.info(":satellite: [magenta]Transferring...</magenta")
145145
success, block_hash, err_msg = await _do_transfer(
146146
subtensor=subtensor,
147147
wallet=wallet,
@@ -152,8 +152,8 @@ async def transfer_extrinsic(
152152
)
153153

154154
if success:
155-
logging.success(":white_heavy_check_mark: [green]Finalized</green>")
156-
logging.info(f"[green]Block Hash:</green> <blue>{block_hash}</blue>")
155+
logging.success(":white_heavy_check_mark: [green]Finalized[/green]")
156+
logging.info(f"[green]Block Hash:[/green] [blue]{block_hash}[/blue]")
157157

158158
if subtensor.network == "finney":
159159
logging.debug("Fetching explorer URLs")
@@ -162,18 +162,18 @@ async def transfer_extrinsic(
162162
)
163163
if explorer_urls != {} and explorer_urls:
164164
logging.info(
165-
f"[green]Opentensor Explorer Link: {explorer_urls.get('opentensor')}</green>"
165+
f"[green]Opentensor Explorer Link: {explorer_urls.get('opentensor')}[/green]"
166166
)
167167
logging.info(
168-
f"[green]Taostats Explorer Link: {explorer_urls.get('taostats')}</green>"
168+
f"[green]Taostats Explorer Link: {explorer_urls.get('taostats')}[/green]"
169169
)
170170

171-
logging.info(":satellite: <magenta>Checking Balance...<magenta>")
171+
logging.info(":satellite: [magenta]Checking Balance...[magenta]")
172172
new_balance = await subtensor.get_balance(wallet.coldkeypub.ss58_address)
173173
logging.info(
174-
f"Balance: [blue]{account_balance}</blue> :arrow_right: [green]{new_balance[wallet.coldkeypub.ss58_address]}</green>"
174+
f"Balance: [blue]{account_balance}[/blue] :arrow_right: [green]{new_balance[wallet.coldkeypub.ss58_address]}[/green]"
175175
)
176176
return True
177177
else:
178-
logging.error(f":cross_mark: <red>Failed</red>: {err_msg}")
178+
logging.error(f":cross_mark: [red]Failed[/red]: {err_msg}")
179179
return False

bittensor/core/extrinsics/async_weights.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async def set_weights_extrinsic(
125125
)
126126

127127
logging.info(
128-
":satellite: <magenta>Setting weights on </magenta><blue>{subtensor.network}</blue> <magenta>...</magenta>"
128+
":satellite: [magenta]Setting weights on [/magenta][blue]{subtensor.network}[/blue] [magenta]...[/magenta]"
129129
)
130130
try:
131131
success, error_message = await _do_set_weights(
@@ -144,14 +144,14 @@ async def set_weights_extrinsic(
144144

145145
if success is True:
146146
message = "Successfully set weights and Finalized."
147-
logging.success(f":white_heavy_check_mark: <green>{message}</green>")
147+
logging.success(f":white_heavy_check_mark: [green]{message}[/green]")
148148
return True, message
149149
else:
150-
logging.error(f"<red>Failed</red> set weights. Error: {error_message}")
150+
logging.error(f"[red]Failed[/red] set weights. Error: {error_message}")
151151
return False, error_message
152152

153153
except Exception as error:
154-
logging.error(f":cross_mark: <red>Failed</red> set weights. Error: {error}")
154+
logging.error(f":cross_mark: [red]Failed[/red] set weights. Error: {error}")
155155
return False, str(error)
156156

157157

0 commit comments

Comments
 (0)