Skip to content

Commit

Permalink
🩹 retrying with a different node when set weight fails
Browse files Browse the repository at this point in the history
  • Loading branch information
PsicoThePato committed May 26, 2024
1 parent c8a391d commit a7446ca
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/synthia/validator/text_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from communex.types import Ss58Address # type: ignore
from fuzzywuzzy import fuzz # type: ignore
from substrateinterface import Keypair # type: ignore
from time import sleep

from ..miner._config import AnthropicSettings, OpenrouterSettings
from ..miner.anthropic import AnthropicModule, OpenrouterModule
Expand Down Expand Up @@ -68,8 +69,15 @@ def set_weights(
uids = list(weighted_scores.keys())
weights = list(weighted_scores.values())
log(f"Settings weights for the following uids: {uids}")
client.vote(key=key, uids=uids, weights=weights, netuid=netuid)

try:
client.vote(key=key, uids=uids, weights=weights, netuid=netuid)
except Exception as e:
log(f"WARNING: Failed to set weights with exception: {e}. Will retry.")
sleep_time = random.uniform(1, 2)
sleep(sleep_time)
# retry with a different node
client = CommuneClient(get_node_url())
client.vote(key=key, uids=uids, weights=weights, netuid=netuid)

def cut_to_max_allowed_weights(
score_dict: dict[int, float], settings: ValidatorSettings | None = None
Expand Down

0 comments on commit a7446ca

Please sign in to comment.