Skip to content

Commit 68f228a

Browse files
committed
feat: add SetMechanism sudo action + boot migration to mechanism_id=0
- New SudoAction::SetMechanism to change a challenge's mechanism_id via sudo - CLI command: platform-sudo set-mechanism -c <id> -m <mechanism_id> - Boot migration: forces all existing challenges to mechanism_id=0 (fixes challenges stored with old default of 1)
1 parent 5ce5a0c commit 68f228a

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

bins/platform-sudo/src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ enum Commands {
7373
#[arg(short, long)]
7474
weight: f64,
7575
},
76+
/// Set a challenge's mechanism ID
77+
SetMechanism {
78+
/// Challenge ID (UUID or name)
79+
#[arg(short = 'c', long)]
80+
challenge_id: String,
81+
/// Mechanism ID
82+
#[arg(short, long)]
83+
mechanism_id: u8,
84+
},
7685
/// Emergency pause the network
7786
Pause {
7887
/// Reason for the pause
@@ -523,6 +532,19 @@ async fn main() -> Result<()> {
523532
});
524533
sudo_cli.send_sudo_action(action).await?;
525534
}
535+
Some(Commands::SetMechanism {
536+
challenge_id,
537+
mechanism_id,
538+
}) => {
539+
let cid = ChallengeId::from_string(&challenge_id);
540+
let action = serde_json::json!({
541+
"SetMechanism": {
542+
"challenge_id": cid.0.to_string(),
543+
"mechanism_id": mechanism_id
544+
}
545+
});
546+
sudo_cli.send_sudo_action(action).await?;
547+
}
526548
Some(Commands::Pause { reason }) => {
527549
let action = serde_json::json!({
528550
"EmergencyPause": {

bins/validator-node/src/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,25 @@ async fn main() -> Result<()> {
830830
info!("RPC server started on {}", args.rpc_addr);
831831
}
832832

833+
// Migrate: ensure all challenges use mechanism_id=0 (main mechanism)
834+
{
835+
let mut cs = chain_state.write();
836+
let mut migrated = 0u32;
837+
for (_id, cfg) in cs.wasm_challenge_configs.iter_mut() {
838+
if cfg.config.mechanism_id != 0 {
839+
info!(
840+
"Migrating challenge {} mechanism_id {} -> 0",
841+
cfg.name, cfg.config.mechanism_id
842+
);
843+
cfg.config.mechanism_id = 0;
844+
migrated += 1;
845+
}
846+
}
847+
if migrated > 0 {
848+
info!("Migrated {} challenges to mechanism_id=0", migrated);
849+
}
850+
}
851+
833852
// Reload WASM modules from persisted challenges on startup
834853
if let Some(ref executor) = wasm_executor {
835854
let challenges: Vec<(platform_core::ChallengeId, String)> = {

crates/core/src/message.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ pub enum SudoAction {
288288
emission_weight: f64,
289289
},
290290

291+
/// Set a challenge's mechanism ID
292+
SetMechanism {
293+
challenge_id: ChallengeId,
294+
mechanism_id: u8,
295+
},
296+
291297
// === Version Management ===
292298
/// Set required validator version (triggers auto-update)
293299
SetRequiredVersion {

crates/core/src/state.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,26 @@ impl ChainState {
366366
)));
367367
}
368368
}
369+
SudoAction::SetMechanism {
370+
challenge_id,
371+
mechanism_id,
372+
} => {
373+
tracing::info!(
374+
challenge_id = %challenge_id,
375+
mechanism_id = mechanism_id,
376+
"Sudo: setting challenge mechanism ID"
377+
);
378+
if let Some(wasm_config) = self.wasm_challenge_configs.get_mut(challenge_id) {
379+
wasm_config.config.mechanism_id = *mechanism_id;
380+
} else if let Some(challenge) = self.challenges.get_mut(challenge_id) {
381+
challenge.config.mechanism_id = *mechanism_id;
382+
} else {
383+
return Err(crate::MiniChainError::Consensus(format!(
384+
"Challenge {} not found",
385+
challenge_id
386+
)));
387+
}
388+
}
369389
SudoAction::SetRequiredVersion {
370390
min_version,
371391
recommended_version,

0 commit comments

Comments
 (0)