@@ -866,31 +866,46 @@ async fn main() -> Result<()> {
866866 if let Some ( ref executor) = wasm_executor {
867867 let exec = Arc :: clone ( executor) ;
868868 let cs_for_invalidator = Arc :: clone ( & chain_state) ;
869- let invalidator: Arc < dyn Fn ( & str ) + Send + Sync > = Arc :: new ( move |challenge_id : & str | {
869+ let invalidator: Arc < dyn Fn ( & str , & [ u8 ] ) + Send + Sync > = Arc :: new ( move |challenge_id : & str , wasm_bytes : & [ u8 ] | {
870870 exec. invalidate_cache ( challenge_id) ;
871- // Reload route definitions from the new WASM module
872- let net_policy = wasm_runtime_interface:: NetworkPolicy :: default ( ) ;
873- let sandbox_policy = wasm_runtime_interface:: SandboxPolicy :: default ( ) ;
874- if let Ok ( ( bytes, _metrics) ) = exec. execute_get_routes ( challenge_id, & net_policy, & sandbox_policy) {
875- if let Ok ( routes) = bincode:: deserialize :: < Vec < platform_challenge_sdk_wasm:: WasmRouteDefinition > > ( & bytes) {
876- let route_infos: Vec < platform_core:: ChallengeRouteInfo > = routes
877- . iter ( )
878- . map ( |r| platform_core:: ChallengeRouteInfo {
879- method : r. method . clone ( ) ,
880- path : r. path . clone ( ) ,
881- description : r. description . clone ( ) ,
882- requires_auth : r. requires_auth ,
883- } )
884- . collect ( ) ;
885- if let Ok ( cid) = uuid:: Uuid :: parse_str ( challenge_id) {
886- let mut state = cs_for_invalidator. write ( ) ;
887- state. register_challenge_routes (
888- platform_core:: ChallengeId :: from_uuid ( cid) ,
889- route_infos,
890- ) ;
891- info ! ( challenge_id = challenge_id, "Reloaded WASM routes after upload" ) ;
871+ if wasm_bytes. is_empty ( ) {
872+ return ;
873+ }
874+ // Reload route definitions from the new WASM bytes
875+ match exec. execute_get_routes_from_bytes (
876+ challenge_id,
877+ wasm_bytes,
878+ & wasm_runtime_interface:: NetworkPolicy :: development ( ) ,
879+ & wasm_runtime_interface:: SandboxPolicy :: default ( ) ,
880+ ) {
881+ Ok ( ( routes_data, _) ) => {
882+ if let Ok ( routes) = bincode:: deserialize :: < Vec < platform_challenge_sdk_wasm:: WasmRouteDefinition > > ( & routes_data) {
883+ let route_infos: Vec < platform_core:: ChallengeRouteInfo > = routes
884+ . iter ( )
885+ . map ( |r| platform_core:: ChallengeRouteInfo {
886+ method : r. method . clone ( ) ,
887+ path : r. path . clone ( ) ,
888+ description : r. description . clone ( ) ,
889+ requires_auth : r. requires_auth ,
890+ } )
891+ . collect ( ) ;
892+ if let Ok ( cid) = uuid:: Uuid :: parse_str ( challenge_id) {
893+ let mut state = cs_for_invalidator. write ( ) ;
894+ state. register_challenge_routes (
895+ platform_core:: ChallengeId :: from_uuid ( cid) ,
896+ route_infos. clone ( ) ,
897+ ) ;
898+ info ! (
899+ challenge_id = challenge_id,
900+ routes_count = route_infos. len( ) ,
901+ "Reloaded WASM routes after upload"
902+ ) ;
903+ }
892904 }
893905 }
906+ Err ( e) => {
907+ warn ! ( challenge_id = challenge_id, error = %e, "Failed to reload routes after upload" ) ;
908+ }
894909 }
895910 } ) ;
896911 * rpc_server. rpc_handler ( ) . wasm_cache_invalidator . write ( ) = Some ( invalidator) ;
0 commit comments