# Docker compose file to simulate a sentry node setup.
#
#
# Setup:
#
# Validator A is not supposed to be connected to the public internet. Instead it
# connects to a sentry node (sentry-a) which connects to the public internet.
#
#
# Usage:
#
# 1. Build `target/release/substrate` binary: `cargo build --release`
#
# 2. Start networks and containers: `sudo docker-compose -f scripts/sentry-node/docker-compose.yml up`
#
# 3. Reach:
#   - validator-a: localhost:9944
#   - sentry-a: localhost:9946

version: "3.7"
services:
  validator:
    ports:
      - "9944:9944"
#    volumes:
#      - ../../target/release/substrate:/usr/local/bin/substrate
    image: parity/polkadot
    networks:
      - network-a
    environment:
        - VALIDATOR_NODE_KEY
        - VALIDATOR_BASE_PATH
        - VALIDATOR_CHAIN
        - VALIDATOR_PORT
        - VALIDATOR_NAME
        - VALIDATOR_RESERVED_NODES
    command:
      # Local node id: QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR
      - "--node-key"
      - "${VALIDATOR_NODE_KEY:-0000000000000000000000000000000000000000000000000000000000000001}"
      - "--base-path"
      - "${VALIDATOR_BASE_PATH:-/tmp/alice}"
      - "--chain=${VALIDATOR_CHAIN:-local}"
      - "--port"
      - "${VALIDATOR_PORT:-30333}"
      - "--validator"
      - "--name"
      - "${VALIDATOR_NANE:-AlicesNode}"
      - "--reserved-nodes"
      - "${VALIDATOR_RESERVED_NODES:-/dns4/sentry/tcp/30333/p2p/QmV7EhW6J6KgmNdr558RH1mPx2xGGznW7At4BhXzntRFsi}"
      # Not only bind to localhost.
      - "--ws-external"
      - "--rpc-external"
      # - "--log"
      # - "sub-libp2p=trace"
      # - "--log"
      # - "afg=trace"
      - "--no-telemetry"
      - "--rpc-cors"
      - "all"

  sentry:
    image: parity/polkadot
    ports:
      - "9946:9944"
#    volumes:
#      - ../../target/release/substrate:/usr/local/bin/substrate
    networks:
      - network-a
      - internet
    environment:
        - SENTRY_NODE_KEY
        - SENTRY_BASE_PATH
        - SENTRY_CHAIN
        - SENTRY_PORT
        - SENTRY_NAME
        - SENTRY_BOOTNODES
    command:
      # Local node id: QmV7EhW6J6KgmNdr558RH1mPx2xGGznW7At4BhXzntRFsi
      - "--node-key"
      - "${SENTRY_NODE_KEY:-0000000000000000000000000000000000000000000000000000000000000003}"
      - "--base-path"
      - "${SENTRY_BASE_PATH:-/tmp/charlies}"
      - "--chain=${SENTRY_CHAIN:-local}"
      # Don't configure a key, as sentry is not a validator.
      - "--port"
      - "${SENTRY_PORT:-30333}"
      # sentry-a is not a validator.
      # - "--validator"
      - "--name"
      - "${SENTRY_NAME:-CharliesNode}"
      - "--bootnodes"
      - "${SENTRY_BOOTNODES:-/dns4/validator-a/tcp/30333/p2p/QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR}"
      - "--no-telemetry"
      - "--rpc-cors"
      - "all"
      # Not only bind to localhost.
      - "--ws-external"
      - "--rpc-external"

networks:
  network-a:
  internet:
