Skip to content

Prevent overlapping battles from overwriting pet progress #80

Open

Description

@suryaswain612

Summary

When a battle is accepted, the backend reads both pets' progress before it locks the pets. If one of the pets is still in another battle, the new battle is built from its old level, XP, streak and cooldown. When the other battle finishes and releases its lock, the new battle can still open. Later it saves its result over the progress from the first battle.

The result is that a pet can skip its cooldown, and the XP and level-up from the first battle are lost. A player can also do this on purpose to an opponent's pet.

In accept.service.ts, freezeFighters reads progress at line 124, but openBattle takes the locks only at line 563. applyProgression in sign.worker.ts then writes absolute values for level, xp and streak.

Todo

  • Take the pet locks before building the snapshot, or read the progress again inside the openBattle transaction and refuse the battle if it changed
  • When saving progress in applyProgression, check that the pet's last receipt hash still matches the one the battle started from
  • Return 409 pet-locked when either pet already has an open battle
  • Add a test where two accepts for the same pet run while the first battle is finishing
  • Add a per-pet continuity check to the verifier, so a snapshot must follow from the pet's previous receipt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions