nappup 1.5.4 → 1.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +28 -10
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -130,7 +130,7 @@ export async function toApp (fileList, nostrSigner, { log = () => {}, dTag, dTag
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
log(`Uploading stall event for
|
|
133
|
+
log(`Uploading stall event for ${dTag}`)
|
|
134
134
|
;({ pause } = (await maybeUploadStall({
|
|
135
135
|
dTag,
|
|
136
136
|
channel,
|
|
@@ -146,6 +146,7 @@ export async function toApp (fileList, nostrSigner, { log = () => {}, dTag, dTag
|
|
|
146
146
|
writeRelays,
|
|
147
147
|
log,
|
|
148
148
|
pause,
|
|
149
|
+
shouldReupload,
|
|
149
150
|
self: nappJson.self?.[0]?.[0],
|
|
150
151
|
countries: nappJson.country,
|
|
151
152
|
categories: nappJson.category,
|
|
@@ -217,23 +218,38 @@ async function throttledSendEvent (event, relays, {
|
|
|
217
218
|
return { pause }
|
|
218
219
|
}
|
|
219
220
|
|
|
220
|
-
const [rateLimitErrors, unretryableErrors] =
|
|
221
|
+
const [rateLimitErrors, maybeUnretryableErrors, unretryableErrors] =
|
|
221
222
|
errors.reduce((r, v) => {
|
|
222
|
-
|
|
223
|
-
|
|
223
|
+
const message = v.reason?.message ?? ''
|
|
224
|
+
if (message.startsWith('rate-limited:')) r[0].push(v)
|
|
225
|
+
// https://github.com/nbd-wtf/nostr-tools/blob/28f7553187d201088c8a1009365db4ecbe03e568/abstract-relay.ts#L311
|
|
226
|
+
else if (message === 'publish timed out') r[1].push(v)
|
|
227
|
+
else r[2].push(v)
|
|
224
228
|
return r
|
|
225
|
-
}, [[], []])
|
|
229
|
+
}, [[], [], []])
|
|
230
|
+
|
|
231
|
+
// One-time special retry
|
|
232
|
+
if (maybeUnretryableErrors.length > 0) {
|
|
233
|
+
const timedOutRelays = maybeUnretryableErrors.map(v => v.relay)
|
|
234
|
+
log(`${maybeUnretryableErrors.length} timeout errors, retrying once after ${pause}ms:\n${maybeUnretryableErrors.map(v => `${v.relay}: ${v.reason.message}`).join('; ')}`)
|
|
235
|
+
if (pause) await new Promise(resolve => setTimeout(resolve, pause))
|
|
236
|
+
const { errors: timeoutRetryErrors } = await nostrRelays.sendEvent(event, timedOutRelays, 15000)
|
|
237
|
+
unretryableErrors.push(...timeoutRetryErrors)
|
|
238
|
+
}
|
|
239
|
+
|
|
226
240
|
if (unretryableErrors.length > 0) {
|
|
227
241
|
log(`${unretryableErrors.length} unretryable errors:\n${unretryableErrors.map(v => `${v.relay}: ${v.reason.message}`).join('; ')}`)
|
|
228
242
|
console.log('Erroed event:', stringifyEvent(event))
|
|
229
243
|
}
|
|
230
|
-
const
|
|
231
|
-
const maybeSuccessfulRelays = relays.length - unretryableErrorsLength
|
|
244
|
+
const maybeSuccessfulRelays = relays.length - unretryableErrors.length
|
|
232
245
|
const hasReachedMaxRetries = retries > maxRetries
|
|
233
246
|
if (
|
|
234
247
|
hasReachedMaxRetries ||
|
|
235
248
|
maybeSuccessfulRelays < minSuccessfulRelays
|
|
236
|
-
)
|
|
249
|
+
) {
|
|
250
|
+
const finalErrors = [...rateLimitErrors, ...unretryableErrors]
|
|
251
|
+
throw new Error(finalErrors.map(v => `\n${v.relay}: ${v.reason}`).join('\n'))
|
|
252
|
+
}
|
|
237
253
|
|
|
238
254
|
if (rateLimitErrors.length === 0) {
|
|
239
255
|
if (pause && trailingPause) await new Promise(resolve => setTimeout(resolve, pause))
|
|
@@ -244,7 +260,8 @@ async function throttledSendEvent (event, relays, {
|
|
|
244
260
|
log(`Rate limited by ${erroedRelays.length} relays, pausing for ${pause + 2000} ms`)
|
|
245
261
|
await new Promise(resolve => setTimeout(resolve, (pause += 2000)))
|
|
246
262
|
|
|
247
|
-
|
|
263
|
+
// Subtracts the successful publishes from the original minSuccessfulRelays goal
|
|
264
|
+
minSuccessfulRelays = Math.max(0, minSuccessfulRelays - (relays.length - erroedRelays.length - unretryableErrors.length))
|
|
248
265
|
return await throttledSendEvent(event, erroedRelays, {
|
|
249
266
|
pause, log, retries: ++retries, maxRetries, minSuccessfulRelays, leadingPause: false, trailingPause
|
|
250
267
|
})
|
|
@@ -386,6 +403,7 @@ async function maybeUploadStall ({
|
|
|
386
403
|
writeRelays,
|
|
387
404
|
log,
|
|
388
405
|
pause,
|
|
406
|
+
shouldReupload,
|
|
389
407
|
self,
|
|
390
408
|
countries,
|
|
391
409
|
categories,
|
|
@@ -631,7 +649,7 @@ async function maybeUploadStall ({
|
|
|
631
649
|
}
|
|
632
650
|
}
|
|
633
651
|
|
|
634
|
-
if (!changed) {
|
|
652
|
+
if (!changed && !shouldReupload) {
|
|
635
653
|
const { storedEvents } = previousResult
|
|
636
654
|
|
|
637
655
|
const matchingEvents = storedEvents.filter(e => e.id === previous.id)
|