Ensure messages are sent to all relays

To be compatible to wallets that only listen on 'relay.cauldron.quest',
we need to make sure we send our messages to all connected relay
servers.
This commit is contained in:
Dagur Valberg Johannsson 2026-04-16 13:37:24 +02:00
parent 053f515b8f
commit 9028384177
No known key found for this signature in database
GPG key ID: FD701804AEE88107

View file

@ -246,26 +246,40 @@ export class RelayClient extends EventEmitter {
this.pairedPubkeyHex,
);
try {
await Promise.any(
const results = await Promise.allSettled(
this.pool.publish(this.config.explicitRelayUrls, wrapped),
);
if (this.config.logNetworkActivity) {
debug(Scope.Relay, `Published message ${message.action} to relay`);
}
} catch (error) {
if (this.config.logNetworkActivity) {
const fulfilled = results.filter((r) => r.status === "fulfilled");
const rejected = results.filter((r) => r.status === "rejected");
if (rejected.length > 0 && this.config.logNetworkActivity) {
for (const r of rejected) {
logError(
Scope.Relay,
`Failed to publish message ${message.action}:`,
error,
`Failed to publish ${message.action} to a relay:`,
(r as PromiseRejectedResult).reason,
);
}
this.emitDisconnect(
error instanceof Error ? error : new Error(`Publish failed: ${error}`),
}
if (fulfilled.length === 0) {
const error = new Error(
`Failed to publish ${message.action} to all relays`,
);
if (this.config.logNetworkActivity) {
logError(Scope.Relay, error.message);
}
this.emitDisconnect(error);
throw error;
}
if (this.config.logNetworkActivity) {
debug(
Scope.Relay,
`Published message ${message.action} to ${fulfilled.length}/${results.length} relay(s)`,
);
}
}
private handleWrappedEvent(wrappedEvent: NostrEvent): void {