Block resubmission of deleted events by ID in SaveEvent and simplify deletion timestamp checks in QueryForDeleted.
This commit is contained in:
@@ -199,25 +199,12 @@ func (d *D) CheckForDeleted(ev *event.E, admins [][]byte) (err error) {
|
||||
sers = append(sers, s...)
|
||||
}
|
||||
if len(sers) > 0 {
|
||||
var idPkTss []*store.IdPkTs
|
||||
var tmp []*store.IdPkTs
|
||||
if tmp, err = d.GetFullIdPubkeyBySerials(sers); chk.E(err) {
|
||||
return
|
||||
}
|
||||
idPkTss = append(idPkTss, tmp...)
|
||||
// sort by timestamp, so the first is the newest
|
||||
sort.Slice(
|
||||
idPkTss, func(i, j int) bool {
|
||||
return idPkTss[i].Ts > idPkTss[j].Ts
|
||||
},
|
||||
// For e-tag deletions (delete by ID), any deletion event means the event cannot be resubmitted
|
||||
// regardless of timestamp, since it's a specific deletion of this exact event
|
||||
err = errorf.E(
|
||||
"blocked: %0x was deleted by ID and cannot be resubmitted",
|
||||
ev.ID,
|
||||
)
|
||||
if ev.CreatedAt < idPkTss[0].Ts {
|
||||
err = errorf.E(
|
||||
"blocked: %0x was deleted because it is older than the delete: event: %d delete: %d",
|
||||
ev.ID, ev.CreatedAt, idPkTss[0].Ts,
|
||||
)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,13 @@ func (d *D) SaveEvent(c context.Context, ev *event.E) (kc, vc int, err error) {
|
||||
log.E.F("error checking if event exists: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Check if the event has been deleted before allowing resubmission
|
||||
if err = d.CheckForDeleted(ev, nil); err != nil {
|
||||
log.I.F("SaveEvent: rejecting resubmission of deleted event ID=%s: %v", hex.Enc(ev.ID), err)
|
||||
err = errorf.E("blocked: %s", err.Error())
|
||||
return
|
||||
}
|
||||
// check for replacement
|
||||
if kind.IsReplaceable(ev.Kind) {
|
||||
// find the events and check timestamps before deleting
|
||||
|
||||
Reference in New Issue
Block a user