Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# If your on windows use wsl / git bash / cygwin / msys2 with direnv

export CFG_PRESET=testnet-02

source ./.envrc.${CFG_PRESET}

# This repository only accepts signed commits:

# point out to users at commit time that commits need to be signed,
# not once they've done many commits and are trying to push a PR:
git config --local commit.gpgSign true
Expand All @@ -11,8 +16,6 @@ if [[ "$(uname -s)" == "Darwin" ]] && [[ "$(uname -m)" == "arm64" ]]; then
export DOCKER_DEFAULT_PLATFORM=linux/arm64
fi

export MIDNIGHT_NODE_IMAGE="midnightnetwork/midnight-node:0.8.0"

export POSTGRES_HOST="postgres" # TODO: replace with IP or host to postgres connection if not connecting to the docker one.
export POSTGRES_PORT="5432"
export POSTGRES_USER="postgres"
Expand All @@ -29,16 +32,11 @@ export POSTGRES_DB="cexplorer"
# We bring together the above variables into a database connection string:
export DB_SYNC_POSTGRES_CONNECTION_STRING="psql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB"

# These are well known addresses of a network that allow you to discover all the other nodes.
export BOOTNODES="/dns/boot-node-01.testnet-02.midnight.network/tcp/30333/ws/p2p/12D3KooWMjUq13USCvQR9Y6yFzYNYgTQBLNAcmc8psAuPx2UUdnB \
/dns/boot-node-02.testnet-02.midnight.network/tcp/30333/ws/p2p/12D3KooWR1cHBUWPCqk3uqhwZqUFekfWj8T7ozK6S18DUT745v4d \
/dns/boot-node-03.testnet-02.midnight.network/tcp/30333/ws/p2p/12D3KooWQxxUgq7ndPfAaCFNbAxtcKYxrAzTxDfRGNktF75SxdX5"

# To start with debug logs, add "-l debug" to APPEND_ARGS
# To expose safe rpc method to the host port 9944, add "--rpc-external" to APPEND_ARGS
export APPEND_ARGS="--no-private-ip --validator --pool-limit 10 --trie-cache-size 0 --prometheus-external"
# To expose safe rpc method to the host port 9944, add "--unsafe-rpc-external" to APPEND_ARGS or --validator
export APPEND_ARGS="--allow-private-ip --pool-limit 10 --trie-cache-size 0 --prometheus-external --rpc-external --rpc-cors all"

export CFG_PRESET=testnet-02

# Validator Values:
if [ ! -f node.privatekey ]; then
Expand Down
7 changes: 7 additions & 0 deletions .envrc.qanet
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# overrides for qanet
export MIDNIGHT_NODE_IMAGE="ghcr.io/midnight-ntwrk/midnight-node:0.12.0-rc.3"

# Well known addresses of network that allow discovery of all other nodes.
export BOOTNODES="/dns/boot-node-01.qanet.dev.midnight.network/tcp/30333/ws/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp \
/dns/boot-node-02.qanet.dev.midnight.network/tcp/30333/ws/p2p/12D3KooWHdiAxVd8uMQR1hGWXccidmfCwLqcMpGwR6QcTP6QRMuD \
/dns/boot-node-03.qanet.dev.midnight.network/tcp/30333/ws/p2p/12D3KooWSCufgHzV4fCwRijfH2k3abrpAJxTKxEvN1FDuRXA2U9x"
7 changes: 7 additions & 0 deletions .envrc.testnet-02
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# overrides for testnet-02
export MIDNIGHT_NODE_IMAGE="ghcr.io/midnight-ntwrk/midnight-node:0.12.0"

# These are well known addresses of a network that allow you to discover all the other nodes.
export BOOTNODES="/dns/boot-node-01.testnet-02.midnight.network/tcp/30333/ws/p2p/12D3KooWMjUq13USCvQR9Y6yFzYNYgTQBLNAcmc8psAuPx2UUdnB \
/dns/boot-node-02.testnet-02.midnight.network/tcp/30333/ws/p2p/12D3KooWR1cHBUWPCqk3uqhwZqUFekfWj8T7ozK6S18DUT745v4d \
/dns/boot-node-03.testnet-02.midnight.network/tcp/30333/ws/p2p/12D3KooWQxxUgq7ndPfAaCFNbAxtcKYxrAzTxDfRGNktF75SxdX5"
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ jobs:
# tell it your default branch so it can diff
DEFAULT_BRANCH: origin/main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_CONFIG: ".gitleaks.toml"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/data
*.privatekey
*.password
ogmios_client.log
5 changes: 5 additions & 0 deletions .gitleaks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[allowlist]
description = "Exclude public keys"
paths = [
'''(?:^|/)pc-chain-config\.json$''',
]
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## 🚀 Features

