@@ -732,31 +732,28 @@ impl<T: ChainRpcClient, U: ChainPubsubClient> RemoteAccountProvider<T, U> {
732732 & self ,
733733 pubkey : & Pubkey ,
734734 ) -> RemoteAccountProviderResult < ( ) > {
735- // If an account is evicted then we need to unsubscribe from it first
735+ // 1. First realize subscription
736+ if let Err ( err) = self . pubsub_client . subscribe ( * pubkey) . await {
737+ return Err ( err) ;
738+ }
739+
740+ // 2. Add to LRU cache
741+ // If an account is evicted then we need to unsubscribe from it
736742 // and then inform upstream that we are no longer tracking it
737743 if let Some ( evicted) = self . lrucache_subscribed_accounts . add ( * pubkey) {
738744 trace ! ( "Evicting {pubkey}" ) ;
739745
740746 // 1. Unsubscribe from the account directly (LRU has already removed it)
741747 if let Err ( err) = self . pubsub_client . unsubscribe ( evicted) . await {
748+ // Should we retry here?
742749 warn ! (
743750 "Failed to unsubscribe from pubsub for evicted account {evicted}: {err:?}" ) ;
744- // Rollback the LRU add since eviction failed
745- self . lrucache_subscribed_accounts . remove ( pubkey) ;
746- return Err ( err) ;
747751 }
748752
749753 // 2. Inform upstream so it can remove it from the store
750754 self . send_removal_update ( evicted) . await ?;
751755 }
752756
753- // 3. Subscribe to the new account (only after successful eviction handling)
754- if let Err ( err) = self . pubsub_client . subscribe ( * pubkey) . await {
755- // Rollback the LRU add since subscription failed
756- self . lrucache_subscribed_accounts . remove ( pubkey) ;
757- return Err ( err) ;
758- }
759-
760757 Ok ( ( ) )
761758 }
762759
@@ -803,6 +800,13 @@ impl<T: ChainRpcClient, U: ChainPubsubClient> RemoteAccountProvider<T, U> {
803800 & self ,
804801 pubkey : & Pubkey ,
805802 ) -> RemoteAccountProviderResult < ( ) > {
803+ if !self . lrucache_subscribed_accounts . can_evict ( pubkey) {
804+ warn ! (
805+ "Tried to unsubscribe from account {} that should never be evicted" ,
806+ pubkey
807+ ) ;
808+ return Ok ( ( ) ) ;
809+ }
806810 if !self . lrucache_subscribed_accounts . contains ( pubkey) {
807811 warn ! (
808812 "Tried to unsubscribe from account {} that was not subscribed in the LRU cache" ,
0 commit comments