diff --git a/.envrc b/.envrc index c642786..2f64928 100644 --- a/.envrc +++ b/.envrc @@ -22,29 +22,51 @@ export POSTGRES_USER="postgres" # A random password is used for your safety. Docker (but not podman) exposes # ports to the internet by default. This needs to be unguessable. -if [ ! -f postgres.password ]; then - uuidgen | tr -d '-' | head -c 16 > postgres.password +if [ ! -f postgres.secret ]; then + uuidgen | tr -d '-' | head -c 16 > postgres.secret fi -export POSTGRES_PASSWORD="$(cat ./postgres.password)" +export POSTGRES_PASSWORD="$(cat ./postgres.secret)" 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" - # To start with debug logs, add "-l debug" to APPEND_ARGS # 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" -# Validator Values: -if [ ! -f node.privatekey ]; then - # generate node key like this: - DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -it docker.io/parity/subkey:latest generate-node-key | sed -n '2p' > midnight-node.privatekey - # Use the second line of output for NODE_KEY (that's what sed -n '2p' does) +# Node Key: +# Generate a unique node key for P2P networking +if [ ! -f midnight-node.secret ]; then + # Generate node key using parity/subkey + DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm docker.io/parity/subkey:latest generate-node-key > midnight-node.secret +fi +export NODE_KEY="$(cat ./midnight-node.secret)" + +# Indexer Values: +if [ ! -f indexer.secret ]; then + # Generate 32-byte hex secret for indexer + uuidgen | tr -d '-' | head -c 32 > indexer.secret +fi +export INDEXER_SECRET="$(cat ./indexer.secret)" + +# +# Mock mode vs Cardano stack: +# Set USE_MOCK=true to run midnight-node with mock Cardano (fast, for dev/testing) +# Set USE_MOCK=false (default) to run full Cardano stack (real blockchain data) +# +export USE_MOCK=${USE_MOCK:-false} + +if [ "$USE_MOCK" = "true" ]; then + # Mock mode: Skip Cardano services and indexer + export COMPOSE_PROFILES="" + export DB_SYNC_POSTGRES_CONNECTION_STRING="" + echo "📝 Mock mode enabled - midnight-node will use mock Cardano data" +else + # Cardano stack mode: Run all services + export COMPOSE_PROFILES="cardano" + export DB_SYNC_POSTGRES_CONNECTION_STRING="psql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB" fi -export NODE_KEY="$(cat ./midnight-node.privatekey)" # # Partner chains config: diff --git a/.envrc.preview b/.envrc.preview new file mode 100644 index 0000000..357ae15 --- /dev/null +++ b/.envrc.preview @@ -0,0 +1,11 @@ +# overrides for preview +export MIDNIGHT_NODE_IMAGE="ghcr.io/midnight-ntwrk/midnight-node:0.17.0-rc.4" +export INDEXER_IMAGE="ghcr.io/midnight-ntwrk/indexer-standalone:3.0.0-alpha.5" +export INDEXER_NETWORK_ID="preview" + +# Mock mode configuration +export MOCK_REGISTRATIONS_FILE="res/mock-bridge-data/default-registrations.json" + +# Well known addresses of network that allow discovery of all other nodes. +export BOOTNODES="/dns/midnight-node-boot-01/tcp/30333/ws/p2p/12D3KooWK66i7dtGVNSwDh9tTeqov1q6LSdWsRLJvTyzTCaywYgK \ +/dns/midnight-node-boot-02/tcp/30333/ws/p2p/12D3KooWHqFfXFwb7WW4jwR8pr4BEf562v5M6c8K3CXAJq4Wx6ym" \ No newline at end of file diff --git a/.envrc.qanet b/.envrc.qanet index 4e493aa..94d0f81 100644 --- a/.envrc.qanet +++ b/.envrc.qanet @@ -1,5 +1,10 @@ # overrides for qanet export MIDNIGHT_NODE_IMAGE="ghcr.io/midnight-ntwrk/midnight-node:0.12.0-rc.3" +export INDEXER_IMAGE="ghcr.io/midnight-ntwrk/indexer-standalone:2.1.4" +export INDEXER_NETWORK_ID="qanet" + +# Mock mode configuration +export MOCK_REGISTRATIONS_FILE="res/mock-bridge-data/qanet-mock.json" # 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 \ diff --git a/.envrc.testnet-02 b/.envrc.testnet-02 index 2d5e64a..33cfab7 100644 --- a/.envrc.testnet-02 +++ b/.envrc.testnet-02 @@ -1,5 +1,10 @@ # overrides for testnet-02 -export MIDNIGHT_NODE_IMAGE="midnightnetwork/midnight-node:0.12.0" +export MIDNIGHT_NODE_IMAGE="midnightnetwork/midnight-node:0.12.1" +export INDEXER_IMAGE="ghcr.io/midnight-ntwrk/indexer-standalone:2.1.4" +export INDEXER_NETWORK_ID="testnet" + +# Mock mode configuration +export MOCK_REGISTRATIONS_FILE="res/mock-bridge-data/testnet-02-mock.json" # 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 \ diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8eef3db..54f9418 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,9 +27,13 @@ jobs: - name: Check compose files run: | source ./.envrc - docker compose -f compose.yml config -q - docker compose -f compose-partner-chains.yml config -q - docker compose -f proof-server.yml config -q + # Test main compose file + docker compose config -q + # Test profiles + docker compose --profile cardano config -q + docker compose --profile ogmios config -q + docker compose --profile proof-server config -q + docker compose --profile cardano --profile ogmios --profile proof-server config -q - name: Run Super-linter uses: github/super-linter@b807e99ddd37e444d189cfd2c2ca1274d8ae8ef1 #v7 diff --git a/.gitignore b/.gitignore index 2cbdf12..62d7fd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /cardano-data/* /data -*.privatekey -*.password +*.secret ogmios_client.log diff --git a/README.md b/README.md index 2a68a1e..b5165e1 100644 --- a/README.md +++ b/README.md @@ -12,38 +12,50 @@ This allows for easy orchestration of the Midnight Node service. 1. Clone repository -2. In `.envrc` set CFG_PRESET to be the environment you wish to point to (E.g. testnet-02). +2. In `.envrc` set CFG_PRESET to be the environment you wish to point to. Available options: + - `qanet` - QA network + - `testnet-02` - TestNet 02 + - `preview` - Preview network 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`. +The `.envrc` file will automatically create random secrets and save them as `postgres.secret` (database password), `midnight-node.secret` (node private key), and `indexer.secret` (indexer app secret). -Choose which compose files to use: +All services are defined in a single `compose.yml` file. Use Docker Compose profiles to control which services run: -- `compose.yml` for Midnight Node -- `compose-partner-chains.yml` for Cardano + DB Sync -- `proof-server.yml` for Local Proof Server +**Available profiles:** -One can use one or multiple compose files at once. +- (no profile) - Midnight Node only +- `cardano` - Adds Cardano stack (cardano-node, postgres, cardano-db-sync) and Indexer with GraphQL API at `http://localhost:8088` +- `ogmios` - Adds Ogmios service at `http://localhost:1337` +- `proof-server` - Adds local Proof Server at `http://localhost:6300` -For example, to run the Midnight Node, you can do: +**Usage examples:** + +Run Midnight Node only: ```shell docker compose up -d ``` -or to run the Midnight Node and Cardano DB Sync, you can do: +Run Midnight Node + Cardano stack + Indexer: + +```shell +docker compose --profile cardano up -d +``` + +Run with Cardano stack + Ogmios: ```shell -docker compose -f ./compose-partner-chains.yml -f ./compose.yml up -d +docker compose --profile cardano --profile ogmios up -d ``` -or to run the Midnight Node, Cardano DB Sync and a local Proof Server, you can do: +Run everything (Cardano + Ogmios + Proof Server): ```shell -docker compose -f ./compose-partner-chains.yml -f ./compose.yml -f ./proof-server.yml up -d +docker compose --profile cardano --profile ogmios --profile proof-server up -d ``` 🚀 That's it. @@ -60,8 +72,8 @@ If you're using `midnight-node smartcontract` or `midnight-node wizards` that ne To restart from fresh, run: ```sh -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 +docker compose --profile cardano --profile ogmios --profile proof-server down -v +docker compose --profile cardano --profile ogmios --profile proof-server kill rm -R ./cardano-data docker volume rm midnight-node-docker_midnight-data-testnet ``` diff --git a/compose-partner-chains.yml b/compose-partner-chains.yml deleted file mode 100644 index 4b73f4b..0000000 --- a/compose-partner-chains.yml +++ /dev/null @@ -1,92 +0,0 @@ -# This file is part of https://github.com/midnightntwrk/midnight-node-docker -# Copyright (C) 2025 Midnight Foundation -# SPDX-License-Identifier: Apache-2.0 -# Licensed under the Apache License, Version 2.0 (the "License"); -# You may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -volumes: - cardano-ipc: {} - db-sync-data: {} - postgres-data: {} - ogmios-data: {} - -services: - cardano-node: - image: ${CARDANO_IMAGE} - platform: linux/amd64 - restart: unless-stopped - container_name: cardano-node - ports: - - "3001:3001" - environment: - - NETWORK=${CARDANO_NETWORK} - - CARDANO_NODE_SOCKET_PATH=/ipc/node.socket - volumes: - - cardano-ipc:/ipc - - ${CARDANO_DATA_DIR}:/data - - postgres: - image: postgres:15.3 - platform: linux/amd64 - container_name: db-sync-postgres - environment: - - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - - POSTGRES_DB=${POSTGRES_DB} - - POSTGRES_USER=${POSTGRES_USER} - volumes: - - postgres-data:/var/lib/postgresql/data - ports: - - "${POSTGRES_PORT}:${POSTGRES_PORT}" - healthcheck: - test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"] - interval: 5s - timeout: 5s - retries: 5 - - cardano-db-sync: - image: ghcr.io/intersectmbo/cardano-db-sync:13.6.0.4 - platform: linux/amd64 - container_name: cardano-db-sync - restart: unless-stopped - depends_on: - postgres: - condition: service_healthy - environment: - - NETWORK=${CARDANO_NETWORK} - - POSTGRES_HOST=${POSTGRES_HOST} - - POSTGRES_PORT=${POSTGRES_PORT} - - POSTGRES_DB=${POSTGRES_DB} - - POSTGRES_USER=${POSTGRES_USER} - - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - volumes: - - cardano-ipc:/node-ipc - - db-sync-data:/var/lib - - cardano-ogmios: - image: cardanosolutions/ogmios:v6.11.0 - platform: linux/amd64 - container_name: cardano-ogmios - restart: unless-stopped - environment: - - DATA_DIR=/data - ports: - - "1337:1337" - volumes: - - cardano-ipc:/ipc - - ogmios-data:/data - command: - - --node-socket - - /ipc/node.socket - - --node-config - - /config/${CARDANO_NETWORK}/cardano-node/config.json - - --host - - 0.0.0.0 diff --git a/compose.yml b/compose.yml index af88c53..31e019b 100644 --- a/compose.yml +++ b/compose.yml @@ -15,8 +15,75 @@ volumes: midnight-data-testnet: {} + indexer-data: {} + postgres-data: {} + cardano-ipc: {} + db-sync-data: {} + ogmios-data: {} services: + postgres: + profiles: ["cardano"] + image: postgres:15.3 + platform: linux/amd64 + container_name: db-sync-postgres + restart: unless-stopped + environment: + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} + - POSTGRES_USER=${POSTGRES_USER} + volumes: + - postgres-data:/var/lib/postgresql/data + ports: + - "${POSTGRES_PORT}:${POSTGRES_PORT}" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"] + interval: 5s + timeout: 5s + retries: 5 + + cardano-node: + profiles: ["cardano"] + image: ${CARDANO_IMAGE} + platform: linux/amd64 + container_name: cardano-node + restart: unless-stopped + environment: + - NETWORK=${CARDANO_NETWORK} + - CARDANO_NODE_SOCKET_PATH=/ipc/node.socket + volumes: + - cardano-ipc:/ipc + - ${CARDANO_DATA_DIR}:/data + ports: + - "3001:3001" + healthcheck: + test: ["CMD-SHELL", "curl -f 127.0.0.1:12788 || exit 1"] + interval: 60s + timeout: 10s + retries: 5 + + cardano-db-sync: + profiles: ["cardano"] + image: ghcr.io/intersectmbo/cardano-db-sync:13.6.0.4 + platform: linux/amd64 + container_name: cardano-db-sync + restart: unless-stopped + depends_on: + postgres: + condition: service_healthy + cardano-node: + condition: service_healthy + environment: + - NETWORK=${CARDANO_NETWORK} + - POSTGRES_HOST=${POSTGRES_HOST} + - POSTGRES_PORT=${POSTGRES_PORT} + - POSTGRES_DB=${POSTGRES_DB} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + volumes: + - cardano-ipc:/node-ipc + - db-sync-data:/var/lib/cexplorer + midnight-node-testnet: container_name: midnight-node restart: unless-stopped @@ -38,3 +105,57 @@ services: - ./data:/data - ./envs/${CFG_PRESET}/pc-chain-config.json:/pc-chain-config.json - midnight-data-testnet:/node + + indexer-standalone: + profiles: ["cardano"] + container_name: indexer + restart: unless-stopped + image: ${INDEXER_IMAGE} + ports: + - "8088:8088" # GraphQL API + environment: + # v2.1.4 config structure (testnet-02, qanet) + - APP__CHAIN_INDEXER_APPLICATION__NETWORK_ID=${INDEXER_NETWORK_ID} + - APP__WALLET_INDEXER_APPLICATION__NETWORK_ID=${INDEXER_NETWORK_ID} + - APP__INFRA__API__NETWORK_ID=${INDEXER_NETWORK_ID} + # v3.x config structure (preview) + - APP__APPLICATION__NETWORK_ID=${INDEXER_NETWORK_ID} + - APP__INFRA__NODE__URL=ws://midnight-node:9944 + - APP__INFRA__STORAGE__CNN_URL=/data/indexer.sqlite + - APP__INFRA__SECRET=${INDEXER_SECRET} + depends_on: + midnight-node-testnet: + condition: service_healthy + volumes: + - indexer-data:/data + + cardano-ogmios: + profiles: ["ogmios"] + image: cardanosolutions/ogmios:v6.11.0 + platform: linux/amd64 + container_name: cardano-ogmios + restart: unless-stopped + environment: + - DATA_DIR=/data + ports: + - "1337:1337" + volumes: + - cardano-ipc:/ipc + - ogmios-data:/data + command: + - --node-socket + - /ipc/node.socket + - --node-config + - /config/${CARDANO_NETWORK}/cardano-node/config.json + - --host + - 0.0.0.0 + + proof-server: + profiles: ["proof-server"] + image: midnightnetwork/proof-server:4.0.0 + container_name: proof-server + ports: + - "6300:6300" + command: "'midnight-proof-server --network testnet'" + healthcheck: + test: ["CMD", "/bin/bash", "-c", ":> /dev/tcp/127.0.0.1/6300 || exit 1"] diff --git a/proof-server.yml b/proof-server.yml deleted file mode 100644 index 0067a01..0000000 --- a/proof-server.yml +++ /dev/null @@ -1,23 +0,0 @@ -# This file is part of https://github.com/midnightntwrk/midnight-node-docker -# Copyright (C) 2025 Midnight Foundation -# SPDX-License-Identifier: Apache-2.0 -# Licensed under the Apache License, Version 2.0 (the "License"); -# You may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -services: - proof-server: - image: midnightnetwork/proof-server:4.0.0 - ports: - - "6300:6300" - command: "'midnight-proof-server --network testnet'" - healthcheck: - test: ["CMD", "/bin/bash", "-c", ":> /dev/tcp/127.0.0.1/6300 || exit 1"] diff --git a/test.sh b/test.sh index 0d61b34..9f9731a 100755 --- a/test.sh +++ b/test.sh @@ -22,7 +22,7 @@ fi cardano_container=$(docker ps --filter "name=cardano-node") if [[ "$cardano_container" != *"cardano"* ]]; then - echo "cardano container not running, please run docker compose -f ./compose-partner-chains.yml -d" + echo "cardano container not running, please run: docker compose --profile cardano up -d" exit 1 fi @@ -119,7 +119,7 @@ fi # midnight=$(docker ps --filter "name=midnight") if [[ "$midnight" != *"midnight"* ]]; then - echo "❌ midnight container not running, please run docker compose -d" + echo "❌ midnight container not running, please run: docker compose up -d" exit 1 fi