@@ -13,7 +13,7 @@ use std::time::Duration;
1313use async_utility:: futures_util:: stream:: BoxStream ;
1414use nostr:: prelude:: * ;
1515use nostr_database:: prelude:: * ;
16- use nostr_gossip:: { BestRelaySelection , GossipListKind , NostrGossip } ;
16+ use nostr_gossip:: { BestRelaySelection , GossipListKind , GossipPublicKeyStatus , NostrGossip } ;
1717use nostr_relay_pool:: prelude:: * ;
1818use tokio:: sync:: broadcast;
1919
@@ -74,7 +74,6 @@ impl Client {
7474 /// use nostr_sdk::prelude::*;
7575 ///
7676 /// let signer = Keys::generate();
77- /// let opts = ClientOptions::default().gossip(true);
7877 /// let client: Client = Client::builder().signer(signer).opts(opts).build();
7978 /// ```
8079 #[ inline]
@@ -1341,14 +1340,14 @@ impl Client {
13411340 {
13421341 tracing:: debug!( kind = ?gossip_kind, "Start checking and updating gossip data." ) ;
13431342
1344- let mut outdated_public_keys: HashSet < PublicKey > = HashSet :: new ( ) ;
1343+ let mut outdated_public_keys: HashMap < PublicKey , Timestamp > = HashMap :: new ( ) ;
13451344
13461345 for public_key in public_keys. into_iter ( ) {
13471346 // Get the public key status
13481347 let status = gossip. status ( & public_key, gossip_kind) . await ?;
13491348
1350- if status. is_outdated ( ) {
1351- outdated_public_keys. insert ( public_key) ;
1349+ if let GossipPublicKeyStatus :: Outdated { created_at } = status {
1350+ outdated_public_keys. insert ( public_key, created_at . unwrap_or_default ( ) ) ;
13521351 }
13531352 }
13541353
@@ -1366,7 +1365,7 @@ impl Client {
13661365
13671366 // Compose database filter
13681367 let db_filter: Filter = Filter :: default ( )
1369- . authors ( outdated_public_keys. clone ( ) )
1368+ . authors ( outdated_public_keys. keys ( ) . copied ( ) )
13701369 . kind ( kind) ;
13711370
13721371 tracing:: debug!( filter = ?db_filter, "Querying database for outdated gossip data." ) ;
@@ -1391,32 +1390,29 @@ impl Client {
13911390 let mut filters: Vec < Filter > = Vec :: with_capacity ( stored_events. len ( ) ) ;
13921391
13931392 // Keep track of the missing public keys
1394- let mut missing_public_keys: HashSet < PublicKey > = outdated_public_keys;
1393+ let mut missing_public_keys: HashSet < PublicKey > =
1394+ outdated_public_keys. keys ( ) . copied ( ) . collect ( ) ;
13951395
13961396 // Try to fetch from relays only the newer events (last created_at + 1)
1397- for event in stored_events. iter ( ) {
1398- let author = event. pubkey ;
1399- let created_at = event. created_at ;
1400-
1397+ for ( author, created_at) in outdated_public_keys. iter ( ) {
14011398 // Construct filter
14021399 let filter: Filter = Filter :: new ( )
1403- . author ( author)
1400+ . author ( * author)
14041401 . kind ( kind)
1405- . since ( created_at + Duration :: from_secs ( 1 ) )
1402+ . since ( * created_at + Duration :: from_secs ( 1 ) )
14061403 . limit ( 1 ) ;
14071404
14081405 filters. push ( filter) ;
14091406
14101407 // Remove from the missing set
1411- missing_public_keys. remove ( & event . pubkey ) ;
1408+ missing_public_keys. remove ( author ) ;
14121409 }
14131410
14141411 tracing:: debug!( filters = ?filters, "Fetching outdated gossip data from relays." ) ;
14151412
14161413 // Fetch the events
14171414 // NOTE: the received events are automatically processed
1418- self
1419- . pool
1415+ self . pool
14201416 . fetch_events_from (
14211417 urls. clone ( ) ,
14221418 filters,
@@ -1426,11 +1422,9 @@ impl Client {
14261422 . await ?;
14271423
14281424 // Update the last check for the stored public keys
1429- for pk in stored_events . iter ( ) . map ( |e| e . pubkey ) {
1425+ for pk in outdated_public_keys . keys ( ) {
14301426 // Update the last check for this public key
1431- gossip
1432- . update_fetch_attempt ( & pk, gossip_kind)
1433- . await ?;
1427+ gossip. update_fetch_attempt ( pk, gossip_kind) . await ?;
14341428 }
14351429
14361430 // Get the missing events
0 commit comments