mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-11 00:37:41 +00:00
fix: detect gift-wrap REQs by kinds array, drop EOSE noise
The diagnostics logger tagged a subscription as gift-wrap when its raw REQ string merely *contained* "1059"/"1060" — which matches incidentally inside a pubkey hex or a since/limit number on unrelated feed REQs. Those feed subs then leaked their EOSEs (and some connect/auth lines) into the DMPagination tag. Match the filter's `kinds` array exactly against the real gift-wrap kinds (1059 + 21059) instead. Also drop the per-relay EOSE line entirely — it's redundant with the "cold boot: … initial load complete" summary that already reports the first EOSE and gift-wrap count. https://claude.ai/code/session_01B1fmmmX8JjQWH3amMLdvcW
This commit is contained in:
+16
-7
@@ -25,7 +25,6 @@ import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnection
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.AuthMessage
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.ClosedMessage
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.EoseMessage
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.EventMessage
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.Message
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.NoticeMessage
|
||||
@@ -89,7 +88,7 @@ class DmRelayDiagnosticsLogger(
|
||||
cmd: Command,
|
||||
success: Boolean,
|
||||
) {
|
||||
if (!cmdStr.contains("1059") && !cmdStr.contains("1060")) return
|
||||
if (!isGiftWrapReq(cmdStr)) return
|
||||
giftWrapRelays.add(relay.url)
|
||||
reqSubId(cmdStr)?.let { giftWrapSubIds.add(it) }
|
||||
Log.d(TAG) { "[+${at()}ms] REQ -> ${relay.url.url} success=$success ${cmdStr.take(400)}" }
|
||||
@@ -112,11 +111,6 @@ class DmRelayDiagnosticsLogger(
|
||||
Log.d(TAG) { "[+${at()}ms] CLOSED <- ${relay.url.url} sub=${msg.subId} reason='${msg.message}'" }
|
||||
}
|
||||
|
||||
is EoseMessage ->
|
||||
if (msg.subId in giftWrapSubIds) {
|
||||
Log.d(TAG) { "[+${at()}ms] EOSE <- ${relay.url.url} sub=${msg.subId}" }
|
||||
}
|
||||
|
||||
is EventMessage ->
|
||||
if (msg.event.kind == GiftWrapEvent.KIND || msg.event.kind == EphemeralGiftWrapEvent.KIND) {
|
||||
giftWrapRelays.add(relay.url)
|
||||
@@ -155,9 +149,24 @@ class DmRelayDiagnosticsLogger(
|
||||
companion object {
|
||||
private const val TAG = "DMPagination"
|
||||
|
||||
// The kinds a gift-wrap REQ carries (1059 + 21059). Matched exactly against the
|
||||
// filter's "kinds" array — never as a substring of the whole command, since a
|
||||
// pubkey hex or timestamp can incidentally contain "1059".
|
||||
private val GIFT_WRAP_KINDS = setOf(GiftWrapEvent.KIND, EphemeralGiftWrapEvent.KIND)
|
||||
|
||||
private val KINDS_ARRAY = Regex("\"kinds\":\\[([0-9,\\s]*)]")
|
||||
|
||||
// Extracts the subscription id from a `["REQ","<subId>",{...}]` command string.
|
||||
private val REQ_SUB_ID = Regex("^\\[\"REQ\",\"([^\"]+)\"")
|
||||
|
||||
private fun reqSubId(cmdStr: String) = REQ_SUB_ID.find(cmdStr)?.groupValues?.get(1)
|
||||
|
||||
/** True only when one of the REQ's `kinds` arrays actually contains a gift-wrap kind. */
|
||||
private fun isGiftWrapReq(cmdStr: String): Boolean =
|
||||
KINDS_ARRAY.findAll(cmdStr).any { match ->
|
||||
match.groupValues[1]
|
||||
.split(',')
|
||||
.any { it.trim().toIntOrNull() in GIFT_WRAP_KINDS }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user