@@ -17,7 +17,7 @@ use crate::node::IsOperationCompleted;
1717use crate :: {
1818 client_events:: HostResult ,
1919 contract:: ContractHandlerEvent ,
20- message:: { InnerMessage , NetMessage , NetMessageV1 , Transaction } ,
20+ message:: { InnerMessage , NetMessage , Transaction } ,
2121 node:: { NetworkBridge , OpManager } ,
2222 ring:: { Location , PeerKeyLocation } ,
2323} ;
@@ -220,15 +220,8 @@ impl Operation for PutOp {
220220 _ => false ,
221221 } ;
222222
223- // Check if we're the initiator of this PUT operation
224- // We only cache locally when either WE initiate the PUT, or when forwarding just of the peer should be seeding
225- let should_seed = match & self . state {
226- Some ( PutState :: PrepareRequest { .. } ) => true ,
227- Some ( PutState :: AwaitingResponse { upstream, .. } ) => {
228- upstream. is_none ( ) || op_manager. ring . should_seed ( & key)
229- }
230- _ => op_manager. ring . should_seed ( & key) ,
231- } ;
223+ // Always cache contracts we encounter - LRU will handle eviction
224+ let should_seed = true ;
232225
233226 let modified_value = if should_seed {
234227 // Cache locally when initiating a PUT. This ensures:
@@ -270,7 +263,7 @@ impl Operation for PutOp {
270263
271264 // Mark as seeded locally if not already
272265 if !is_already_seeding {
273- op_manager. ring . seed_contract ( key) ;
266+ op_manager. ring . seed_contract ( key, value . size ( ) as u64 ) ;
274267 super :: announce_contract_cached ( op_manager, & key) . await ;
275268 tracing:: debug!(
276269 tx = %id,
@@ -415,8 +408,8 @@ impl Operation for PutOp {
415408 // Get the contract key and check if we should handle it
416409 let key = contract. key ( ) ;
417410 let is_subscribed_contract = op_manager. ring . is_seeding_contract ( & key) ;
418- let should_seed = op_manager . ring . should_seed ( & key ) ;
419- let should_handle_locally = !is_subscribed_contract && should_seed ;
411+ // Always cache contracts - LRU handles eviction
412+ let should_handle_locally = !is_subscribed_contract;
420413
421414 tracing:: debug!(
422415 tx = %id,
@@ -481,7 +474,7 @@ impl Operation for PutOp {
481474
482475 let child_tx = super :: start_subscription_request ( op_manager, * id, key) ;
483476 tracing:: debug!( tx = %id, %child_tx, "started subscription as child operation" ) ;
484- op_manager. ring . seed_contract ( key) ;
477+ op_manager. ring . seed_contract ( key, value . size ( ) as u64 ) ;
485478 super :: announce_contract_cached ( op_manager, & key) . await ;
486479
487480 true
@@ -729,7 +722,7 @@ impl Operation for PutOp {
729722 peer = %op_manager. ring. connection_manager. own_location( ) ,
730723 "Adding contract to local seed list"
731724 ) ;
732- op_manager. ring . seed_contract ( key) ;
725+ op_manager. ring . seed_contract ( key, state . size ( ) as u64 ) ;
733726 super :: announce_contract_cached ( op_manager, & key) . await ;
734727 } else {
735728 tracing:: debug!(
@@ -836,8 +829,8 @@ impl Operation for PutOp {
836829 let key = contract. key ( ) ;
837830 let peer_loc = op_manager. ring . connection_manager . own_location ( ) ;
838831 let is_seeding_contract = op_manager. ring . is_seeding_contract ( & key) ;
839- let should_seed = op_manager . ring . should_seed ( & key ) ;
840- let should_handle_locally = should_seed && !is_seeding_contract;
832+ // Always cache contracts - LRU handles eviction
833+ let should_handle_locally = !is_seeding_contract;
841834
842835 tracing:: debug!(
843836 tx = %id,
@@ -903,35 +896,12 @@ impl Operation for PutOp {
903896 . await ?;
904897 }
905898
906- // Start subscription and handle dropped contracts
907- let ( dropped_contract, old_subscribers) = {
908- let child_tx = super :: start_subscription_request ( op_manager, * id, key) ;
909- tracing:: debug!( tx = %id, %child_tx, "started subscription as child operation" ) ;
910- let result = op_manager. ring . seed_contract ( key) ;
911- super :: announce_contract_cached ( op_manager, & key) . await ;
912- result
913- } ;
914-
915- // Notify subscribers of dropped contracts
916- if let Some ( dropped_key) = dropped_contract {
917- for subscriber in old_subscribers {
918- if let Some ( addr) = subscriber. socket_addr ( ) {
919- conn_manager
920- . send (
921- addr,
922- NetMessage :: V1 ( NetMessageV1 :: Unsubscribed {
923- transaction : Transaction :: new :: < PutMsg > ( ) ,
924- key : dropped_key,
925- from : op_manager
926- . ring
927- . connection_manager
928- . own_location ( ) ,
929- } ) ,
930- )
931- . await ?;
932- }
933- }
934- }
899+ // Start subscription and record cache access
900+ let child_tx = super :: start_subscription_request ( op_manager, * id, key) ;
901+ tracing:: debug!( tx = %id, %child_tx, "started subscription as child operation" ) ;
902+ let _evicted = op_manager. ring . seed_contract ( key, new_value. size ( ) as u64 ) ;
903+ super :: announce_contract_cached ( op_manager, & key) . await ;
904+ // Note: Evicted contracts are handled by SeedingManager (subscribers cleaned up internally)
935905 } else if last_hop && !already_put {
936906 // Last hop but not handling locally, still need to put
937907 put_contract (
@@ -1277,7 +1247,9 @@ pub(crate) async fn request_put(op_manager: &OpManager, mut put_op: PutOp) -> Re
12771247 peer = %op_manager. ring. connection_manager. own_location( ) ,
12781248 "Adding contract to local seed list"
12791249 ) ;
1280- op_manager. ring . seed_contract ( key) ;
1250+ op_manager
1251+ . ring
1252+ . seed_contract ( key, updated_value. size ( ) as u64 ) ;
12811253 super :: announce_contract_cached ( op_manager, & key) . await ;
12821254
12831255 // Determine which peers need to be notified and broadcast the update
0 commit comments