Skip to content

Commit

Permalink
Clean up old state before hydra, so we know hydra is online
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumplation committed Dec 10, 2024
1 parent d4ea435 commit aacbdb3
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions referee/referee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,30 @@ const keys = {
};
console.log("Address: ", keys.address);


// check for extraneous state utxos and cleanup
while(true) {
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
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",
});
}
break;
} catch (e) {
console.warn("Failed to fetch and parse node utxos: ", e);
}
}

const { default: createModule } = await import("../websockets-doom.js");
const module = await createModule({
locateFile: (path, scripts) => {
Expand Down Expand Up @@ -232,28 +256,6 @@ global.playerDisconnected = async (addr: number, player: number) => {
}
};

// check for extraneous state utxos and cleanup
for(let i = 0; i < 5; i++) {
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
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",
});
}
break;
} catch (e) {
console.warn("Failed to fetch and parse node utxos: ", e);
}
}

// Log a new game or player joined transaction if we see it
let timeout = 60_000;
Expand Down

0 comments on commit aacbdb3

Please sign in to comment.