Skip to content

Commit 8f1c24c

Browse files
committed
fix: sync validators to P2P state manager for storage consensus
The storage proposal consensus requires validators to be present in the P2P StateManager, not just the ValidatorSet. This was causing quorum calculation to fail because total_validators was 0.
1 parent f4ad317 commit 8f1c24c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

bins/validator-node/src/main.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ async fn main() -> Result<()> {
448448
&chain_state,
449449
&valid_voters,
450450
&state_root_consensus,
451+
&state_manager,
451452
);
452453
info!(
453454
"Validator set: {} active validators",
@@ -509,6 +510,7 @@ async fn main() -> Result<()> {
509510
&chain_state,
510511
&valid_voters,
511512
&state_root_consensus,
513+
&state_manager,
512514
);
513515
info!(
514516
"Validator set: {} active validators",
@@ -1238,7 +1240,7 @@ async fn main() -> Result<()> {
12381240
match sync_metagraph(client, netuid).await {
12391241
Ok(mg) => {
12401242
info!("Metagraph refreshed: {} neurons", mg.n);
1241-
update_validator_set_from_metagraph(&mg, &validator_set, &chain_state, &valid_voters, &state_root_consensus);
1243+
update_validator_set_from_metagraph(&mg, &validator_set, &chain_state, &valid_voters, &state_root_consensus, &state_manager);
12421244
if let Some(sc) = subtensor_client.as_mut() {
12431245
sc.set_metagraph(mg);
12441246
}
@@ -1453,10 +1455,14 @@ fn update_validator_set_from_metagraph(
14531455
state_root_consensus: &Arc<
14541456
parking_lot::Mutex<platform_distributed_storage::state_consensus::StateRootConsensus>,
14551457
>,
1458+
state_manager: &Arc<StateManager>,
14561459
) {
14571460
let mut cs = chain_state.write();
14581461
cs.registered_hotkeys.clear();
14591462

1463+
// Collect validators for P2P state manager
1464+
let mut p2p_validators: Vec<(Hotkey, u64)> = Vec::new();
1465+
14601466
for neuron in metagraph.neurons.values() {
14611467
let hotkey_bytes: [u8; 32] = neuron.hotkey.clone().into();
14621468
let hotkey = Hotkey(hotkey_bytes);
@@ -1476,8 +1482,9 @@ fn update_validator_set_from_metagraph(
14761482
// Use the same min_stake threshold as the P2P validator set (10000 TAO = 10e12 RAO)
14771483
if stake >= 10_000_000_000_000 {
14781484
cs.validators.entry(hotkey.clone()).or_insert_with(|| {
1479-
platform_core::ValidatorInfo::new(hotkey, platform_core::Stake(stake))
1485+
platform_core::ValidatorInfo::new(hotkey.clone(), platform_core::Stake(stake))
14801486
});
1487+
p2p_validators.push((hotkey, stake));
14811488
}
14821489
}
14831490

@@ -1487,6 +1494,13 @@ fn update_validator_set_from_metagraph(
14871494
state_root_consensus.lock().set_valid_voters(voter_hotkeys);
14881495

14891496
cs.update_hash();
1497+
1498+
// Sync validators to P2P state manager for storage consensus
1499+
state_manager.apply(|state| {
1500+
for (hotkey, stake) in p2p_validators {
1501+
state.update_validator(hotkey, stake);
1502+
}
1503+
});
14901504
}
14911505

14921506
async fn handle_network_event(

0 commit comments

Comments
 (0)