|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# ─── Configuration ───────────────────────────────────────────────────────────── |
| 5 | +RPC_URL="http://127.0.0.1:9944" # your node’s JSON-RPC HTTP endpoint |
| 6 | +RPC_URL="https://rpc.qanet.dev.midnight.network/" |
| 7 | + |
| 8 | +echo Get genesis utxo from running midnight node... |
| 9 | +GET_PC_PARAMS="curl -s -H \"Content-Type:application/json\" \ |
| 10 | + -d '{\"jsonrpc\":\"2.0\",\"method\":\"sidechain_getParams\",\"params\":[],\"id\":1}' \ |
| 11 | + \"$RPC_URL\"" |
| 12 | +GENESIS_UTXO=$(eval "$GET_PC_PARAMS" | jq -r '.result.genesis_utxo') |
| 13 | +echo "GENESIS_UTXO=$GENESIS_UTXO" |
| 14 | + |
| 15 | + |
| 16 | +export GENESIS_TX_HASH="${GENESIS_UTXO%%#*}" |
| 17 | +export GENESIS_COIN_INDEX="${GENESIS_UTXO##*#}" |
| 18 | +echo Check coin has been spent according to cardano... |
| 19 | +QUERY_UTXO_CMD="./cardano-cli.sh query utxo --tx-in $GENESIS_UTXO --output-json 2>/dev/null" |
| 20 | +genesis_utxo_json=$(eval "$QUERY_UTXO_CMD"); |
| 21 | + |
| 22 | +if [ "$genesis_utxo_json" = "{}" ] ; then |
| 23 | + echo "✅ Genesis can't be found in UTXOs." |
| 24 | +else |
| 25 | + echo "❌ As part of chain registration process Genesis UTXO should have been spent but $genesis_utxo_json" |
| 26 | +fi |
| 27 | + |
| 28 | +# Assume that db-sync is synced. |
| 29 | + |
| 30 | +# Find spent UTXO: |
| 31 | +export PGPASSWORD=$POSTGRES_PASSWORD |
| 32 | + |
| 33 | +spent_utxo=$(psql \ |
| 34 | + -h 127.0.0.1 -p "$POSTGRES_PORT" \ |
| 35 | + -U "$POSTGRES_USER" -d "$POSTGRES_DB" \ |
| 36 | + -tAc "SELECT |
| 37 | + tx_out.tx_id, |
| 38 | + encode(tx.hash, 'hex') AS tx_hash, |
| 39 | + tx_out.index, |
| 40 | + tx_out.value, |
| 41 | + tx_out.address, |
| 42 | + datum.bytes AS inline_datum |
| 43 | +FROM tx_out |
| 44 | +JOIN tx ON tx.id = tx_out.tx_id |
| 45 | +LEFT JOIN datum ON tx_out.inline_datum_id = datum.id |
| 46 | +WHERE tx.hash = '\\x${GENESIS_TX_HASH}' |
| 47 | +LIMIT 10; |
| 48 | + ;") |
| 49 | + |
| 50 | +if [ "$spent_utxo" = "" ] ; then |
| 51 | + echo "❌ As part of chain registration process Genesis UTXO should have been spent but can't find it in db-sync's spent list: $spent_utxo" |
| 52 | +else |
| 53 | + echo "✅ Spent genesis coin found: '$spent_utxo'" |
| 54 | + |
| 55 | + # can show url to tx hash https://preview.cexplorer.io/tx/1bb8027cb698c4b4c829396ac6eabac2ad46d80744c7a6822298dd76633c4f4f |
| 56 | +fi |
| 57 | + |
| 58 | + |
| 59 | +EPOCH_CMD="./cardano-cli.sh query tip 2>/dev/null" |
| 60 | +tip=$(eval "$EPOCH_CMD"); |
| 61 | +CURRENT_EPOCH=$(echo "$tip" | jq -r '.epoch') |
| 62 | +echo "epoc=$CURRENT_EPOCH" |
| 63 | + |
| 64 | + |
| 65 | +# curl -s -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"sidechain_getStatus","params":[],"id":1}' https://rpc.qanet.dev.midnight.network/ |
| 66 | + |
| 67 | +# {"jsonrpc":"2.0","id":1,"result":{"sidechain":{"epoch":242583,"slot":291100548,"nextEpochTimestamp":1746604800000},"mainchain":{"epoch":925,"slot":79947270,"nextEpochTimestamp":1746662400000}}}% |
| 68 | + |
| 69 | +# sidechain_getEpochCommittee |
| 70 | +# sidechain_getRegistrations |
| 71 | + |
| 72 | +EPOCH=$CURRENT_EPOCH |
| 73 | +GET_PC_ARIADNE_PARAMS="curl -s -H \"Content-Type:application/json\" \ |
| 74 | + -d '{\"jsonrpc\":\"2.0\",\"method\":\"sidechain_getAriadneParameters\",\"params\":[$EPOCH],\"id\":1}' \"$RPC_URL\"" |
| 75 | +echo "$GET_PC_ARIADNE_PARAMS" |
| 76 | +ARIADNE_PARAMS=$(eval "$GET_PC_ARIADNE_PARAMS") |
| 77 | +if [[ $ARIADNE_PARAMS == *ExpectedDataNotFound* ]]; then |
| 78 | + echo No current ariadne registration... |
| 79 | + echo Checking for future ariadne registration... |
| 80 | + START_EPOCH=$CURRENT_EPOCH # Assume EPOCH is already set |
| 81 | + |
| 82 | + for ((i = 0; i <= 10; i++)); do |
| 83 | + CURRENT_EPOCH=$((START_EPOCH + i)) |
| 84 | + echo "Checking epoch $CURRENT_EPOCH" |
| 85 | + |
| 86 | + # Replace this with your actual command and condition |
| 87 | + RESPONSE=$(curl -s -H "Content-Type: application/json" \ |
| 88 | + -d '{"jsonrpc":"2.0","method":"sidechain_getAriadneParameters","params":['"$CURRENT_EPOCH"'], "id":1}' "$RPC_URL") |
| 89 | + |
| 90 | + if [[ "$RESPONSE" != *"ExpectedDataNotFound"* ]]; then |
| 91 | + ACTIVE_EPOCH=$CURRENT_EPOCH |
| 92 | + ARIADNE_PARAMS=$RESPONSE |
| 93 | + DIFF=$((CURRENT_EPOCH - EPOCH)) |
| 94 | + echo "Registration found at epoch $CURRENT_EPOCH (active in $DIFF days time)" |
| 95 | + echo "(SPOs can start registering now)" |
| 96 | + break |
| 97 | + fi |
| 98 | + done |
| 99 | + if [[ -z "$ACTIVE_EPOCH" ]]; then |
| 100 | + echo "No pending registration for the chain. Please register the chain's Genesis UTXO:" |
| 101 | + echo "./midnight-node wizards setup-main-chain-state (but ./midnight-node wizards prepare-configuration will need to have been done first and ./midnight-node wizards generate-keys before that.)" |
| 102 | + fi |
| 103 | +else |
| 104 | + ACTIVE_EPOCH=$CURRENT_EPOCH |
| 105 | + echo Found current ariadne registration... |
| 106 | +fi |
| 107 | + |
| 108 | +START_EPOCH=$CURRENT_EPOCH # Assume EPOCH is already set |
| 109 | +for ((i = 0; i <= 10; i++)); do |
| 110 | + CURRENT_EPOCH=$((START_EPOCH + i)) |
| 111 | + # echo "Checking epoch $CURRENT_EPOCH" |
| 112 | + |
| 113 | + # Replace this with your actual command and condition |
| 114 | + RESPONSE=$(curl -s -H "Content-Type: application/json" \ |
| 115 | + -d '{"jsonrpc":"2.0","method":"sidechain_getAriadneParameters","params":['"$CURRENT_EPOCH"'], "id":1}' "$RPC_URL") |
| 116 | + |
| 117 | + if [[ "$RESPONSE" != *"ExpectedDataNotFound"* ]]; then |
| 118 | + ACTIVE_EPOCH=$CURRENT_EPOCH |
| 119 | + ARIADNE_PARAMS=$RESPONSE |
| 120 | + DIFF=$((CURRENT_EPOCH - EPOCH)) |
| 121 | + |
| 122 | + # given there is a registration, check it's valid. |
| 123 | + PERMISSIONED_CANDIDATES_VALID=$(echo "$ARIADNE_PARAMS" | jq -r '[.result.permissionedCandidates[] | select(.isValid == true)] | length') |
| 124 | + CANDIDATES_VALID=$(echo "$ARIADNE_PARAMS" | jq -r '[.result.candidateRegistrations[][] | select(.isValid == true)] | length') |
| 125 | + INTERNAL_SPO_COUNT=$(echo "$ARIADNE_PARAMS" |jq '.result.permissionedCandidates | length') |
| 126 | + EXTERNAL_SPO_COUNT=$(echo "$ARIADNE_PARAMS" |jq '.result.candidateRegistrations | length') |
| 127 | + if [[ "$PERMISSIONED_CANDIDATES_VALID" == "$INTERNAL_SPO_COUNT" ]]; then |
| 128 | + PERM_MSG="✅ All $INTERNAL_SPO_COUNT permissioned candidates valid" |
| 129 | + else |
| 130 | + PERM_MSG="❌ $PERMISSIONED_CANDIDATES_VALID of $INTERNAL_SPO_COUNT permissioned candidates are valid" |
| 131 | + fi |
| 132 | + if [[ "$CANDIDATES_VALID" == "$EXTERNAL_SPO_COUNT" ]]; then |
| 133 | + CAND_MSG="✅ All $EXTERNAL_SPO_COUNT candidate registrations valid" |
| 134 | + else |
| 135 | + CAND_MSG="❌ $CANDIDATES_VALID of $EXTERNAL_SPO_COUNT candidate registrations valid" |
| 136 | + fi |
| 137 | + |
| 138 | + echo "✅ Epoch $CURRENT_EPOCH ($DIFF days time) | $CAND_MSG | $PERM_MSG" |
| 139 | + else |
| 140 | + echo "❌ Epoch $CURRENT_EPOCH : ExpectedDataNotFound" |
| 141 | + fi |
| 142 | +done |
| 143 | + |
| 144 | +# midnight_apiVersions |
| 145 | +# midnight_ledgerVersion |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | +# Registrations status for epoch 929: |
| 150 | +# running external command: /midnight-node registration-status --mainchain-pub-key 0x1f4bf447da2b78482b2656f7f504b321c9f0b8712faabbd0de7c47ab13d9cd4a --mc-epoch-number 929 --chain chain-spec.json --base-path /tmp/.tmpii6vGf |
| 151 | +# command output: Error: Input("ChainSpec Parse error: Error opening spec file `chain-spec.json`: No such file or directory (os error 2)") |
| 152 | +# Running executable failed with status exit status |
0 commit comments