Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #245 from blockchain-insights/feat/upgrade2.2_bt7.0
Browse files Browse the repository at this point in the history
Updating to bittensor 7.0
  • Loading branch information
aph5nt authored Jun 4, 2024
2 parents b698b73 + 63abaa3 commit 42d135a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion insights/api/insight_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import yaml

import numpy as np
from typing import List, Dict, Tuple, Union, Any
from protocols.chat import ChatMessageRequest, ChatMessageResponse, ChatMessageVariantRequest, ContentType
from fastapi.middleware.cors import CORSMiddleware
from starlette.requests import Request
Expand Down Expand Up @@ -154,7 +155,6 @@ def __init__(
wallet: None,
subtensor: None,
metagraph: None,
scores: None,
):
"""
API can be invoked while running a validator.
Expand Down
36 changes: 15 additions & 21 deletions neurons/validators/utils/uids.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ def check_uid_availability(
# Available otherwise.
return True

def get_top_miner_uids(
metagraph: "bt.metagraph.Metagraph", top_rate: float = 1, exclude: List[int] = None, vpermit_tao_limit: int = 4096
) -> np.int64:
async def get_top_miner_uids(metagraph: "bt.metagraph.Metagraph",
wallet: "bt.wallet.Wallet",
top_rate: float = 1,
vpermit_tao_limit: int = 4096) -> np.int64:

"""Returns the available top miner UID from the metagraph.
Args:
metagraph (bt.metagraph.Metagraph): Metagraph object
Expand All @@ -50,9 +52,8 @@ def get_top_miner_uids(
Returns:
top_miner_uid (np.int64): The top miner UID.
"""

dendrite = bt.dendrite(wallet=wallet)
try:
dendrite = bt.dendrite(wallet=wallet)
miner_candidate_uids = []
for uid in range(metagraph.n.item()):
uid_is_available = check_uid_availability(
Expand All @@ -73,22 +74,15 @@ def get_top_miner_uids(

# Consider both of incentive and trust score
values = [(uid, metagraph.I[uid] * metagraph.trust[uid]) for uid in miner_ip_filtered_uids]

# Consider only incentive
# values = [(uid, metagraph.I[uid]) for uid in candidate_uids]

ips = []
filtered_uids = []
for uid, _ in sorted_values:
if metagraph.axons[uid].ip not in ips:
ips.append(metagraph.axons[uid].ip)
filtered_uids.append(uid)

values = [(uid, metagraph.I[uid] * metagraph.trust[uid]) for uid in filtered_uids]
sorted_values = sorted(values, key=lambda x: x[1], reverse=True)
top_rate_num_items = max(1, int(top_rate * len(filtered_uids)))
top_miner_uids = np.array([uid for uid, _ in sorted_values[:top_rate_num_items]])
return top_miner_uids
sorted_values = sorted(values, key=lambda x: x[1], reverse=True)
top_rate_num_items = max(1, int(top_rate * len(miner_ip_filtered_uids)))
top_miner_uids = np.array([uid for uid, _ in sorted_values[:top_rate_num_items]])
return top_miner_uids
except Exception as e:
logger.error(message=f"Failed to get top miner uids: {e}")
return None
finally:
dendrite.close_session()


def get_random_uids(
Expand Down

0 comments on commit 42d135a

Please sign in to comment.