From 907d5c6dc100ddc47343421db89f5ae53af5d68f Mon Sep 17 00:00:00 2001 From: doomsower <12031673+doomsower@users.noreply.github.com> Date: Mon, 22 Jul 2024 15:01:07 -0500 Subject: [PATCH] fix: milliseconds bug --- src/services/RedstoneServiceV3.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/services/RedstoneServiceV3.ts b/src/services/RedstoneServiceV3.ts index 91898ca..02b63ae 100644 --- a/src/services/RedstoneServiceV3.ts +++ b/src/services/RedstoneServiceV3.ts @@ -83,13 +83,13 @@ export class RedstoneServiceV3 { // // Also, when forking anvil->anvil (when running on testnets) block.timestamp can be in future because min ts for block is 1 seconds, // and scripts can take dozens of blocks (hundreds for faucet). So we take min value; - const now = new Date().getTime(); - const anvilTs = 10 * Math.floor(Number(block.timestamp) / 10) * 1000; - const fromNowTs = 10_000 * Math.floor(now / 10_000 - 1); - this.#optimisticTimestamp = Math.min(anvilTs, fromNowTs); - const delta = Math.floor(now / 1000) - this.#optimisticTimestamp; + const nowMs = new Date().getTime(); + const anvilTsS = 10 * Math.floor(Number(block.timestamp) / 10); + const fromNowTsS = 10 * Math.floor(nowMs / 10_000 - 1); + this.#optimisticTimestamp = Math.min(anvilTsS, fromNowTsS); + const deltaS = Math.floor(nowMs / 1000) - this.#optimisticTimestamp; this.logger.info( - `will use optimistic timestamp: ${this.#optimisticTimestamp} (delta: ${delta}s)`, + `will use optimistic timestamp: ${this.#optimisticTimestamp} (delta: ${deltaS}s)`, ); } }