fix(publish): flag + log unconfirmed (optimistic) relay publishes

publishEventToRelay optimistically reports success when a relay handle exposes
no ok/failed event and isn't thenable (legacy 'seen'-only relays). That made an
UNCONFIRMED publish indistinguishable from a real ack, so a note could show
'Published' with nothing actually stored. The result now carries optimistic:true
for that path (callers can distinguish it from a confirmed ack) and logs a
dev.warn. Behavior is otherwise unchanged (still treated as success for legacy
relays). Publish audit #3.

Test: tests/nostr-publish-optimistic.test.mjs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
thePR0M3TH3ANandClaude Opus 4.8 committed 2026-06-16 20:28:27 -04:00
1 parent 3d6ffe997b
commit ac1dcff184
2 files changed
+60 -3

No files matched your search

+11 -3
View File
@@ -68,12 +68,12 @@ export function publishEventToRelay(pool, url, event, options = {}) {
return new Promise((resolve) => {
let settled = false;
const finalize = (success, error = null) => {
const finalize = (success, error = null, optimistic = false) => {
if (settled) {
return;
}
settled = true;
resolve({ url, success, error });
resolve({ url, success, error, optimistic });
};
const timeoutId = setTimeout(() => {
@@ -149,8 +149,16 @@ export function publishEventToRelay(pool, url, event, options = {}) {
return;
}
// No confirmation channel: the relay handle exposed neither an ok/failed
// event nor a thenable. We still optimistically report success for legacy
// "seen"-only relays, but mark the result `optimistic` and log it so a
// silently-unconfirmed publish is traceable rather than indistinguishable
// from a real relay ack (publish audit #3).
clearTimeout(timeoutId);
finalize(true);
devLogger.warn(
`[nostrPublish] Optimistic (unconfirmed) publish success for ${url}: relay gave no ok/failed/then signal.`,
);
finalize(true, null, true);
});
}