Skip to content

Commit ae73c0a

Browse files
committed
fix(miner,scripts): sync metagraph at startup, fix bittensor v10 api names
1 parent ca2079b commit ae73c0a

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

instant_register.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ def ensure_wallet(name: str, hotkey: str = "default") -> bt.Wallet:
8484
created_cold = False
8585
created_hot = False
8686

87-
if not Path(w.coldkeyfile.path).exists():
87+
if not Path(w.coldkey_file.path).exists():
8888
w.create_new_coldkey(n_words=12, use_password=False, overwrite=False)
8989
created_cold = True
9090

91-
if not Path(w.hotkeyfile.path).exists():
91+
if not Path(w.hotkey_file.path).exists():
9292
w.create_new_hotkey(n_words=12, use_password=False, overwrite=False)
9393
created_hot = True
9494

@@ -143,12 +143,11 @@ def ensure_wallet(name: str, hotkey: str = "default") -> bt.Wallet:
143143
# ── Step 4: Create subnet ────────────────────────────────────────────────────
144144
print(f"\n{BO}[4/6] Ensuring subnet {NETUID} exists...{RS}")
145145
try:
146-
existing = bt_sub.get_subnets()
147-
if NETUID in existing:
146+
if bt_sub.subnet_exists(netuid=NETUID):
148147
ok(f"Subnet {NETUID} already exists")
149148
else:
150149
owner_wallet = wallets["owner"]
151-
result = bt_sub.register_subnetwork(
150+
result = bt_sub.register_subnet(
152151
wallet=owner_wallet,
153152
prompt=False,
154153
)
@@ -165,7 +164,7 @@ def ensure_wallet(name: str, hotkey: str = "default") -> bt.Wallet:
165164
w = wallets[wallet_name]
166165
hk = w.hotkey.ss58_address
167166
try:
168-
if bt_sub.is_hotkey_registered(netuid=NETUID, hotkey_ss58=hk):
167+
if bt_sub.is_hotkey_registered_on_subnet(hotkey_ss58=hk, netuid=NETUID):
169168
ok(f"{wallet_name}: already registered on subnet {NETUID}")
170169
continue
171170
except Exception:

miner.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,16 @@ def run(self):
285285
self.axon.start()
286286
bt.logging.success(f"Axon started on port {self.axon.port}")
287287

288+
# Sync metagraph immediately so the blacklist can pass validator hotkeys
289+
# from the first request onward (before serve_axon's inclusion wait).
290+
try:
291+
self.metagraph.sync(subtensor=self.subtensor)
292+
bt.logging.info(
293+
f"Metagraph synced at startup: {len(self.metagraph.hotkeys)} hotkeys"
294+
)
295+
except Exception as e:
296+
bt.logging.warning(f"Initial metagraph sync failed ({e}) — blacklist may reject early requests")
297+
288298
# Announce axon to chain — retry once, but never abort if it fails.
289299
# On local --dev nodes serve_axon may return Custom Error 10 if the
290300
# subnet was just created and state is still settling; the axon is
@@ -313,10 +323,10 @@ def run(self):
313323
try:
314324
if step % 5 == 0:
315325
self.metagraph.sync(subtensor=self.subtensor)
316-
bt.logging.info(
317-
f"[step={step}] NTS={self.oap.get_nts(self.agent_id_hex):.1f} "
318-
f"counter={self.counter}"
319-
)
326+
bt.logging.info(
327+
f"[step={step}] NTS={self.oap.get_nts(self.agent_id_hex):.1f} "
328+
f"counter={self.counter} | hotkeys={len(self.metagraph.hotkeys)}"
329+
)
320330
step += 1
321331
time.sleep(12)
322332
except KeyboardInterrupt:

0 commit comments

Comments
 (0)