Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/hidden-content-cache-start-always.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'nostream': patch
---

fix(nip56): start the hidden-content cache on every worker, not only when reporting is on at boot

A worker started the cache of hidden report targets only if `nip56.enabled` was true when it booted. On a relay that turned reporting and `hideActionableReports` on later, through a settings reload or a backup restore, the live-delivery check was active but the cache stayed empty, so reported pubkeys and events were still sent to open subscriptions until the next restart. The cache now starts on every worker. Each tick still reads the settings first and queries the database only while `hideActionableReports` is on, so a relay that does not use reporting pays no database cost.
14 changes: 9 additions & 5 deletions src/factories/worker-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ export const workerFactory = (): AppWorker => {
// subscriber could see unfiltered content in the brief window before this
// resolves) self-heals on the cache's own periodic refresh, not a
// dedicated retry path.
if (settings.nip56?.enabled) {
startHiddenContentCache(reportRepository, createSettings).catch((error) =>
logger.error('failed to start hidden content cache: %o', error),
)
}
//
// Started on every worker whatever nip56.enabled says at boot: each tick
// reads the settings fresh and only queries the database while
// hideActionableReports is on, so a relay that turns reporting on later
// (settings reload or backup restore) is picked up within one interval
// instead of hiding nothing until the next restart.
startHiddenContentCache(reportRepository, createSettings).catch((error) =>
logger.error('failed to start hidden content cache: %o', error),
)

// Constructs the WoT graph singleton (and starts warming it up, if enabled)
// right at worker boot -- before this call, the singleton was only ever
Expand Down
27 changes: 26 additions & 1 deletion test/unit/factories/worker-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('workerFactory', () => {
worker.close()
})

it('does not start the cache when nip56 is unset', async () => {
it('does not read the DB at boot when nip56 is unset', async () => {
createSettingsStub.returns({
info: { relay_url: 'url' },
network: {},
Expand All @@ -102,5 +102,30 @@ describe('workerFactory', () => {
expect(findActionableTargetsStub.called).to.be.false
worker.close()
})

it('picks up hideActionableReports turned on after a boot without nip56', async () => {
const clock = Sinon.useFakeTimers({ toFake: ['setInterval', 'clearInterval'] })
try {
let settings: any = { info: { relay_url: 'url' }, network: {} }
createSettingsStub.callsFake(() => settings)

const worker = workerFactory()
await new Promise((resolve) => setImmediate(resolve))
expect(findActionableTargetsStub.called).to.be.false

settings = {
...settings,
nip56: { enabled: true, trustedModerators: [], hideActionableReports: true },
}
clock.tick(30000)
await new Promise((resolve) => setImmediate(resolve))

expect(findActionableTargetsStub.callCount).to.equal(1)
worker.close()
} finally {
stopHiddenContentCache()
clock.restore()
}
})
})
})
Loading