@@ -163,6 +163,7 @@ impl Operation for PutOp {
163163 match input {
164164 PutMsg :: RequestPut {
165165 id,
166+ sender,
166167 contract,
167168 related_contracts,
168169 value,
@@ -171,7 +172,7 @@ impl Operation for PutOp {
171172 } => {
172173 // Get the contract key and own location
173174 let key = contract. key ( ) ;
174- let sender = op_manager. ring . connection_manager . own_location ( ) ;
175+ let own_location = op_manager. ring . connection_manager . own_location ( ) ;
175176
176177 tracing:: info!(
177178 "Requesting put for contract {} from {} to {}" ,
@@ -268,34 +269,41 @@ impl Operation for PutOp {
268269 // Create a SeekNode message to forward to the next hop
269270 return_msg = Some ( PutMsg :: SeekNode {
270271 id : * id,
271- sender,
272+ sender : sender . clone ( ) ,
272273 target : forward_target,
273274 value : modified_value. clone ( ) ,
274275 contract : contract. clone ( ) ,
275276 related_contracts : related_contracts. clone ( ) ,
276277 htl : * htl,
277278 } ) ;
279+
280+ // Transition to AwaitingResponse state to handle future SuccessfulPut messages
281+ new_state = Some ( PutState :: AwaitingResponse {
282+ key,
283+ upstream : Some ( sender. clone ( ) ) ,
284+ contract : contract. clone ( ) ,
285+ state : modified_value,
286+ subscribe : false ,
287+ } ) ;
278288 } else {
279289 // No other peers to forward to - we're the final destination
280290 tracing:: debug!(
281291 tx = %id,
282292 %key,
283- "No peers to forward to - handling PUT completion locally"
293+ "No peers to forward to - handling PUT completion locally, sending SuccessfulPut back to sender "
284294 ) ;
285- return_msg = None ;
286- }
287295
288- // Transition to AwaitingResponse state to handle future SuccessfulPut messages
289- new_state = Some ( PutState :: AwaitingResponse {
290- key ,
291- upstream : match & self . state {
292- Some ( PutState :: ReceivedRequest ) => None ,
293- _ => None ,
294- } ,
295- contract : contract . clone ( ) ,
296- state : modified_value ,
297- subscribe : false ,
298- } ) ;
296+ // Send SuccessfulPut back to the sender (upstream node)
297+ return_msg = Some ( PutMsg :: SuccessfulPut {
298+ id : * id ,
299+ target : sender . clone ( ) ,
300+ key ,
301+ sender : own_location ,
302+ } ) ;
303+
304+ // Mark operation as finished
305+ new_state = Some ( PutState :: Finished { key } ) ;
306+ }
299307 }
300308 PutMsg :: SeekNode {
301309 id,
@@ -1110,6 +1118,7 @@ pub(crate) async fn request_put(op_manager: &OpManager, mut put_op: PutOp) -> Re
11101118 // Create RequestPut message and forward to target peer
11111119 let msg = PutMsg :: RequestPut {
11121120 id,
1121+ sender : own_location,
11131122 contract,
11141123 related_contracts,
11151124 value,
@@ -1272,6 +1281,7 @@ mod messages {
12721281 /// Internal node instruction to find a route to the target node.
12731282 RequestPut {
12741283 id : Transaction ,
1284+ sender : PeerKeyLocation ,
12751285 contract : ContractContainer ,
12761286 #[ serde( deserialize_with = "RelatedContracts::deser_related_contracts" ) ]
12771287 related_contracts : RelatedContracts < ' static > ,
0 commit comments