Skip to content

Commit a00e87d

Browse files
author
Roman
committed
Merge remote-tracking branch 'origin/feat/roman/selective-metagraph' into feat/roman/selective-metagraph
2 parents caed733 + 050a578 commit a00e87d

File tree

2 files changed

+141
-91
lines changed

2 files changed

+141
-91
lines changed

bittensor/core/async_subtensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,9 +1494,9 @@ async def get_metagraph_info(
14941494
with the given netuid does not exist.
14951495
14961496
Example:
1497-
meta_info = subtensor.get_metagraph_info(netuid=2)
1497+
meta_info = await subtensor.get_metagraph_info(netuid=2)
14981498
1499-
partial_meta_info = subtensor.get_metagraph_info(
1499+
partial_meta_info = await subtensor.get_metagraph_info(
15001500
netuid=2,
15011501
field_indices=[SelectiveMetagraphIndex.Name, SelectiveMetagraphIndex.OwnerHotkeys]
15021502
)

bittensor/core/chain_data/metagraph_info.py

Lines changed: 139 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,16 @@ def _from_dict(cls, decoded: dict) -> "MetagraphInfo":
177177
identity=decoded["identity"],
178178
network_registered_at=decoded["network_registered_at"],
179179
# Keys for owner.
180-
owner_hotkey=decode_account_id(decoded["owner_hotkey"][0])
181-
if decoded.get("owner_hotkey") is not None
182-
else None,
183-
owner_coldkey=decode_account_id(decoded["owner_coldkey"][0])
184-
if decoded.get("owner_coldkey") is not None
185-
else None,
180+
owner_hotkey=(
181+
decode_account_id(decoded["owner_hotkey"][0])
182+
if decoded.get("owner_hotkey") is not None
183+
else None
184+
),
185+
owner_coldkey=(
186+
decode_account_id(decoded["owner_coldkey"][0])
187+
if decoded.get("owner_coldkey") is not None
188+
else None
189+
),
186190
# Tempo terms.
187191
block=decoded["block"],
188192
tempo=decoded["tempo"],
@@ -199,21 +203,25 @@ def _from_dict(cls, decoded: dict) -> "MetagraphInfo":
199203
pending_alpha_emission=_tbwu(decoded["pending_alpha_emission"], _netuid),
200204
pending_root_emission=_tbwu(decoded["pending_root_emission"]),
201205
subnet_volume=_tbwu(decoded["subnet_volume"], _netuid),
202-
moving_price=Balance.from_tao(
203-
fixed_to_float(decoded.get("moving_price"), 32)
204-
)
205-
if decoded.get("moving_price") is not None
206-
else None,
206+
moving_price=(
207+
Balance.from_tao(fixed_to_float(decoded.get("moving_price"), 32))
208+
if decoded.get("moving_price") is not None
209+
else None
210+
),
207211
# Hparams for epoch
208212
rho=decoded["rho"],
209213
kappa=decoded["kappa"],
210214
# Validator params
211-
min_allowed_weights=u16tf(decoded["min_allowed_weights"])
212-
if decoded.get("min_allowed_weights") is not None
213-
else None,
214-
max_weights_limit=u16tf(decoded["max_weights_limit"])
215-
if decoded["max_weights_limit"] is not None
216-
else None,
215+
min_allowed_weights=(
216+
u16tf(decoded["min_allowed_weights"])
217+
if decoded.get("min_allowed_weights") is not None
218+
else None
219+
),
220+
max_weights_limit=(
221+
u16tf(decoded["max_weights_limit"])
222+
if decoded["max_weights_limit"] is not None
223+
else None
224+
),
217225
weights_version=decoded["weights_version"],
218226
weights_rate_limit=decoded["weights_rate_limit"],
219227
activity_cutoff=decoded["activity_cutoff"],
@@ -222,23 +230,31 @@ def _from_dict(cls, decoded: dict) -> "MetagraphInfo":
222230
num_uids=decoded["num_uids"],
223231
max_uids=decoded["max_uids"],
224232
burn=_tbwu(decoded["burn"]),
225-
difficulty=u64tf(decoded["difficulty"])
226-
if decoded["difficulty"] is not None
227-
else None,
233+
difficulty=(
234+
u64tf(decoded["difficulty"])
235+
if decoded["difficulty"] is not None
236+
else None
237+
),
228238
registration_allowed=decoded["registration_allowed"],
229239
pow_registration_allowed=decoded["pow_registration_allowed"],
230240
immunity_period=decoded["immunity_period"],
231-
min_difficulty=u64tf(decoded["min_difficulty"])
232-
if decoded["min_difficulty"] is not None
233-
else None,
234-
max_difficulty=u64tf(decoded["max_difficulty"])
235-
if decoded["max_difficulty"] is not None
236-
else None,
241+
min_difficulty=(
242+
u64tf(decoded["min_difficulty"])
243+
if decoded["min_difficulty"] is not None
244+
else None
245+
),
246+
max_difficulty=(
247+
u64tf(decoded["max_difficulty"])
248+
if decoded["max_difficulty"] is not None
249+
else None
250+
),
237251
min_burn=_tbwu(decoded["min_burn"]),
238252
max_burn=_tbwu(decoded["max_burn"]),
239-
adjustment_alpha=u64tf(decoded["adjustment_alpha"])
240-
if decoded["adjustment_alpha"] is not None
241-
else None,
253+
adjustment_alpha=(
254+
u64tf(decoded["adjustment_alpha"])
255+
if decoded["adjustment_alpha"] is not None
256+
else None
257+
),
242258
adjustment_interval=decoded["adjustment_interval"],
243259
target_regs_per_interval=decoded["target_regs_per_interval"],
244260
max_regs_per_block=decoded["max_regs_per_block"],
@@ -248,74 +264,108 @@ def _from_dict(cls, decoded: dict) -> "MetagraphInfo":
248264
commit_reveal_period=decoded["commit_reveal_period"],
249265
# Bonds
250266
liquid_alpha_enabled=decoded["liquid_alpha_enabled"],
251-
alpha_high=u16tf(decoded["alpha_high"])
252-
if decoded["alpha_high"] is not None
253-
else None,
254-
alpha_low=u16tf(decoded["alpha_low"])
255-
if decoded["alpha_low"] is not None
256-
else None,
257-
bonds_moving_avg=u64tf(decoded["bonds_moving_avg"])
258-
if decoded["bonds_moving_avg"] is not None
259-
else None,
267+
alpha_high=(
268+
u16tf(decoded["alpha_high"])
269+
if decoded["alpha_high"] is not None
270+
else None
271+
),
272+
alpha_low=(
273+
u16tf(decoded["alpha_low"])
274+
if decoded["alpha_low"] is not None
275+
else None
276+
),
277+
bonds_moving_avg=(
278+
u64tf(decoded["bonds_moving_avg"])
279+
if decoded["bonds_moving_avg"] is not None
280+
else None
281+
),
260282
# Metagraph info.
261-
hotkeys=[decode_account_id(ck) for ck in decoded.get("hotkeys", [])]
262-
if decoded.get("hotkeys") is not None
263-
else None,
264-
coldkeys=[decode_account_id(hk) for hk in decoded.get("coldkeys", [])]
265-
if decoded.get("coldkeys") is not None
266-
else None,
283+
hotkeys=(
284+
[decode_account_id(ck) for ck in decoded.get("hotkeys", [])]
285+
if decoded.get("hotkeys") is not None
286+
else None
287+
),
288+
coldkeys=(
289+
[decode_account_id(hk) for hk in decoded.get("coldkeys", [])]
290+
if decoded.get("coldkeys") is not None
291+
else None
292+
),
267293
identities=decoded["identities"],
268294
axons=decoded.get("axons", []),
269295
active=decoded["active"],
270296
validator_permit=decoded["validator_permit"],
271-
pruning_score=[u16tf(ps) for ps in decoded.get("pruning_score", [])]
272-
if decoded.get("pruning_score") is not None
273-
else None,
297+
pruning_score=(
298+
[u16tf(ps) for ps in decoded.get("pruning_score", [])]
299+
if decoded.get("pruning_score") is not None
300+
else None
301+
),
274302
last_update=decoded["last_update"],
275-
emission=[_tbwu(em, _netuid) for em in decoded.get("emission", [])]
276-
if decoded.get("emission") is not None
277-
else None,
278-
dividends=[u16tf(dv) for dv in decoded.get("dividends", [])]
279-
if decoded.get("dividends") is not None
280-
else None,
281-
incentives=[u16tf(ic) for ic in decoded.get("incentives", [])]
282-
if decoded.get("incentives") is not None
283-
else None,
284-
consensus=[u16tf(cs) for cs in decoded.get("consensus", [])]
285-
if decoded.get("consensus") is not None
286-
else None,
287-
trust=[u16tf(tr) for tr in decoded.get("trust", [])]
288-
if decoded.get("trust") is not None
289-
else None,
290-
rank=[u16tf(rk) for rk in decoded.get("rank", [])]
291-
if decoded.get("rank") is not None
292-
else None,
303+
emission=(
304+
[_tbwu(em, _netuid) for em in decoded.get("emission", [])]
305+
if decoded.get("emission") is not None
306+
else None
307+
),
308+
dividends=(
309+
[u16tf(dv) for dv in decoded.get("dividends", [])]
310+
if decoded.get("dividends") is not None
311+
else None
312+
),
313+
incentives=(
314+
[u16tf(ic) for ic in decoded.get("incentives", [])]
315+
if decoded.get("incentives") is not None
316+
else None
317+
),
318+
consensus=(
319+
[u16tf(cs) for cs in decoded.get("consensus", [])]
320+
if decoded.get("consensus") is not None
321+
else None
322+
),
323+
trust=(
324+
[u16tf(tr) for tr in decoded.get("trust", [])]
325+
if decoded.get("trust") is not None
326+
else None
327+
),
328+
rank=(
329+
[u16tf(rk) for rk in decoded.get("rank", [])]
330+
if decoded.get("rank") is not None
331+
else None
332+
),
293333
block_at_registration=decoded["block_at_registration"],
294-
alpha_stake=[_tbwu(ast, _netuid) for ast in decoded["alpha_stake"]]
295-
if decoded.get("alpha_stake") is not None
296-
else None,
297-
tao_stake=[
298-
_tbwu(ts) * settings.ROOT_TAO_STAKE_WEIGHT
299-
for ts in decoded["tao_stake"]
300-
]
301-
if decoded.get("tao_stake") is not None
302-
else None,
303-
total_stake=[_tbwu(ts, _netuid) for ts in decoded["total_stake"]]
304-
if decoded.get("total_stake") is not None
305-
else None,
334+
alpha_stake=(
335+
[_tbwu(ast, _netuid) for ast in decoded["alpha_stake"]]
336+
if decoded.get("alpha_stake") is not None
337+
else None
338+
),
339+
tao_stake=(
340+
[
341+
_tbwu(ts) * settings.ROOT_TAO_STAKE_WEIGHT
342+
for ts in decoded["tao_stake"]
343+
]
344+
if decoded.get("tao_stake") is not None
345+
else None
346+
),
347+
total_stake=(
348+
[_tbwu(ts, _netuid) for ts in decoded["total_stake"]]
349+
if decoded.get("total_stake") is not None
350+
else None
351+
),
306352
# Dividend break down
307-
tao_dividends_per_hotkey=[
308-
(decode_account_id(alpha[0]), _tbwu(alpha[1]))
309-
for alpha in decoded["tao_dividends_per_hotkey"]
310-
]
311-
if decoded.get("tao_dividends_per_hotkey") is not None
312-
else None,
313-
alpha_dividends_per_hotkey=[
314-
(decode_account_id(adphk[0]), _tbwu(adphk[1], _netuid))
315-
for adphk in decoded["alpha_dividends_per_hotkey"]
316-
]
317-
if decoded.get("alpha_dividends_per_hotkey") is not None
318-
else None,
353+
tao_dividends_per_hotkey=(
354+
[
355+
(decode_account_id(alpha[0]), _tbwu(alpha[1]))
356+
for alpha in decoded["tao_dividends_per_hotkey"]
357+
]
358+
if decoded.get("tao_dividends_per_hotkey") is not None
359+
else None
360+
),
361+
alpha_dividends_per_hotkey=(
362+
[
363+
(decode_account_id(adphk[0]), _tbwu(adphk[1], _netuid))
364+
for adphk in decoded["alpha_dividends_per_hotkey"]
365+
]
366+
if decoded.get("alpha_dividends_per_hotkey") is not None
367+
else None
368+
),
319369
)
320370

321371

0 commit comments

Comments
 (0)