From 45dc0a796e8e1a8f1304ea27efc99d4242fe785c Mon Sep 17 00:00:00 2001 From: yHSJ Date: Tue, 3 Dec 2024 17:04:39 -0500 Subject: [PATCH] fix: conserve value in spam txs --- src/utils/HydraMultiplayer/base.ts | 84 +++++++++++++++--------------- src/utils/hydra.ts | 14 ----- 2 files changed, 42 insertions(+), 56 deletions(-) diff --git a/src/utils/HydraMultiplayer/base.ts b/src/utils/HydraMultiplayer/base.ts index b0010e3..5102165 100644 --- a/src/utils/HydraMultiplayer/base.ts +++ b/src/utils/HydraMultiplayer/base.ts @@ -83,48 +83,48 @@ export abstract class HydraMultiplayer { } public observeTx(txId: TxHash, tx: any): void { - try { - const body = tx[0]; - const outputs = body["1"]; - const output = outputs[0]; - const datumRaw: Uint8Array | undefined = output?.["2"]?.[1]?.value; - if (!datumRaw) { - return; - } - const packets = decodePackets(datumRaw); - if (!packets) { - // We failed to decode packets, so this might be a new game or join game tx - const game = decodeGame(datumRaw); - if (game.players.length == 1) { - this.gameId = txId; - this.players = game.players; - this.onNewGame?.( - txId, - Number(game.playerCount), - Number(game.botCount), - game.players[0], - ); - } else { - if (this.players?.toString() !== game.players.toString()) { - this.players = game.players; - this.onPlayerJoin?.(this.gameId!, game.players); - } - } - return; - } - for (const packet of packets) { - this.onPacket?.(tx, packet); - if (packet.to == this.myIP) { - const buf = this.module._malloc!(packet.data.length); - this.module.HEAPU8!.set(packet.data, buf); - this.module._ReceivePacket!(packet.from, buf, packet.data.length); - this.module._free!(buf); - this.onTxSeen?.(txId, tx); - } - } - } catch (err) { - console.warn(err); - } + // try { + // const body = tx[0]; + // const outputs = body["1"]; + // const output = outputs[0]; + // const datumRaw: Uint8Array | undefined = output?.["2"]?.[1]?.value; + // if (!datumRaw) { + // return; + // } + // const packets = decodePackets(datumRaw); + // if (!packets) { + // // We failed to decode packets, so this might be a new game or join game tx + // const game = decodeGame(datumRaw); + // if (game.players.length == 1) { + // this.gameId = txId; + // this.players = game.players; + // this.onNewGame?.( + // txId, + // Number(game.playerCount), + // Number(game.botCount), + // game.players[0], + // ); + // } else { + // if (this.players?.toString() !== game.players.toString()) { + // this.players = game.players; + // this.onPlayerJoin?.(this.gameId!, game.players); + // } + // } + // return; + // } + // for (const packet of packets) { + // this.onPacket?.(tx, packet); + // if (packet.to == this.myIP) { + // const buf = this.module._malloc!(packet.data.length); + // this.module.HEAPU8!.set(packet.data, buf); + // this.module._ReceivePacket!(packet.from, buf, packet.data.length); + // this.module._free!(buf); + // this.onTxSeen?.(txId, tx); + // } + // } + // } catch (err) { + // console.warn(err); + // } } protected signData(data: string): string { diff --git a/src/utils/hydra.ts b/src/utils/hydra.ts index a4f27e8..45bcc8d 100644 --- a/src/utils/hydra.ts +++ b/src/utils/hydra.ts @@ -119,19 +119,6 @@ export class Hydra { break; case "TxValid": { - if (this.startTime === 0) { - this.startTime = performance.now(); - } - this.tx_count += 1; - const endTime = performance.now(); - if (endTime > this.startTime + 1000) { - console.log( - `Current Data: ${this.tx_count} Transactions | ${this.tx_count / ((endTime - this.startTime) / 1000)} TPS`, - ); - - this.startTime = performance.now(); - this.tx_count = 0; - } // // Record seen time // if (this.tx_timings[txid]?.sent) { // const seenTime = now - this.tx_timings[txid].sent; @@ -235,7 +222,6 @@ export class Hydra { const txId = txParsed.body().hash(); this.tx_timings[txId] = { sent: performance.now() }; this.tx_count++; - this.connection.send( JSON.stringify({ tag: "NewTx",