diff --git a/neurons/validator.py b/neurons/validator.py index efc2f7d..4a348a4 100644 --- a/neurons/validator.py +++ b/neurons/validator.py @@ -71,18 +71,11 @@ def __init__(self, config=None): self.load_state() self.miner_data_handler = MinerDataHandler() - self.price_data_provider = PriceDataProvider() + self.price_data_provider = PriceDataProvider(self.asset_list) self.scheduler = sched.scheduler(time.time, time.sleep) self.miner_uids: list[int] = [] - self.assert_assets_supported() - - def assert_assets_supported(self): - # Assert assets are all implemented in the price data provider: - for asset in self.asset_list: - assert asset in PriceDataProvider.TOKEN_MAP - def forward_validator(self): """ Validator forward pass. Consists of: @@ -181,16 +174,6 @@ def cycle_high_frequency(self, asset: str): cycle_start_time = get_current_time() self.forward_prompt(asset, HIGH_FREQUENCY) - - current_time = get_current_time() - scored_time: datetime = round_time_to_minutes(current_time) - bt.logging.info(f"forward score {HIGH_FREQUENCY.label} frequency") - calculate_scores( - self.miner_data_handler, - self.price_data_provider, - scored_time, - HIGH_FREQUENCY, - ) self.schedule_cycle(cycle_start_time, HIGH_FREQUENCY) def forward_prompt(self, asset: str, prompt_config: PromptConfig): @@ -224,10 +207,6 @@ def forward_prompt(self, asset: str, prompt_config: PromptConfig): ) def forward_score_low_frequency(self): - bt.logging.info(f"forward score {LOW_FREQUENCY.label} frequency") - current_time = get_current_time() - scored_time: datetime = round_time_to_minutes(current_time) - # ================= Step 3 ================= # # Calculate rewards based on historical predictions data # from the miner_predictions table: @@ -237,6 +216,10 @@ def forward_score_low_frequency(self): # we store the rewards in the miner_scores table # ========================================== # + bt.logging.info(f"forward score {LOW_FREQUENCY.label} frequency") + current_time = get_current_time() + scored_time: datetime = round_time_to_minutes(current_time) + success = calculate_scores( self.miner_data_handler, self.price_data_provider, @@ -244,6 +227,19 @@ def forward_score_low_frequency(self): LOW_FREQUENCY, ) + if not success: + return + + scored_time: datetime = round_time_to_minutes(current_time) + current_time = get_current_time() + bt.logging.info(f"forward score {HIGH_FREQUENCY.label} frequency") + success = calculate_scores( + self.miner_data_handler, + self.price_data_provider, + scored_time, + HIGH_FREQUENCY, + ) + if not success: return diff --git a/synth/base/dendrite.py b/synth/base/dendrite.py index ee7f5d0..8520709 100644 --- a/synth/base/dendrite.py +++ b/synth/base/dendrite.py @@ -1,5 +1,3 @@ -import sys -import traceback from typing import List, Optional, Tuple, Type, Union import time import asyncio @@ -268,5 +266,4 @@ def log_exception(exception: Exception): # bt.logging.trace(f"{error_type}#{error_id}: {exception}") pass else: - bt.logging.error(f"{error_type}#{error_id}: {exception}") - traceback.print_exc(file=sys.stderr) + bt.logging.exception(f"{error_type}#{error_id}: {exception}") diff --git a/synth/base/miner.py b/synth/base/miner.py index 257c390..01c6097 100644 --- a/synth/base/miner.py +++ b/synth/base/miner.py @@ -19,7 +19,6 @@ import asyncio import threading import argparse -import traceback import bittensor as bt @@ -138,7 +137,7 @@ def run(self): # In case of unforeseen errors, the miner will log the error and continue operations. except Exception: - bt.logging.error(traceback.format_exc()) + bt.logging.exception("Unknown error") def run_in_background_thread(self): """ diff --git a/synth/base/validator.py b/synth/base/validator.py index 1544db1..cf0d1fb 100644 --- a/synth/base/validator.py +++ b/synth/base/validator.py @@ -18,7 +18,6 @@ # DEALINGS IN THE SOFTWARE. -import sys import copy import numpy as np import asyncio @@ -27,7 +26,6 @@ import bittensor as bt from typing import List, Union -import traceback from synth.base.dendrite import SynthDendrite from synth.base.neuron import BaseNeuron @@ -132,13 +130,11 @@ def run(self): if not self.config.neuron.axon_off: self.axon.stop() bt.logging.success("Validator killed by keyboard interrupt.") - traceback.print_exc(file=sys.stderr) exit() # In case of unforeseen errors, the validator will log the error and continue operations. - except Exception as err: - bt.logging.error(f"Error during validation: {str(err)}") - traceback.print_exc(file=sys.stderr) + except Exception: + bt.logging.exception("Error during validation") def set_weights(self): """ diff --git a/synth/validator/miner_data_handler.py b/synth/validator/miner_data_handler.py index 9ce07cb..77298d6 100644 --- a/synth/validator/miner_data_handler.py +++ b/synth/validator/miner_data_handler.py @@ -1,6 +1,4 @@ from datetime import datetime, timedelta -import traceback -import sys import typing import logging import math @@ -102,8 +100,7 @@ def get_latest_asset(self, time_length: int) -> str | None: return str(result[0].asset) except Exception as e: - bt.logging.error(f"in get_next_asset (got an exception): {e}") - traceback.print_exc(file=sys.stderr) + bt.logging.exception(f"in get_next_asset (got an exception): {e}") return None @retry( @@ -180,8 +177,7 @@ def save_responses( connection.execute(insert_stmt_miner_predictions) return validator_requests_id # TODO: finish this: refactor to add the validator_requests_id in the score and reward table except Exception as e: - bt.logging.error(f"in save_responses (got an exception): {e}") - traceback.print_exc(file=sys.stderr) + bt.logging.exception(f"in save_responses (got an exception): {e}") @retry( stop=stop_after_attempt(5), @@ -260,8 +256,9 @@ def set_miner_scores( ) connection.execute(insert_stmt_miner_scores) except Exception as e: - bt.logging.error(f"in set_miner_scores (got an exception): {e}") - traceback.print_exc(file=sys.stderr) + bt.logging.exception( + f"in set_miner_scores (got an exception): {e}" + ) def get_miner_uid_of_prediction_request( self, validator_request_id: int @@ -291,10 +288,9 @@ def get_miner_uid_of_prediction_request( return result except Exception as e: - bt.logging.error( + bt.logging.exception( f"in get_miner_uid_of_prediction_request (got an exception): {e}" ) - traceback.print_exc(file=sys.stderr) return None def get_miner_prediction( @@ -333,10 +329,9 @@ def get_miner_prediction( return result except Exception as e: - bt.logging.error( + bt.logging.exception( f"in get_miner_prediction (got an exception): {e}" ) - traceback.print_exc(file=sys.stderr) return None def get_validator_requests_to_score( @@ -418,10 +413,9 @@ def get_validator_requests_to_score( return results except Exception as e: - bt.logging.error( + bt.logging.exception( f"in get_latest_prediction_request (got an exception): {e}" ) - traceback.print_exc(file=sys.stderr) return None @retry( @@ -456,8 +450,9 @@ def insert_new_miners(self, metagraph_info: list): ) connection.execute(insert_stmt) except Exception as e: - bt.logging.error(f"in insert_new_miners (got an exception): {e}") - traceback.print_exc(file=sys.stderr) + bt.logging.exception( + f"in insert_new_miners (got an exception): {e}" + ) def update_metagraph_history(self, metagraph_info: list): try: @@ -468,10 +463,9 @@ def update_metagraph_history(self, metagraph_info: list): ) connection.execute(insert_stmt) except Exception as e: - bt.logging.error( + bt.logging.exception( f"in update_metagraph_history (got an exception): {e}" ) - traceback.print_exc(file=sys.stderr) def get_miner_scores( self, @@ -515,8 +509,9 @@ def get_miner_scores( return pd.DataFrame(result.fetchall(), columns=list(result.keys())) except Exception as e: - bt.logging.error(f"in get_miner_scores (got an exception): {e}") - traceback.print_exc(file=sys.stderr) + bt.logging.exception( + f"in get_miner_scores (got an exception): {e}" + ) return pd.DataFrame() def populate_miner_uid_in_miner_data(self, miner_data: list[dict]): @@ -525,10 +520,9 @@ def populate_miner_uid_in_miner_data(self, miner_data: list[dict]): with connection.begin(): miner_uid_map = self.get_miner_ids_map(connection) except Exception as e: - bt.logging.error( + bt.logging.exception( f"in populate_miner_uid_in_miner_data (got an exception): {e}" ) - traceback.print_exc(file=sys.stderr) return None for row in miner_data: @@ -554,10 +548,9 @@ def update_miner_rewards(self, miner_rewards_data: list[dict]): ) connection.execute(insert_stmt) except Exception as e: - bt.logging.error( + bt.logging.exception( f"in update_miner_rewards (got an exception): {e}" ) - traceback.print_exc(file=sys.stderr) def update_weights_history( self, @@ -585,7 +578,6 @@ def update_weights_history( ) connection.execute(insert_stmt) except Exception as e: - bt.logging.error( + bt.logging.exception( f"in update_weights_history (got an exception): {e}" ) - traceback.print_exc(file=sys.stderr) diff --git a/synth/validator/price_data_provider.py b/synth/validator/price_data_provider.py index aeb79f1..658b83b 100644 --- a/synth/validator/price_data_provider.py +++ b/synth/validator/price_data_provider.py @@ -31,6 +31,14 @@ class PriceDataProvider: "SOL": "Crypto.SOL/USD", } + def __init__(self, asset_list: list[str] = []): + self.assert_assets_supported(asset_list) + + def assert_assets_supported(self, asset_list: list[str]): + # Assert assets are all implemented in the price data provider: + for asset in asset_list: + assert asset in self.TOKEN_MAP + @retry( stop=stop_after_attempt(5), wait=wait_random_exponential(multiplier=7),