|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# NOTE: This script patches the genesis timestamp of a fork config so a new |
| 4 | +# network could be schedueld to genesis in some instant in the future. |
| 5 | +# It differs from create_runtime_config.sh in that it's aimed at dealing with |
| 6 | +# output generated by `mina advanced generate-hard-fork-config` |
| 7 | + |
| 8 | +set -eux -o pipefail |
| 9 | + |
| 10 | +# ==================== Inputs to this script ==================== |
| 11 | +# The fork config we aim to patch on |
| 12 | +FORK_CONFIG_TO_PATCH=${FORK_CONFIG_TO_PATCH:?FORK_CONFIG_TO_PATCH is not provided} |
| 13 | +# Prefork network slot time in seconds |
| 14 | +PREFORK_SLOT_TIME_SEC=${PREFORK_SLOT_TIME_SEC:?PREFORK_SLOT_TIME_SEC is not provided} |
| 15 | +# Delta in slots between the `slot_chain_end` of prefork network and |
| 16 | +# `global_slot_since_genesis` of postfork network |
| 17 | +HARDFORK_GENESIS_SLOT_DELTA=${HARDFORK_GENESIS_SLOT_DELTA:?HARDFORK_GENESIS_SLOT_DELTA is not provided} |
| 18 | +# =============================================================== |
| 19 | + |
| 20 | +PREFORK_SLOT_CHAIN_END_TIMESTAMP=$(jq -r '.genesis.genesis_state_timestamp' "$FORK_CONFIG_TO_PATCH") |
| 21 | +PREFORK_SLOT_CHAIN_END=$(jq -r '.proof.fork.global_slot_since_genesis' "$FORK_CONFIG_TO_PATCH") |
| 22 | + |
| 23 | +HARDFORK_GENESIS_SEC_DELTA=$((PREFORK_SLOT_TIME_SEC * HARDFORK_GENESIS_SLOT_DELTA)) |
| 24 | +POSTFORK_GENESIS_TIMESTAMP=$(date -u -d "$PREFORK_SLOT_CHAIN_END_TIMESTAMP + $HARDFORK_GENESIS_SEC_DELTA seconds" +"%Y-%m-%dT%H:%M:%S.%6NZ") |
| 25 | +POSTFORK_GENESIS_SLOT=$((PREFORK_SLOT_CHAIN_END + HARDFORK_GENESIS_SLOT_DELTA)) |
| 26 | + |
| 27 | +jq -M \ |
| 28 | + --arg genesis_timestamp "$POSTFORK_GENESIS_TIMESTAMP" \ |
| 29 | + --argjson slot "$POSTFORK_GENESIS_SLOT" \ |
| 30 | + ' .genesis.genesis_state_timestamp = $genesis_timestamp |
| 31 | + | .proof.fork.global_slot_since_genesis = $slot |
| 32 | + ' \ |
| 33 | + "$FORK_CONFIG_TO_PATCH" |
0 commit comments