22
22
from retry import retry
23
23
from rich .prompt import Confirm
24
24
25
- from bittensor .core .settings import bt_console
26
25
from bittensor .utils import format_error_message
27
26
from bittensor .utils .btlogging import logging
28
27
from bittensor .utils .networking import ensure_connected
@@ -142,24 +141,22 @@ def register_extrinsic(
142
141
Flag is ``true`` if extrinsic was finalized or uncluded in the block. If we did not wait for finalization / inclusion, the response is ``true``.
143
142
"""
144
143
if not subtensor .subnet_exists (netuid ):
145
- bt_console .print (
146
- ":cross_mark: [red]Failed[/red]: error: [bold white]subnet:{}[/bold white] does not exist." .format (
147
- netuid
148
- )
144
+ logging .error (
145
+ f":cross_mark: <red>Failed: </red> Subnet <blue>{ netuid } </blue> does not exist."
149
146
)
150
147
return False
151
148
152
- with bt_console .status (
153
- f":satellite: Checking Account on [bold]subnet:{ netuid } [/bold]..."
154
- ):
155
- neuron = subtensor .get_neuron_for_pubkey_and_subnet (
156
- wallet .hotkey .ss58_address , netuid = netuid
149
+ logging .info (
150
+ f":satellite: <magenta>Checking Account on subnet</magenta> <blue>{ netuid } </blue><magenta>...</magenta>"
151
+ )
152
+ neuron = subtensor .get_neuron_for_pubkey_and_subnet (
153
+ wallet .hotkey .ss58_address , netuid = netuid
154
+ )
155
+ if not neuron .is_null :
156
+ logging .debug (
157
+ f"Wallet <green>{ wallet } </green> is already registered on <blue>{ neuron .netuid } </blue> with <blue>{ neuron .uid } </blue>."
157
158
)
158
- if not neuron .is_null :
159
- logging .debug (
160
- f"Wallet { wallet } is already registered on { neuron .netuid } with { neuron .uid } "
161
- )
162
- return True
159
+ return True
163
160
164
161
if prompt :
165
162
if not Confirm .ask (
@@ -178,14 +175,14 @@ def register_extrinsic(
178
175
# Attempt rolling registration.
179
176
attempts = 1
180
177
while True :
181
- bt_console . print (
182
- ":satellite: Registering...({ }/{})" . format ( attempts , max_allowed_attempts )
178
+ logging . info (
179
+ f ":satellite: <magenta> Registering...</magenta> <blue>( { attempts } /{ max_allowed_attempts } )</blue>"
183
180
)
184
181
# Solve latest POW.
185
182
if cuda :
186
183
if not torch .cuda .is_available ():
187
184
if prompt :
188
- bt_console . print ("CUDA is not available." )
185
+ logging . info ("CUDA is not available." )
189
186
return False
190
187
pow_result : Optional [POWSolution ] = create_pow (
191
188
subtensor ,
@@ -218,73 +215,71 @@ def register_extrinsic(
218
215
netuid = netuid , hotkey_ss58 = wallet .hotkey .ss58_address
219
216
)
220
217
if is_registered :
221
- bt_console . print (
222
- f":white_heavy_check_mark: [ green] Already registered on netuid:{ netuid } [/green] "
218
+ logging . info (
219
+ f":white_heavy_check_mark: < green> Already registered on netuid:</green> <blue> { netuid } </blue>. "
223
220
)
224
221
return True
225
222
226
223
# pow successful, proceed to submit pow to chain for registration
227
224
else :
228
- with bt_console . status (":satellite: Submitting POW..." ):
229
- # check if pow result is still valid
230
- while not pow_result .is_stale (subtensor = subtensor ):
231
- result : tuple [bool , Optional [str ]] = _do_pow_register (
232
- self = subtensor ,
233
- netuid = netuid ,
234
- wallet = wallet ,
235
- pow_result = pow_result ,
236
- wait_for_inclusion = wait_for_inclusion ,
237
- wait_for_finalization = wait_for_finalization ,
238
- )
239
- success , err_msg = result
240
-
241
- if not success :
242
- # Look error here
243
- # https://github.com/opentensor/subtensor/blob/development/pallets/subtensor/src/errors.rs
244
- if "HotKeyAlreadyRegisteredInSubNet" in err_msg :
245
- bt_console . print (
246
- f":white_heavy_check_mark: [ green] Already Registered on [bold] subnet: { netuid } [/bold][/green] "
247
- )
248
- return True
225
+ logging . info (":satellite: <magenta> Submitting POW...</magenta>" )
226
+ # check if pow result is still valid
227
+ while not pow_result .is_stale (subtensor = subtensor ):
228
+ result : tuple [bool , Optional [str ]] = _do_pow_register (
229
+ self = subtensor ,
230
+ netuid = netuid ,
231
+ wallet = wallet ,
232
+ pow_result = pow_result ,
233
+ wait_for_inclusion = wait_for_inclusion ,
234
+ wait_for_finalization = wait_for_finalization ,
235
+ )
236
+ success , err_msg = result
237
+
238
+ if not success :
239
+ # Look error here
240
+ # https://github.com/opentensor/subtensor/blob/development/pallets/subtensor/src/errors.rs
241
+ if "HotKeyAlreadyRegisteredInSubNet" in err_msg :
242
+ logging . info (
243
+ f":white_heavy_check_mark: < green> Already Registered on subnet </green><blue> { netuid } </blue>. "
244
+ )
245
+ return True
249
246
250
- bt_console . print (f":cross_mark: [ red] Failed[ /red]: { err_msg } " )
251
- time .sleep (0.5 )
247
+ logging . error (f":cross_mark: < red> Failed:< /red> { err_msg } " )
248
+ time .sleep (0.5 )
252
249
253
- # Successful registration, final check for neuron and pubkey
250
+ # Successful registration, final check for neuron and pubkey
251
+ else :
252
+ logging .info (":satellite: <magenta>Checking Balance...</magenta>" )
253
+ is_registered = subtensor .is_hotkey_registered (
254
+ hotkey_ss58 = wallet .hotkey .ss58_address ,
255
+ netuid = netuid ,
256
+ )
257
+ if is_registered :
258
+ logging .info (
259
+ ":white_heavy_check_mark: <green>Registered</green>"
260
+ )
261
+ return True
254
262
else :
255
- bt_console .print (":satellite: Checking Balance..." )
256
- is_registered = subtensor .is_hotkey_registered (
257
- hotkey_ss58 = wallet .hotkey .ss58_address ,
258
- netuid = netuid ,
263
+ # neuron not found, try again
264
+ logging .error (
265
+ ":cross_mark: <red>Unknown error. Neuron not found.</red>"
259
266
)
260
- if is_registered :
261
- bt_console .print (
262
- ":white_heavy_check_mark: [green]Registered[/green]"
263
- )
264
- return True
265
- else :
266
- # neuron not found, try again
267
- bt_console .print (
268
- ":cross_mark: [red]Unknown error. Neuron not found.[/red]"
269
- )
270
- continue
271
- else :
272
- # Exited loop because pow is no longer valid.
273
- bt_console .print ("[red]POW is stale.[/red]" )
274
- # Try again.
275
- continue
267
+ continue
268
+ else :
269
+ # Exited loop because pow is no longer valid.
270
+ logging .error ("<red>POW is stale.</red>" )
271
+ # Try again.
272
+ continue
276
273
277
274
if attempts < max_allowed_attempts :
278
275
# Failed registration, retry pow
279
276
attempts += 1
280
- bt_console .print (
281
- ":satellite: Failed registration, retrying pow ...({}/{})" .format (
282
- attempts , max_allowed_attempts
283
- )
277
+ logging .info (
278
+ f":satellite: <magenta>Failed registration, retrying pow ...</magenta> <blue>({ attempts } /{ max_allowed_attempts } )</blue>"
284
279
)
285
280
else :
286
281
# Failed to register after max attempts.
287
- bt_console . print ( "[ red] No more attempts.[ /red] " )
282
+ logging . error ( "< red> No more attempts.< /red> " )
288
283
return False
289
284
290
285
@@ -370,82 +365,70 @@ def burned_register_extrinsic(
370
365
success (bool): Flag is ``true`` if extrinsic was finalized or uncluded in the block. If we did not wait for finalization / inclusion, the response is ``true``.
371
366
"""
372
367
if not subtensor .subnet_exists (netuid ):
373
- bt_console .print (
374
- ":cross_mark: [red]Failed[/red]: error: [bold white]subnet:{}[/bold white] does not exist." .format (
375
- netuid
376
- )
368
+ logging .error (
369
+ f":cross_mark: <red>Failed error:</red> subnet <blue>{ netuid } </blue> does not exist."
377
370
)
378
371
return False
379
372
380
373
try :
381
374
wallet .unlock_coldkey ()
382
375
except KeyFileError :
383
- bt_console . print (
384
- ":cross_mark: [ red] Keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid[ /red]:[bold white] \n [/bold white] "
376
+ logging . error (
377
+ ":cross_mark: < red> Keyfile is corrupt, non-writable, non-readable or the password used to decrypt is invalid.< /red> "
385
378
)
386
379
return False
387
- with bt_console .status (
388
- f":satellite: Checking Account on [bold]subnet:{ netuid } [/bold]..."
389
- ):
390
- neuron = subtensor .get_neuron_for_pubkey_and_subnet (
391
- wallet .hotkey .ss58_address , netuid = netuid
392
- )
393
-
394
- old_balance = subtensor .get_balance (wallet .coldkeypub .ss58_address )
395
-
396
- recycle_amount = subtensor .recycle (netuid = netuid )
397
- if not neuron .is_null :
398
- bt_console .print (
399
- ":white_heavy_check_mark: [green]Already Registered[/green]:\n "
400
- "uid: [bold white]{}[/bold white]\n "
401
- "netuid: [bold white]{}[/bold white]\n "
402
- "hotkey: [bold white]{}[/bold white]\n "
403
- "coldkey: [bold white]{}[/bold white]" .format (
404
- neuron .uid , neuron .netuid , neuron .hotkey , neuron .coldkey
405
- )
406
- )
407
- return True
380
+ logging .info (
381
+ f":satellite: <magenta>Checking Account on subnet</magenta> <blue>{ netuid } </blue><magenta> ...</magenta>"
382
+ )
383
+ neuron = subtensor .get_neuron_for_pubkey_and_subnet (
384
+ wallet .hotkey .ss58_address , netuid = netuid
385
+ )
386
+
387
+ old_balance = subtensor .get_balance (wallet .coldkeypub .ss58_address )
388
+
389
+ recycle_amount = subtensor .recycle (netuid = netuid )
390
+ if not neuron .is_null :
391
+ logging .info (":white_heavy_check_mark: <green>Already Registered</green>" )
392
+ logging .info (f"\t \t uid: <blue>{ neuron .uid } </blue>" )
393
+ logging .info (f"\t \t netuid: <blue>{ neuron .netuid } </blue>" )
394
+ logging .info (f"\t \t hotkey: <blue>{ neuron .hotkey } </blue>" )
395
+ logging .info (f"\t \t coldkey: <blue>{ neuron .coldkey } </blue>" )
396
+ return True
408
397
409
398
if prompt :
410
399
# Prompt user for confirmation.
411
400
if not Confirm .ask (f"Recycle { recycle_amount } to register on subnet:{ netuid } ?" ):
412
401
return False
413
402
414
- with bt_console .status (":satellite: Recycling TAO for Registration..." ):
415
- success , err_msg = _do_burned_register (
416
- self = subtensor ,
417
- netuid = netuid ,
418
- wallet = wallet ,
419
- wait_for_inclusion = wait_for_inclusion ,
420
- wait_for_finalization = wait_for_finalization ,
403
+ logging .info (":satellite: <magenta>Recycling TAO for Registration...</magenta>" )
404
+ success , err_msg = _do_burned_register (
405
+ self = subtensor ,
406
+ netuid = netuid ,
407
+ wallet = wallet ,
408
+ wait_for_inclusion = wait_for_inclusion ,
409
+ wait_for_finalization = wait_for_finalization ,
410
+ )
411
+
412
+ if not success :
413
+ logging .error (f":cross_mark: <red>Failed:</red> { err_msg } " )
414
+ time .sleep (0.5 )
415
+ return False
416
+ # Successful registration, final check for neuron and pubkey
417
+ else :
418
+ logging .info (":satellite: <magenta>Checking Balance...</magenta>" )
419
+ block = subtensor .get_current_block ()
420
+ new_balance = subtensor .get_balance (wallet .coldkeypub .ss58_address , block = block )
421
+
422
+ logging .info (
423
+ f"Balance: <blue>{ old_balance } </blue> :arrow_right: <green>{ new_balance } </green>"
421
424
)
422
-
423
- if not success :
424
- bt_console . print ( f":cross_mark: [red]Failed[/red]: { err_msg } " )
425
- time . sleep ( 0.5 )
426
- return False
427
- # Successful registration, final check for neuron and pubkey
425
+ is_registered = subtensor . is_hotkey_registered (
426
+ netuid = netuid , hotkey_ss58 = wallet . hotkey . ss58_address
427
+ )
428
+ if is_registered :
429
+ logging . info ( ":white_heavy_check_mark: <green>Registered</green>" )
430
+ return True
428
431
else :
429
- bt_console .print (":satellite: Checking Balance..." )
430
- block = subtensor .get_current_block ()
431
- new_balance = subtensor .get_balance (
432
- wallet .coldkeypub .ss58_address , block = block
433
- )
434
-
435
- bt_console .print (
436
- "Balance:\n [blue]{}[/blue] :arrow_right: [green]{}[/green]" .format (
437
- old_balance , new_balance
438
- )
439
- )
440
- is_registered = subtensor .is_hotkey_registered (
441
- netuid = netuid , hotkey_ss58 = wallet .hotkey .ss58_address
442
- )
443
- if is_registered :
444
- bt_console .print (":white_heavy_check_mark: [green]Registered[/green]" )
445
- return True
446
- else :
447
- # neuron not found, try again
448
- bt_console .print (
449
- ":cross_mark: [red]Unknown error. Neuron not found.[/red]"
450
- )
451
- return False
432
+ # neuron not found, try again
433
+ logging .error (":cross_mark: <red>Unknown error. Neuron not found.</red>" )
434
+ return False
0 commit comments