Skip to content

Commit

Permalink
fix: retry end game and cleanup seperately
Browse files Browse the repository at this point in the history
  • Loading branch information
yHSJ committed Dec 12, 2024
1 parent 8836589 commit a6988a7
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions referee/referee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,17 @@ console.log("Address: ", keys.address);

// check for extraneous state utxos and cleanup
while (true) {
console.log("Checking head's utxo set for stale games...");
try {
console.log("Checking head's utxo set for stale games...");
const response = await fetch(`${HYDRA_NODE}snapshot/utxo`);
const data = await response.json();
// Currently, we are just wiping the utxos after every game
// We may want to make this logic more robust if we are hoping to preserve those utxos
console.log("Current UTxO set size: ", Object.keys(data).length);
if (Object.keys(data).length > 1) {
console.log("Cleaning up old game state");
await fetch("http://localhost:8000/game/end_game", {
method: "POST",
});
await fetch("http://localhost:8000/game/cleanup", {
method: "POST",
});
console.log("Ending existing game...");
await endGame();
console.log("Cleaningup existing game...");
await cleanupGame();
console.log("Cleaned up! Node is back to healthy state");
}
break;
} catch (e) {
Expand All @@ -139,6 +136,40 @@ while (true) {
}
}

async function endGame() {
let status = 0;
while (![200, 201].includes(status)) {
try {
let response = await fetch("http://localhost:8000/game/end_game", {
method: "POST",
});
status = response.status;
} catch (e) {
console.log("Failed to end game: ", e);
await new Promise((resolve) => setTimeout(resolve, 200));
}
}

console.log("Succesfully ended game");
}

async function cleanupGame() {
let status = 0;
while (![200, 201].includes(status)) {
try {
let response = await fetch("http://localhost:8000/game/cleanup", {
method: "POST",
});
status = response.status;
} catch (e) {
console.log("Failed to cleanup game: ", e);
await new Promise((resolve) => setTimeout(resolve, 200));
}
}

console.log("Succesfully cleanedup game");
}

let exiting = false;
const { default: createModule } = await import("../websockets-doom.js");
const module = await createModule({
Expand Down

0 comments on commit a6988a7

Please sign in to comment.