From 9b0e2982460c4bb55f040c389b8d9bdea9978b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pr=C3=A9vost?= <998369+prevostc@users.noreply.github.com> Date: Sat, 3 Aug 2024 14:49:24 +0200 Subject: [PATCH] Add rng to allow redeploy of the same version --- .gitignore | 5 ++++- bin/prepare.sh | 6 +++++- src/common/clock.ts | 3 ++- src/random.template.ts | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 src/random.template.ts diff --git a/.gitignore b/.gitignore index 7fc02fe..7dbbd2a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,7 @@ node_modules subgraph.yaml src/config.ts -tests/.latest.json \ No newline at end of file +tests/.latest.json + +random.json +src/random.ts \ No newline at end of file diff --git a/bin/prepare.sh b/bin/prepare.sh index 0da4048..3c8e179 100755 --- a/bin/prepare.sh +++ b/bin/prepare.sh @@ -16,4 +16,8 @@ fi set -e yarn --silent run mustache config/$CHAIN.json subgraph.template.yaml > subgraph.yaml -yarn --silent run mustache config/$CHAIN.json src/config.template.ts > src/config.ts \ No newline at end of file +yarn --silent run mustache config/$CHAIN.json src/config.template.ts > src/config.ts + +RNG=$((1 + $RANDOM % 100000)) +echo '{"random": '$RNG'}' > random.json +yarn --silent run mustache random.json src/random.template.ts > src/random.ts \ No newline at end of file diff --git a/src/common/clock.ts b/src/common/clock.ts index 05d9a2a..9dd1f5b 100644 --- a/src/common/clock.ts +++ b/src/common/clock.ts @@ -3,13 +3,14 @@ import { HOUR } from "../common/utils/time" import { getClockTick } from "../common/entity/clock" import { updateClmDataOnClockTick } from "../clm/clock" import { updateClassicDataOnClockTick } from "../classic/clock" +import { RANDOM } from "../random" export function handleClockTick(block: ethereum.Block): void { const timestamp = block.timestamp let tickRes1h = getClockTick(timestamp, HOUR) if (!tickRes1h.isNew) { - log.debug("handleClockTick: tick already exists for {}", [tickRes1h.tick.id.toHexString()]) + log.debug("handleClockTick[rng={}]: tick already exists for {}", [RANDOM, tickRes1h.tick.id.toHexString()]) return } tickRes1h.tick.save() diff --git a/src/random.template.ts b/src/random.template.ts new file mode 100644 index 0000000..82f6aa8 --- /dev/null +++ b/src/random.template.ts @@ -0,0 +1,2 @@ +// force the subgraph has to be different to make sure we don't fail on redeploy +export const RANDOM = "{{random}}"