Skip to content

Commit b6ed215

Browse files
committed
fix: write storage data when local vote reaches consensus
When the proposer's own vote is enough to reach the 35% stake threshold, the data was not being written. Now the local proposal handler checks consensus result and writes immediately if reached.
1 parent 2ce4424 commit b6ed215

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

bins/validator-node/src/main.rs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,14 +1278,51 @@ async fn main() -> Result<()> {
12781278
challenge_id = %proposal.challenge_id,
12791279
"Adding local storage proposal to state"
12801280
);
1281+
let proposal_id = proposal.proposal_id;
12811282
state_manager.apply(|state| {
12821283
state.add_storage_proposal(proposal.clone());
12831284
});
1284-
// Also vote for our own proposal
1285+
// Vote for our own proposal
12851286
let my_hotkey = keypair.hotkey();
1286-
state_manager.apply(|state| {
1287-
state.vote_storage_proposal(&proposal.proposal_id, my_hotkey, true);
1287+
let consensus_result = state_manager.apply(|state| {
1288+
state.vote_storage_proposal(&proposal_id, my_hotkey, true)
12881289
});
1290+
1291+
// If consensus reached with just our vote (high stake), write immediately
1292+
if let Some(true) = consensus_result {
1293+
let proposal_opt = state_manager.apply(|state| {
1294+
state.remove_storage_proposal(&proposal_id)
1295+
});
1296+
if let Some(p) = proposal_opt {
1297+
let storage_key = StorageKey::new(
1298+
&p.challenge_id.to_string(),
1299+
hex::encode(&p.key),
1300+
);
1301+
let result = if p.value.is_empty() {
1302+
storage.delete(&storage_key).await
1303+
} else {
1304+
storage.put(storage_key.clone(), p.value.clone(), PutOptions::default()).await.map(|_| true)
1305+
};
1306+
match result {
1307+
Ok(_) => {
1308+
let op = if p.value.is_empty() { "deleted" } else { "written" };
1309+
info!(
1310+
proposal_id = %hex::encode(&p.proposal_id[..8]),
1311+
challenge_id = %p.challenge_id,
1312+
key_len = p.key.len(),
1313+
"Local proposal consensus reached, data {}", op
1314+
);
1315+
}
1316+
Err(e) => {
1317+
error!(
1318+
proposal_id = %hex::encode(&p.proposal_id[..8]),
1319+
error = %e,
1320+
"Failed to write local consensus storage"
1321+
);
1322+
}
1323+
}
1324+
}
1325+
}
12891326
}
12901327

12911328
// Metagraph refresh

0 commit comments

Comments
 (0)