make replacement not delete, and filter query results respect limits

- Added detailed logging in GetSerialsByRange, CheckForDeleted, and SaveEvent functions to improve traceability during event processing.
- Implemented safety limits in GetSerialsByRange to prevent infinite loops during debugging.
- Updated event deletion logic to ensure only specific events are marked as deleted, improving clarity in event management.
- Refactored WouldReplaceEvent to maintain compatibility while simplifying the return values.
- Adjusted test cases to verify the correct behavior of replaced events and their deletion status.
This commit is contained in:
2025-10-20 21:08:48 +01:00
parent 65e8ab4fbe
commit c7dcbdec9f
5 changed files with 75 additions and 71 deletions

View File

@@ -5,6 +5,7 @@ import (
"lol.mleku.dev/chk"
"lol.mleku.dev/errorf"
"lol.mleku.dev/log"
"next.orly.dev/pkg/database/indexes/types"
"next.orly.dev/pkg/encoders/event"
"next.orly.dev/pkg/encoders/filter"
@@ -20,6 +21,7 @@ import (
// pubkeys that also may delete the event, normally only the author is allowed
// to delete an event.
func (d *D) CheckForDeleted(ev *event.E, admins [][]byte) (err error) {
log.T.F("CheckForDeleted: checking event %x", ev.ID)
keys := append([][]byte{ev.Pubkey}, admins...)
authors := tag.NewFromBytesSlice(keys...)
// if the event is addressable, check for a deletion event with the same
@@ -184,26 +186,33 @@ func (d *D) CheckForDeleted(ev *event.E, admins [][]byte) (err error) {
return
}
// otherwise we check for a delete by event id
log.T.F("CheckForDeleted: checking for e-tag deletion of event %x", ev.ID)
log.T.F("CheckForDeleted: authors filter: %v", authors)
log.T.F("CheckForDeleted: looking for tag e with value: %s", hex.Enc(ev.ID))
var idxs []Range
if idxs, err = GetIndexesFromFilter(
&filter.F{
Authors: authors,
Kinds: kind.NewS(kind.Deletion),
Tags: tag.NewS(
tag.NewFromAny("#e", hex.Enc(ev.ID)),
tag.NewFromAny("e", hex.Enc(ev.ID)),
),
},
); chk.E(err) {
return
}
log.T.F("CheckForDeleted: found %d indexes", len(idxs))
var sers types.Uint40s
for _, idx := range idxs {
for i, idx := range idxs {
log.T.F("CheckForDeleted: checking index %d: %v", i, idx)
var s types.Uint40s
if s, err = d.GetSerialsByRange(idx); chk.E(err) {
return
}
log.T.F("CheckForDeleted: index %d returned %d serials", i, len(s))
if len(s) > 0 {
// Any e-tag deletion found means the exact event was deleted and cannot be resubmitted
log.T.F("CheckForDeleted: found e-tag deletion for event %x", ev.ID)
err = errorf.E("blocked: %0x has been deleted", ev.ID)
return
}