From 3b086787f254aa4d208b0d245bd2f3217101a682 Mon Sep 17 00:00:00 2001 From: hscott Date: Thu, 5 Dec 2024 15:56:39 -0500 Subject: [PATCH] set block update to before weight setting code in set_weights loop --- precog/utils/bittensor.py | 2 +- precog/validators/weight_setter.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/precog/utils/bittensor.py b/precog/utils/bittensor.py index 29256de..844ff70 100644 --- a/precog/utils/bittensor.py +++ b/precog/utils/bittensor.py @@ -13,7 +13,7 @@ def setup_bittensor_objects(self): # if chain endpoint is set, overwrite network arg self.config.subtensor.network = self.config.subtensor.chain_endpoint # Initialize subtensor. - self.subtensor = bt.subtensor(config=self.config, chain_endpoint=self.config.subtensor.chain_endpoint) + self.subtensor = bt.subtensor(config=self.config, network=self.config.subtensor.chain_endpoint) self.metagraph = self.subtensor.metagraph(self.config.netuid) self.wallet = bt.wallet(config=self.config) self.dendrite = bt.dendrite(wallet=self.wallet) diff --git a/precog/validators/weight_setter.py b/precog/validators/weight_setter.py index d3f08fb..a704bd1 100755 --- a/precog/validators/weight_setter.py +++ b/precog/validators/weight_setter.py @@ -116,6 +116,13 @@ def node_query(self, module, method, params): return result async def set_weights(self): + try: + self.current_block = self.subtensor.get_current_block() + self.blocks_since_last_update = ( + self.current_block - self.node_query("SubtensorModule", "LastUpdate", [self.config.netuid])[self.my_uid] + ) + except Exception: + bt.logging.error("Failed to get current block, skipping block update") if self.blocks_since_last_update >= self.set_weights_rate: uids = array(self.available_uids) weights = [self.moving_average_scores[uid] for uid in self.available_uids] @@ -144,13 +151,6 @@ async def set_weights(self): "Failed to set weights this iteration with message:", msg, ) - try: - self.current_block = self.subtensor.get_current_block() - self.blocks_since_last_update = ( - self.current_block - self.node_query("SubtensorModule", "LastUpdate", [self.config.netuid])[self.my_uid] - ) - except Exception: - bt.logging.error("Failed to get current block, skipping block update") async def scheduled_prediction_request(self): if not hasattr(self, "timestamp"):