File tree Expand file tree Collapse file tree 4 files changed +67
-0
lines changed
Expand file tree Collapse file tree 4 files changed +67
-0
lines changed Original file line number Diff line number Diff 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" : {
Original file line number Diff line number Diff 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 ) > = {
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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,
You can’t perform that action at this time.
0 commit comments