mischief: retry web contract insert on transient failure, refund only on lost race

This commit is contained in:
prosolis
2026-07-15 00:20:34 -07:00
parent 11bfce780c
commit c9282cb18a

View File

@@ -941,13 +941,24 @@ func (p *AdventurePlugin) placeWebMischief(order peteclient.MischiefOrder) misch
WindowEndsAt: now.Add(mischiefWindow), WindowEndsAt: now.Add(mischiefWindow),
} }
if err := insertMischiefContract(c); err != nil { if err := insertMischiefContract(c); err != nil {
// The one-live-per-target index rejected us — a rival contract is already // Distinguish the one legitimate rejection from a transient write failure,
// on this target (ours isn't: we checked order_guid up top). Refund and // the same way the Matrix path does — the two want opposite handling.
// bounce; the buyer lost a race, not money. if liveMischiefForTarget(targetID) != nil {
// A rival contract is already on this target (ours isn't: we checked
// order_guid up top). Refund and terminally bounce; the buyer lost a
// race, not money.
refund() refund()
slog.Warn("mischief: web contract insert rejected", "order", order.GUID, "target", targetID, "err", err) slog.Warn("mischief: web contract lost the race", "order", order.GUID, "target", targetID)
return mischiefWebResult{Status: mischiefWebBouncedIneligible, Detail: "someone already sent a monster their way"} return mischiefWebResult{Status: mischiefWebBouncedIneligible, Detail: "someone already sent a monster their way"}
} }
// A real write failure with no rival to blame. Leave the debit in place
// and the order pending — the guid makes the next poll's re-run a no-op on
// the money and a clean retry on the insert, which is the whole point of
// keying on it. Refunding here would both drop a placeable hit and, worse,
// hand out a free contract if the retry then succeeded against the credit.
slog.Warn("mischief: web contract insert failed, will retry", "order", order.GUID, "target", targetID, "err", err)
return mischiefWebResult{Retry: true}
}
p.announceMischiefContract(c, tier) p.announceMischiefContract(c, tier)
p.dmMischiefVictim(c, tier) p.dmMischiefVictim(c, tier)