Skip to content

Commit 377e480

Browse files
committed
pool: improve Relay::support_negentropy method
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent b7b4886 commit 377e480

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
* pool: `RelayPool::send_event` and `RelayPool::batch_event` send only to relays with `WRITE` flag ([Yuki Kishimoto])
6767
* pool: `RelayPool::subscribe_with_id`, `RelayPool::get_events_of` and `RelayPool::stream_events_of` REQ events only to relays with `READ` flag ([Yuki Kishimoto])
6868
* pool: bump `async-wsocket` to `v0.9` ([Yuki Kishimoto])
69+
* pool: improve `Relay::support_negentropy` method ([Yuki Kishimoto])
6970
* signer: update NIP-04 and NIP-44 methods signature ([Yuki Kishimoto])
7071
* webln: bump `webln` to `v0.3` ([Yuki Kishimoto])
7172
* sqlite: deprecate `SQLiteDatabase` in favor of LMDB ([Yuki Kishimoto])

crates/nostr-relay-pool/src/relay/internal.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use nostr::nips::nip11::RelayInformationDocument;
2222
#[cfg(not(target_arch = "wasm32"))]
2323
use nostr::secp256k1::rand;
2424
use nostr::{
25-
ClientMessage, Event, EventId, Filter, JsonUtil, Keys, Kind, MissingPartialEvent, PartialEvent,
25+
ClientMessage, Event, EventId, Filter, JsonUtil, Kind, MissingPartialEvent, PartialEvent,
2626
RawRelayMessage, RelayMessage, SubscriptionId, Timestamp, Url,
2727
};
2828
use nostr_database::{DatabaseEventStatus, DynNostrDatabase};
@@ -2220,13 +2220,27 @@ impl InternalRelay {
22202220
}
22212221

22222222
pub async fn support_negentropy(&self) -> Result<bool, Error> {
2223-
let pk = Keys::generate();
2224-
let filter = Filter::new().author(pk.public_key());
2223+
// Check if NIP-77 is marked as supported in relay document
2224+
#[cfg(feature = "nip11")]
2225+
{
2226+
let document = self.document().await;
2227+
if let Some(nips) = document.supported_nips {
2228+
if nips.contains(&77) {
2229+
return Ok(true);
2230+
}
2231+
}
2232+
}
2233+
2234+
// Not declared in relay document or relay document not found
2235+
// Execute dry-run reconciliation to check if it's supported
2236+
let filter: Filter = Filter::new().limit(1);
22252237
match self
22262238
.reconcile_with_items(
22272239
filter,
22282240
Vec::new(),
2229-
NegentropyOptions::new().initial_timeout(Duration::from_secs(5)),
2241+
NegentropyOptions::new()
2242+
.initial_timeout(Duration::from_secs(5))
2243+
.dry_run(),
22302244
)
22312245
.await
22322246
{

0 commit comments

Comments
 (0)