Skip to content
Merged

. #2

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion allways/cli/dendrite_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ def get_ephemeral_wallet() -> bt.Wallet:
return wallet


def discover_validators(subtensor: bt.Subtensor, netuid: int) -> list:
def discover_validators(subtensor: bt.Subtensor, netuid: int, contract_client=None) -> list:
"""Discover validator axon endpoints from metagraph.

Filters for UIDs with validator_permit=True and is_serving=True.
When contract_client is provided, also filters to only whitelisted validators.
Returns list of axon endpoints.
"""
metagraph = subtensor.metagraph(netuid=netuid)
Expand All @@ -49,6 +50,12 @@ def discover_validators(subtensor: bt.Subtensor, netuid: int) -> list:
axon = metagraph.axons[uid]
if not axon.is_serving:
continue
if contract_client:
try:
if not contract_client.is_validator(metagraph.hotkeys[uid]):
continue
except Exception:
pass
axons.append(axon)

return axons
Expand Down
9 changes: 3 additions & 6 deletions allways/cli/swap_commands/miner_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import rich_click as click
from rich.table import Table

from allways.cli.dendrite_lite import discover_validators
from allways.cli.swap_commands.helpers import (
SWAP_STATUS_COLORS,
console,
Expand Down Expand Up @@ -176,13 +177,9 @@ def miner_activate():

synapse = MinerActivateSynapse(hotkey=hotkey, signature=signature, message=message)

# Discover validators from metagraph
metagraph = subtensor.metagraph(netuid=netuid)
# Discover whitelisted validators from metagraph
dendrite = bt.Dendrite(wallet=wallet)

validator_axons = [
axon for uid, axon in enumerate(metagraph.axons) if metagraph.validator_permit[uid] and axon.is_serving
]
validator_axons = discover_validators(subtensor, netuid, contract_client=client)

if not validator_axons:
console.print('[red]No validators found on metagraph[/red]\n')
Expand Down
2 changes: 1 addition & 1 deletion allways/cli/swap_commands/post_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def post_tx_command(tx_hash: str, netuid: int):
source_key = wallet.coldkey if state.source_chain == 'tao' else None

# Discover validators
validator_axons = discover_validators(subtensor, netuid)
validator_axons = discover_validators(subtensor, netuid, contract_client=client)
if not validator_axons:
console.print('[red]No validators found on metagraph[/red]')
return
Expand Down
2 changes: 1 addition & 1 deletion allways/cli/swap_commands/swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def broadcast_reserve_with_retry(
)

ephemeral_wallet = get_ephemeral_wallet()
validator_axons = discover_validators(subtensor, netuid)
validator_axons = discover_validators(subtensor, netuid, contract_client=client)
if not validator_axons:
console.print('[red]No validators found on metagraph[/red]')
return None
Expand Down
Loading