Skip to content

Commit

Permalink
Add rng to allow redeploy of the same version
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Aug 3, 2024
1 parent 9c86a45 commit 9b0e298
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ node_modules
subgraph.yaml
src/config.ts

tests/.latest.json
tests/.latest.json

random.json
src/random.ts
6 changes: 5 additions & 1 deletion bin/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
3 changes: 2 additions & 1 deletion src/common/clock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/random.template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// force the subgraph has to be different to make sure we don't fail on redeploy
export const RANDOM = "{{random}}"

0 comments on commit 9b0e298

Please sign in to comment.