From f3bb3260d17e34ef71594ed7d53e07dca68cfcff Mon Sep 17 00:00:00 2001 From: Terry Tipton Date: Tue, 28 Apr 2026 18:53:49 -0400 Subject: [PATCH] refactor: inline single-use _reconnect_subtensor helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _reconnect_subtensor was a 3-line method on BaseNeuron called from exactly one place — the ConnectionClosedError retry branch in check_registered. Inlining matches the merged #748 / #801 pattern (single-use private helper folded into its only caller); the inlined two lines (info log + Subtensor instantiation) read just as cleanly in the retry context. `grep -rn _reconnect_subtensor` confirms no other call sites in gittensor/, neurons/, or tests/. -6/+2 lines, full test suite passes. --- neurons/base/neuron.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/neurons/base/neuron.py b/neurons/base/neuron.py index 28ff38c77..3dcfa70fb 100644 --- a/neurons/base/neuron.py +++ b/neurons/base/neuron.py @@ -97,11 +97,6 @@ def __init__(self, config=None): ) self.step = 0 - def _reconnect_subtensor(self): - """Recreate subtensor connection when WebSocket goes stale.""" - bt.logging.info('Reconnecting subtensor...') - self.subtensor = bt.Subtensor(config=self.config) - @abstractmethod async def forward(self, synapse: bt.Synapse) -> bt.Synapse: ... @@ -143,7 +138,8 @@ def check_registered(self, max_retries: int = 3): f'WebSocket connection closed during check_registered (attempt {attempt + 1}/{max_retries}): {e}' ) if attempt < max_retries - 1: - self._reconnect_subtensor() + bt.logging.info('Reconnecting subtensor...') + self.subtensor = bt.Subtensor(config=self.config) time.sleep(2**attempt) # Exponential backoff: 1s, 2s, 4s else: raise