relay: write audit entry for NIP-09 event deletion - #4097
Open
iroiro147 wants to merge 1 commit into
Open
Conversation
Wire AuditAction::EventDeleted into all three NIP-09 deletion paths so
operators gain trace evidence for deletions that currently flow silently:
* handle_delete_event_side_effect (NIP-29 kind-9005 moderation e-tag):
audit after the soft-delete succeeds. Actor is the kind-9005 signer.
* handle_standard_deletion_event (NIP-09 kind:5 e-tag loop): audit after
each successful soft_delete_event_and_update_thread. Actor is the
kind:5 signer. Detail carries the deleted event's kind and channel_id
so the entry remains queryable post-tombstone.
* handle_a_tag_deletion (NIP-09 a-tag coordinate): audit after a match
in soft_delete_by_coordinate. Object id is the full coordinate
<kind>:<pubkey>:<d_tag> which is stable across a replace and resolvable
by the operator to the deleted row; actor is the kind:5 signer.
Introduce enqueue_event_deleted_audit next to enqueue_event_created_audit,
mirroring its bounded-channel / propagate-backpressure / no-op-when-None
contract. The helper is best-effort (any failure-path is absorbed by the
send error branch, never panics the deletion flow).
deletion_path is recorded in detail ("moderation_e_tag" | "e_tag" |
"a_tag") so post-hoc queries can distinguish moderation deletions from
user self-deletions from coordinate deletions.
Fixes block#4034
Signed-off-by: Sarthak Singh <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.
Fixes #4034.
What
AuditAction::EventDeletedwas defined incrates/buzz-audit/src/action.rsbut had zero production call sites. Any NIP-09 event deletion flowed silently — no operator trace, no post-incident forensics.Change
Wire
AuditAction::EventDeletedinto all three NIP-09 deletion paths inbuzz-relay:handle_delete_event_side_effect(NIP-29 kind-9005 moderatione-tag): audit aftersoft_delete_event_and_update_threadsucceeds. Actor is the kind-9005 signer.handle_standard_deletion_event(NIP-09 kind:5e-tag loop): audit after each successful soft-delete. Actor is the kind:5 signer. Thedetailcarries the deleted event'skindandchannel_idso the entry remains queryable post-tombstone.handle_a_tag_deletion(NIP-09a-tag coordinate): audit aftersoft_delete_by_coordinatematches.object_idis the full coordinate string (<kind>:<pubkey>:<d_tag>) which is stable across a replace and resolvable to the deleted row.New helper
enqueue_event_deleted_audit(incrates/buzz-relay/src/handlers/event.rs) sits next toenqueue_event_created_auditand mirrors its contract:audit_txisNone(no-op)buzz_audit_send_errors_totalcounter — never panics the deletion flow.The
deletion_pathdetail field distinguishes the three paths ("moderation_e_tag"/"e_tag"/"a_tag") so operators can split moderation deletions from user self-deletions from coordinate deletions in post-hoc queries.Why this is safe
if !deletedguard, so a no-op (already-deleted or unknown id) does NOT produce a spurious audit entry.Verification
cargo check -p buzz-relay --lib— clean.cargo clippy -p buzz-relay --all-targets -- -D warnings— clean.cargo test -p buzz-relay --lib— 824 pass, 9 fail. The 9 failures are pre-existing PG-dependent tests inapi::media/api::admin(they fail identically onmain); none of them touchhandlers::side_effectsor the audit helper.Intended follow-ups (out of scope for this PR)
hard_delete_supersededpath incrates/buzz-db/src/lib.rs:4768(replace_parameterized_event) also deletes a row, but it's an upsert, not a NIP-09 deletion. I deliberately did not tag itEventDeleted— if the issue author wants the supersede case audited too, that's a separate change with a differentAuditAction(probably a newEventSupersededdiscriminator).