fix: expand bounded gift-wrap backfill requests

This commit is contained in:
Taksh committed 2026-09-30 22:36:00 +05:30
1 parent 45b5eed2fe
commit fdf74ea830
3 files changed
+26 -2

No files matched your search

+1 -1
View File
@@ -1867,7 +1867,7 @@ struct NostrFilter: Encodable {
filter.kinds = [1059] // Gift wrap kind
filter.since = since?.timeIntervalSince1970.toInt()
filter.tagFilters = ["p": [pubkey]]
filter.limit = TransportConfig.nostrRelayDefaultFetchLimit // reasonable limit
filter.limit = TransportConfig.nostrGiftWrapFetchLimit
return filter
}
+4 -1
View File
@@ -269,7 +269,10 @@ enum TransportConfig {
// Reconnect delays get ±20% random jitter so relays that dropped together
// (e.g. a network blip) don't thundering-herd the same reconnect instant.
static let nostrRelayBackoffJitterRatio: Double = 0.2
static let nostrRelayDefaultFetchLimit: Int = 100
// Randomized envelope timestamps can put a recent DM behind older rumors.
// Match the existing location backfill allowance, while keeping requests bounded.
// Relays may impose a lower cap; this is not complete history pagination.
static let nostrGiftWrapFetchLimit: Int = 1000
// How many consecutive Tor-readiness waits (each bounded by TorManager's
// bootstrap deadline) to attempt before unblocking pending EOSE callers.
static let nostrTorReadyMaxWaitAttempts: Int = 3
+21
View File
@@ -453,6 +453,27 @@ struct NostrProtocolTests {
#expect(!signed.isValidSignature())
}
@Test func giftWrapFilter_requestsExpandedBoundedBackfill() throws {
let since = Date(timeIntervalSince1970: 1_699_739_900)
let filter = NostrFilter.giftWrapsFor(pubkey: "recipient", since: since)
let data = try JSONEncoder().encode(filter)
let object = try #require(try JSONSerialization.jsonObject(with: data) as? [String: Any])
let limit = try #require(object["limit"] as? Int)
#expect(object["kinds"] as? [Int] == [1059])
#expect(object["#p"] as? [String] == ["recipient"])
#expect(object["since"] as? Int == 1_699_739_900)
#expect(limit == 1000)
// Model a relay honoring the requested cap and sorting by outer created_at.
// A freshly sent rumor can have an older envelope than 100 retained wraps.
let recentRumorEnvelope = 1_699_920_800
let retainedEnvelopes = (0..<100).map { 1_699_990_000 + $0 }
let newestFirst = (retainedEnvelopes + [recentRumorEnvelope]).sorted(by: >)
#expect(!newestFirst.prefix(100).contains(recentRumorEnvelope))
#expect(newestFirst.prefix(limit).contains(recentRumorEnvelope))
}
@Test func geohashNotesSingleFilter_encodesExpectedTagShape() throws {
let since = Date(timeIntervalSince1970: 1_234_567)
let filter = NostrFilter.geohashNotes("u4pruyd", since: since, limit: 42)