Skip to content

Commit 6eb287a

Browse files
committed
fix(weight-submit): create fresh Bittensor connection for each submission
- Store config (endpoint, netuid, signer_seed) instead of persistent connection - Create fresh SubtensorClient in fetch_and_submit() for each hourly submission - Connection automatically dropped after each submission - Prevents stale connection issues - each submission starts fresh - CRv4 commit-reveal still works via WeightSubmitter
1 parent 08dbe65 commit 6eb287a

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

bins/validator-node/src/standalone_weight_submitter.rs

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ struct WeightEntry {
5757
/// Standalone weight submitter - no P2P dependencies
5858
/// Uses WeightSubmitter internally for CRv4 commit-reveal support
5959
pub struct StandaloneWeightSubmitter {
60-
weight_submitter: Arc<Mutex<WeightSubmitter>>,
60+
// Configuration stored to create fresh connections
61+
endpoint: String,
62+
netuid: u16,
63+
signer_seed: String,
6164
http_client: Client,
6265
last_submission_hour: Arc<Mutex<Option<i64>>>,
6366
running: Arc<AtomicBool>,
@@ -74,21 +77,16 @@ impl StandaloneWeightSubmitter {
7477
.build()
7578
.expect("Failed to create HTTP client");
7679

77-
let config = BittensorConfig {
78-
endpoint: endpoint.to_string(),
80+
info!(
81+
endpoint = %endpoint,
7982
netuid,
80-
use_commit_reveal: true,
81-
version_key: 1,
82-
};
83-
84-
let mut client = SubtensorClient::new(config);
85-
client.connect().await?;
86-
client.set_signer(signer_seed)?;
87-
88-
let weight_submitter = WeightSubmitter::new(client, None);
83+
"Standalone weight submitter initialized (will create fresh connection for each submission)"
84+
);
8985

9086
Ok(Self {
91-
weight_submitter: Arc::new(Mutex::new(weight_submitter)),
87+
endpoint: endpoint.to_string(),
88+
netuid,
89+
signer_seed: signer_seed.to_string(),
9290
http_client,
9391
last_submission_hour: Arc::new(Mutex::new(None)),
9492
running: Arc::new(AtomicBool::new(true)),
@@ -193,8 +191,29 @@ impl StandaloneWeightSubmitter {
193191
})
194192
.collect();
195193

196-
let mut submitter = self.weight_submitter.lock().await;
197-
submitter.submit_mechanism_weights_batch(&mechanism_weights).await?;
194+
// Create FRESH Bittensor connection for this submission
195+
info!(endpoint = %self.endpoint, "Creating fresh Bittensor connection...");
196+
197+
let config = BittensorConfig {
198+
endpoint: self.endpoint.clone(),
199+
netuid: self.netuid,
200+
use_commit_reveal: true,
201+
version_key: 1,
202+
};
203+
204+
let mut client = SubtensorClient::new(config);
205+
client.connect().await
206+
.map_err(|e| anyhow::anyhow!("Bittensor connection failed to {}: {}", self.endpoint, e))?;
207+
client.set_signer(&self.signer_seed)
208+
.map_err(|e| anyhow::anyhow!("Failed to set signer: {}", e))?;
209+
210+
let mut weight_submitter = WeightSubmitter::new(client, None);
211+
212+
weight_submitter.submit_mechanism_weights_batch(&mechanism_weights).await?;
213+
214+
info!("Weights submitted successfully, connection will be dropped");
215+
216+
// Connection is automatically dropped when weight_submitter goes out of scope
198217

199218
Ok(())
200219
}

0 commit comments

Comments
 (0)