fix(relay): force monotonic created_at on NIP-IA archive snapshots (#3848) - #3954
Open
iroiro147 wants to merge 1 commit into
Open
fix(relay): force monotonic created_at on NIP-IA archive snapshots (#3848)#3954iroiro147 wants to merge 1 commit into
iroiro147 wants to merge 1 commit into
Conversation
Rapid NIP-IA archive operations within one wall-clock second produce kind:13535 snapshots with identical created_at. NIP-01 resolves same-second replaceable events by lowest event id (randomly signed), so an intermediate snapshot can win over a newer accepted delta, stranding the authoritative slot on stale data. Add a pre-sign query for the prior kind:13535 snapshot and force created_at to max(prior + 1, now), mirroring the guard already used by publish_dm_visibility_snapshot and emit_addressable_discovery_event. Includes a regression test (DB-gated, skips gracefully without Postgres). Closes block#3848 Signed-off-by: iroiro147 <sarthak.singh@juspay.in>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Rapid NIP-IA archive operations within one wall-clock second produce multiple kind:13535 snapshots with identical
created_at. Under NIP-01, same-second replaceable events resolve by lowest event id, and since ids are randomly signed, an intermediate snapshot can win over a newer accepted delta — stranding the authoritative replaceable slot on stale data.Closes #3848.
Fix
Mirror the guard already used by
publish_dm_visibility_snapshotandemit_addressable_discovery_event: before signing, query the prior stored kind:13535 snapshot and force the new event'screated_attomax(prior.created_at + 1, now). Six rapid same-second publishes now yield T..=T+5 — strictly increasing, so NIP-01 replacement ordering is deterministic and always favors the latest.crates/buzz-relay/src/handlers/side_effects.rs::publish_nipia_archival_listTest
New regression test
nipia_archival_list_snapshots_are_monotonic_through_same_secondinidentity_archive.rs: publishes six same-second snapshots and asserts six distinct, strictly-increasingcreated_atvalues. DB-gated; skips gracefully without a local Postgres (matches the existing harness pattern).cargo check -p buzz-relay --all-targetswarning-clean. Full lib suite: the only failures are 9 pre-existingapi::media/api::adminfailures that reproduce identically on cleanmain(verified viagit stash), unrelated to this change.