File tree Expand file tree Collapse file tree 3 files changed +23
-5
lines changed
Expand file tree Collapse file tree 3 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -862,6 +862,15 @@ async fn main() -> Result<()> {
862862 rpc_server. rpc_handler ( ) . set_route_handler ( handler) ;
863863 }
864864
865+ // Wire WASM cache invalidation callback for uploads
866+ if let Some ( ref executor) = wasm_executor {
867+ let exec = Arc :: clone ( executor) ;
868+ let invalidator: Arc < dyn Fn ( & str ) + Send + Sync > = Arc :: new ( move |challenge_id : & str | {
869+ exec. invalidate_cache ( challenge_id) ;
870+ } ) ;
871+ * rpc_server. rpc_handler ( ) . wasm_cache_invalidator . write ( ) = Some ( invalidator) ;
872+ }
873+
865874 // Wire real-time weight computation for subnet_getWeights RPC
866875 {
867876 let uid_map = Arc :: clone ( & shared_uid_map) ;
@@ -3064,11 +3073,9 @@ async fn handle_network_event(
30643073 }
30653074 }
30663075
3067- // Invalidate WASM cache (skip for wasm_upload - module was just compiled fresh)
3068- if update. update_type != "wasm_upload" {
3069- if let Some ( ref executor) = wasm_executor_ref {
3070- executor. invalidate_cache ( & challenge_id_str) ;
3071- }
3076+ // Always invalidate WASM cache on any update (including wasm_upload)
3077+ if let Some ( ref executor) = wasm_executor_ref {
3078+ executor. invalidate_cache ( & challenge_id_str) ;
30723079 }
30733080 } else {
30743081 warn ! (
Original file line number Diff line number Diff line change @@ -194,6 +194,8 @@ pub struct RpcHandler {
194194 pub keypair : Arc < RwLock < Option < platform_core:: Keypair > > > ,
195195 /// Real-time weight computation handler
196196 pub get_weights_handler : Arc < RwLock < Option < GetWeightsHandler > > > ,
197+ /// Callback to invalidate WASM cache for a challenge (called on wasm_upload)
198+ pub wasm_cache_invalidator : Arc < RwLock < Option < Arc < dyn Fn ( & str ) + Send + Sync > > > > ,
197199}
198200
199201impl RpcHandler {
@@ -209,6 +211,7 @@ impl RpcHandler {
209211 broadcast_tx : Arc :: new ( RwLock :: new ( None ) ) ,
210212 keypair : Arc :: new ( RwLock :: new ( None ) ) ,
211213 get_weights_handler : Arc :: new ( RwLock :: new ( None ) ) ,
214+ wasm_cache_invalidator : Arc :: new ( RwLock :: new ( None ) ) ,
212215 }
213216 }
214217
Original file line number Diff line number Diff line change @@ -1238,6 +1238,14 @@ async fn sudo_challenge_handler(
12381238 "Challenge update broadcast initiated"
12391239 ) ;
12401240
1241+ // Invalidate local WASM cache so new module is loaded on next request
1242+ if request. action == "wasm_upload" {
1243+ if let Some ( ref invalidator) = * handler. wasm_cache_invalidator . read ( ) {
1244+ invalidator ( & request. challenge_id ) ;
1245+ info ! ( challenge_id = %request. challenge_id, "WASM cache invalidated after upload" ) ;
1246+ }
1247+ }
1248+
12411249 (
12421250 StatusCode :: OK ,
12431251 Json ( serde_json:: json!( {
You can’t perform that action at this time.
0 commit comments