fix: publish NIP-52 events with monotonic created_at (#26) #27
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/monotonic-created-at"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Backend counterpart of aiolabs/webapp#122. Fixes #26.
Problem
build_nip52_event()stampedcreated_at=int(time.time()). NIP-52 calendar events (31922/31923) are replaceable and get republished whenever inventory changes (a ticket sells). Relays only push a replacement to open subscriptions whencreated_atis strictly newer, so two republishes in the same wall-clock second tie and the second is silently dropped — a connected client's "X tickets remaining" badge stalls until a reload. Same root cause as the webapp's live-ticket-count bug.Fix
nostr_timestamp.py—monotonic_created_at(last, now=None)=max(now, last+1), a tiny pure module mirroring the webapp'smonotonicCreatedAtanddocs/nostr-patterns/replaceable-events.md.Event.nostr_event_created_at(set after each publish innostr_hooks.py:45) — no new schema, no migration.int(time.time()).Tests
tests/test_nostr_timestamp.py: no-prior, same-second bump, wall-clock tracking, future-dated prior, strictly-increasing same-second burst (mirrors the webapp'stimestamp.spec.ts). Pure-logic verified locally; ruff + black clean.Known limitation (follow-up in #26)
Two concurrent sales reading the same stored anchor before either persists can still compute the same
+1. Full hardening needs a row-level lock / transaction around read-bump-publish-persist. This change fixes the dominant sequential case and is strictly better thantime.time().Versioning / deploy
Bumps
config.json→1.6.1-aio.6(aio semver stays ahead of upstream 1.6.1). Tag +aiolabs/lnbits-extensionscatalog entry + sha256 are the separate post-merge release step (test on dev LNbits → tag at HEAD → add catalog entry), per the extension version-bump procedure.🤖 Generated with Claude Code