Skip to content

Commit 3a816d9

Browse files
authored
Resolve unconditional sn2-relay connection for non-mainnet validators (#433)
1 parent 59dc7ac commit 3a816d9

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

crates/sn2-validator/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct ValidatorConfig {
1818
pub user_uid: u16,
1919
pub relay_enabled: bool,
2020
pub relay_url: String,
21+
pub relay_url_override: bool,
2122
pub api_miners_pct: u32,
2223
pub disable_benchmark: bool,
2324
pub metrics_port: u16,
@@ -80,6 +81,7 @@ impl ValidatorConfig {
8081
user_uid,
8182
relay_enabled: !cli.no_relay,
8283
relay_url,
84+
relay_url_override: cli.relay_url.is_some(),
8385
api_miners_pct: cli.api_miners_pct,
8486
disable_benchmark: cli.disable_benchmark,
8587
metrics_port: cli.metrics_port,
@@ -144,6 +146,7 @@ impl ValidatorConfig {
144146
user_uid: 1,
145147
relay_enabled: false,
146148
relay_url: String::new(),
149+
relay_url_override: false,
147150
api_miners_pct: 0,
148151
disable_benchmark: cli.disable_benchmark,
149152
metrics_port: cli.metrics_port,

crates/sn2-validator/src/validator_loop/mod.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -209,25 +209,42 @@ impl ValidatorLoop {
209209
.clone()
210210
.ok_or_else(|| anyhow::anyhow!("wallet required in production mode"))?;
211211
let client = MinerQueryClient::new(wallet.clone())?;
212-
let relay = RelayManager::new(
213-
config.relay_url.clone(),
214-
wallet.clone(),
215-
config.relay_enabled,
216-
dsperse_tx.clone(),
217-
rwr_tx.clone(),
218-
);
212+
let is_mainnet_validator = config.netuid == DEFAULT_NETUID
213+
&& config
214+
.metagraph
215+
.get_neuron(config.user_uid)
216+
.is_some_and(|n| n.validator_permit);
217+
let relay_reporting_enabled =
218+
(IS_RELEASE_BUILD || config.relay_url_override) && is_mainnet_validator;
219+
let relay = if relay_reporting_enabled {
220+
Some(RelayManager::new(
221+
config.relay_url.clone(),
222+
wallet.clone(),
223+
config.relay_enabled,
224+
dsperse_tx.clone(),
225+
rwr_tx.clone(),
226+
))
227+
} else {
228+
if !is_mainnet_validator {
229+
info!(
230+
netuid = config.netuid,
231+
"sn2-relay disabled for non-mainnet validator"
232+
);
233+
} else {
234+
info!(
235+
version = SOFTWARE_VERSION,
236+
"sn2-relay disabled for non-release build"
237+
);
238+
}
239+
None
240+
};
219241
let api_reporting_enabled = IS_RELEASE_BUILD || config.proof_api_url.is_some();
220242
if !api_reporting_enabled {
221243
info!(
222244
version = SOFTWARE_VERSION,
223245
"sn2-api reporting disabled for non-release build"
224246
);
225247
}
226-
let is_mainnet_validator = config.netuid == DEFAULT_NETUID
227-
&& config
228-
.metagraph
229-
.get_neuron(config.user_uid)
230-
.is_some_and(|n| n.validator_permit);
231248
let stats_enabled =
232249
api_reporting_enabled && !config.disable_metric_logging && is_mainnet_validator;
233250
if api_reporting_enabled && !is_mainnet_validator {
@@ -265,7 +282,7 @@ impl ValidatorLoop {
265282
};
266283
(
267284
Arc::new(RwLock::new(client)),
268-
Some(relay),
285+
relay,
269286
uploader,
270287
reporter,
271288
events,

0 commit comments

Comments
 (0)