- Switch networks by altering CFG_PRESET only
- Added `test.sh` to detect problems and provide solutions.
- Added `reset-midnight.sh` script to clear down midnight's blockchain.
- `--validator` flag not set by default.
- Port from prior repository (#3)
- If direnv isn't working give an appropriate error message.
- /data dir should be .gitignored
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ This allows for easy orchestration of the Midnight Node service.

1. Clone repository

2. run `direnv allow` to load the environment variables
2. In `.envrc` set CFG_PRESET to be the environment you wish to point to (E.g. testnet-02).

3. Run `docker-compose up`
3. run `direnv allow` to load the environment variables

4. Run `docker-compose up`

The `.envrc` file will automatically create a random private key and save it as `midnight-node.privatekey`.

Expand Down Expand Up @@ -48,6 +50,11 @@ docker compose -f ./compose-partner-chains.yml -f ./compose.yml -f ./proof-serve

### Troubleshooting

### Connecting to Ogmios

If you're using `midnight-node smartcontract` or `midnight-node wizards` that need ogmios, and you're running midnight-node in docker you must pass `-O ws://host.docker.internal:1337` as an argument.
(Once PartnerChains 1.7+ is released OGMIOS_URL env var can be set so that it just works, but for now you have to pass it as an argument.)

### Clean start

To restart from fresh, run:
Expand All @@ -56,8 +63,8 @@ To restart from fresh, run:
docker compose -f ./compose-partner-chains.yml -f ./compose.yml -f ./proof-server.yml down -v
docker compose -f ./compose-partner-chains.yml -f ./compose.yml -f ./proof-server.yml kill
rm ~/ipc/node.socket
rm -R ./data
rm -R ./cardano-data
docker volume rm midnight-node-docker_midnight-data-testnet
```

#### Env vars not setup
Expand Down
1 change: 1 addition & 0 deletions cardano-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm \
-e CARDANO_NODE_SOCKET_PATH="/ipc/node.socket" \
-e CARDANO_NODE_NETWORK_ID="${CARDANO_NODE_NETWORK_ID}" \
-v ~/ipc:/ipc \
-v "${CARDANO_DATA_DIR}:/data" \
"${CARDANO_IMAGE}" \
cli "$@"
152 changes: 152 additions & 0 deletions check-chain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/usr/bin/env bash
set -euo pipefail

# ─── Configuration ─────────────────────────────────────────────────────────────
RPC_URL="http://127.0.0.1:9944" # your node’s JSON-RPC HTTP endpoint
RPC_URL="https://rpc.qanet.dev.midnight.network/"

echo Get genesis utxo from running midnight node...
GET_PC_PARAMS="curl -s -H \"Content-Type:application/json\" \
-d '{\"jsonrpc\":\"2.0\",\"method\":\"sidechain_getParams\",\"params\":[],\"id\":1}' \
\"$RPC_URL\""
GENESIS_UTXO=$(eval "$GET_PC_PARAMS" | jq -r '.result.genesis_utxo')
echo "GENESIS_UTXO=$GENESIS_UTXO"


export GENESIS_TX_HASH="${GENESIS_UTXO%%#*}"
export GENESIS_COIN_INDEX="${GENESIS_UTXO##*#}"
echo Check coin has been spent according to cardano...
QUERY_UTXO_CMD="./cardano-cli.sh query utxo --tx-in $GENESIS_UTXO --output-json 2>/dev/null"
genesis_utxo_json=$(eval "$QUERY_UTXO_CMD");

if [ "$genesis_utxo_json" = "{}" ] ; then
echo "✅ Genesis can't be found in UTXOs."
else
echo "❌ As part of chain registration process Genesis UTXO should have been spent but $genesis_utxo_json"
fi

# Assume that db-sync is synced.

# Find spent UTXO:
export PGPASSWORD=$POSTGRES_PASSWORD

spent_utxo=$(psql \
-h 127.0.0.1 -p "$POSTGRES_PORT" \
-U "$POSTGRES_USER" -d "$POSTGRES_DB" \
-tAc "SELECT
tx_out.tx_id,
encode(tx.hash, 'hex') AS tx_hash,
tx_out.index,
tx_out.value,
tx_out.address,
datum.bytes AS inline_datum
FROM tx_out
JOIN tx ON tx.id = tx_out.tx_id
LEFT JOIN datum ON tx_out.inline_datum_id = datum.id
WHERE tx.hash = '\\x${GENESIS_TX_HASH}'
LIMIT 10;
;")

if [ "$spent_utxo" = "" ] ; then
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"
else
echo "✅ Spent genesis coin found: '$spent_utxo'"

# can show url to tx hash https://preview.cexplorer.io/tx/1bb8027cb698c4b4c829396ac6eabac2ad46d80744c7a6822298dd76633c4f4f
fi


EPOCH_CMD="./cardano-cli.sh query tip 2>/dev/null"
tip=$(eval "$EPOCH_CMD");
CURRENT_EPOCH=$(echo "$tip" | jq -r '.epoch')
echo "epoc=$CURRENT_EPOCH"


# curl -s -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"sidechain_getStatus","params":[],"id":1}' https://rpc.qanet.dev.midnight.network/

# {"jsonrpc":"2.0","id":1,"result":{"sidechain":{"epoch":242583,"slot":291100548,"nextEpochTimestamp":1746604800000},"mainchain":{"epoch":925,"slot":79947270,"nextEpochTimestamp":1746662400000}}}%

# sidechain_getEpochCommittee
# sidechain_getRegistrations

EPOCH=$CURRENT_EPOCH
GET_PC_ARIADNE_PARAMS="curl -s -H \"Content-Type:application/json\" \
-d '{\"jsonrpc\":\"2.0\",\"method\":\"sidechain_getAriadneParameters\",\"params\":[$EPOCH],\"id\":1}' \"$RPC_URL\""
echo "$GET_PC_ARIADNE_PARAMS"
ARIADNE_PARAMS=$(eval "$GET_PC_ARIADNE_PARAMS")
if [[ $ARIADNE_PARAMS == *ExpectedDataNotFound* ]]; then
echo No current ariadne registration...
echo Checking for future ariadne registration...
START_EPOCH=$CURRENT_EPOCH # Assume EPOCH is already set

for ((i = 0; i <= 10; i++)); do
CURRENT_EPOCH=$((START_EPOCH + i))
echo "Checking epoch $CURRENT_EPOCH"

# Replace this with your actual command and condition
RESPONSE=$(curl -s -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"sidechain_getAriadneParameters","params":['"$CURRENT_EPOCH"'], "id":1}' "$RPC_URL")

if [[ "$RESPONSE" != *"ExpectedDataNotFound"* ]]; then
ACTIVE_EPOCH=$CURRENT_EPOCH
ARIADNE_PARAMS=$RESPONSE
DIFF=$((CURRENT_EPOCH - EPOCH))
echo "Registration found at epoch $CURRENT_EPOCH (active in $DIFF days time)"
echo "(SPOs can start registering now)"
break
fi
done
if [[ -z "$ACTIVE_EPOCH" ]]; then
echo "No pending registration for the chain. Please register the chain's Genesis UTXO:"
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.)"
fi
else
ACTIVE_EPOCH=$CURRENT_EPOCH
echo Found current ariadne registration...
fi

START_EPOCH=$CURRENT_EPOCH # Assume EPOCH is already set
for ((i = 0; i <= 10; i++)); do
CURRENT_EPOCH=$((START_EPOCH + i))
# echo "Checking epoch $CURRENT_EPOCH"

# Replace this with your actual command and condition
RESPONSE=$(curl -s -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"sidechain_getAriadneParameters","params":['"$CURRENT_EPOCH"'], "id":1}' "$RPC_URL")

if [[ "$RESPONSE" != *"ExpectedDataNotFound"* ]]; then
ACTIVE_EPOCH=$CURRENT_EPOCH
ARIADNE_PARAMS=$RESPONSE
DIFF=$((CURRENT_EPOCH - EPOCH))

# given there is a registration, check it's valid.
PERMISSIONED_CANDIDATES_VALID=$(echo "$ARIADNE_PARAMS" | jq -r '[.result.permissionedCandidates[] | select(.isValid == true)] | length')
CANDIDATES_VALID=$(echo "$ARIADNE_PARAMS" | jq -r '[.result.candidateRegistrations[][] | select(.isValid == true)] | length')
INTERNAL_SPO_COUNT=$(echo "$ARIADNE_PARAMS" |jq '.result.permissionedCandidates | length')
EXTERNAL_SPO_COUNT=$(echo "$ARIADNE_PARAMS" |jq '.result.candidateRegistrations | length')
if [[ "$PERMISSIONED_CANDIDATES_VALID" == "$INTERNAL_SPO_COUNT" ]]; then
PERM_MSG="✅ All $INTERNAL_SPO_COUNT permissioned candidates valid"
else
PERM_MSG="❌ $PERMISSIONED_CANDIDATES_VALID of $INTERNAL_SPO_COUNT permissioned candidates are valid"
fi
if [[ "$CANDIDATES_VALID" == "$EXTERNAL_SPO_COUNT" ]]; then
CAND_MSG="✅ All $EXTERNAL_SPO_COUNT candidate registrations valid"
else
CAND_MSG="❌ $CANDIDATES_VALID of $EXTERNAL_SPO_COUNT candidate registrations valid"
fi

echo "✅ Epoch $CURRENT_EPOCH ($DIFF days time) | $CAND_MSG | $PERM_MSG"
else
echo "❌ Epoch $CURRENT_EPOCH : ExpectedDataNotFound"
fi
done

# midnight_apiVersions
# midnight_ledgerVersion



# Registrations status for epoch 929:
# running external command: /midnight-node registration-status --mainchain-pub-key 0x1f4bf447da2b78482b2656f7f504b321c9f0b8712faabbd0de7c47ab13d9cd4a --mc-epoch-number 929 --chain chain-spec.json --base-path /tmp/.tmpii6vGf
# command output: Error: Input("ChainSpec Parse error: Error opening spec file `chain-spec.json`: No such file or directory (os error 2)")
# Running executable failed with status exit status
36 changes: 7 additions & 29 deletions compose-partner-chains.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ volumes:
db-sync-data: {}
postgres-data: {}
ogmios-data: {}
kupo-data: {}

services:
cardano-node:
image: ${CARDANO_IMAGE}
platform: linux/amd64
restart: unless-stopped
container_name: cardano-node
ports:
Expand Down Expand Up @@ -52,10 +52,10 @@ services:
timeout: 5s
retries: 5

db-sync:
cardano-db-sync:
image: ghcr.io/intersectmbo/cardano-db-sync:13.6.0.4
platform: linux/amd64
container_name: db-sync
container_name: cardano-db-sync
restart: unless-stopped
depends_on:
postgres:
Expand All @@ -71,9 +71,10 @@ services:
- ${HOME_IPC}:/node-ipc # Use ${HOME_IPC} from .envrc
- db-sync-data:/var/lib

ogmios:
image: cardanosolutions/ogmios:v6.5.0
container_name: ogmios
cardano-ogmios:
image: cardanosolutions/ogmios:v6.11.0
platform: linux/amd64
container_name: cardano-ogmios
restart: unless-stopped
environment:
- DATA_DIR=/data
Expand All @@ -89,26 +90,3 @@ services:
- /config/${CARDANO_NETWORK}/cardano-node/config.json
- --host
- 0.0.0.0

kupo:
image: cardanosolutions/kupo:v2.9.0
container_name: kupo
command:
- --node-socket
- /ipc/node.socket
- --node-config
- /config/config.json
- --host
- 0.0.0.0
- --workdir
- /db
- --match
- "*"
- --since
- "origin"
ports:
- "1442:1442"
volumes:
- kupo-data:/db
- ${HOME_IPC}:/ipc # Use ${HOME_IPC} from .envrc
- $CARDANO_CONFIG_DIR:/config
2 changes: 2 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ services:
test: [ "CMD", "curl", "-f", "http://localhost:9944/health" ]
interval: 2s
volumes:
- ./data:/data
- ./envs/${CFG_PRESET}/pc-chain-config.json:/pc-chain-config.json
- midnight-data-testnet:/node
Loading