# Synor ZK-Rollup Layer - Docker Compose
# Zero-knowledge rollup components for L2 scaling

version: '3.9'

services:
  # ZK Sequencer - collects transactions and builds batches
  zk-sequencer:
    build:
      context: .
      dockerfile: docker/zk-rollup/Dockerfile
    container_name: synor-zk-sequencer
    hostname: zk-sequencer
    restart: unless-stopped
    environment:
      - RUST_LOG=info
      - NODE_ID=zk-sequencer-1
      - L1_RPC=http://synor-node-1:8545
      - PROOF_BACKEND=groth16
      - MAX_BATCH_SIZE=1000
    volumes:
      - zk-sequencer-data:/data/zk
      - zk-proofs:/proofs
      - ./docker/zk-rollup/config.toml:/config/config.toml:ro
    ports:
      - "3001:3001"   # Sequencer API
      - "3002:3002"   # Prover RPC
      - "9001:9001"   # Metrics
    networks:
      - synor-zk-net
      - synor-testnet
    # depends_on synor-node-1 when integrating with testnet
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3001/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

  # ZK Prover Pool - dedicated proof generation
  zk-prover-1:
    build:
      context: .
      dockerfile: docker/zk-rollup/Dockerfile
    container_name: synor-zk-prover-1
    hostname: zk-prover-1
    restart: unless-stopped
    environment:
      - RUST_LOG=info
      - NODE_ID=zk-prover-1
      - PROVER_MODE=true
      - SEQUENCER_RPC=http://zk-sequencer:3002
      - PROVER_THREADS=4
    volumes:
      - zk-prover-1-data:/data/zk
      - zk-proofs:/proofs
    networks:
      - synor-zk-net
    depends_on:
      - zk-sequencer
    deploy:
      resources:
        limits:
          cpus: '4'
          memory: 8G
        reservations:
          cpus: '2'
          memory: 4G

  zk-prover-2:
    build:
      context: .
      dockerfile: docker/zk-rollup/Dockerfile
    container_name: synor-zk-prover-2
    hostname: zk-prover-2
    restart: unless-stopped
    environment:
      - RUST_LOG=info
      - NODE_ID=zk-prover-2
      - PROVER_MODE=true
      - SEQUENCER_RPC=http://zk-sequencer:3002
      - PROVER_THREADS=4
    volumes:
      - zk-prover-2-data:/data/zk
      - zk-proofs:/proofs
    networks:
      - synor-zk-net
    depends_on:
      - zk-sequencer
    deploy:
      resources:
        limits:
          cpus: '4'
          memory: 8G
        reservations:
          cpus: '2'
          memory: 4G

  # ZK API Gateway - public interface
  zk-gateway:
    image: nginx:alpine
    container_name: synor-zk-gateway
    hostname: zk-gateway
    restart: unless-stopped
    volumes:
      - ./docker/zk-rollup/nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - "3080:80"     # Public API
      - "3443:443"    # HTTPS
    networks:
      - synor-zk-net
    depends_on:
      - zk-sequencer
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost/health"]
      interval: 15s
      timeout: 5s
      retries: 3

  # Prometheus for ZK metrics
  zk-prometheus:
    image: prom/prometheus:latest
    container_name: synor-zk-prometheus
    hostname: zk-prometheus
    restart: unless-stopped
    volumes:
      - ./docker/zk-rollup/prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - zk-prometheus-data:/prometheus
    ports:
      - "9090:9090"
    networks:
      - synor-zk-net
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'

volumes:
  zk-sequencer-data:
    driver: local
  zk-prover-1-data:
    driver: local
  zk-prover-2-data:
    driver: local
  zk-proofs:
    driver: local
  zk-prometheus-data:
    driver: local

networks:
  synor-zk-net:
    driver: bridge
    ipam:
      config:
        - subnet: 172.24.0.0/16
  synor-testnet:
    name: blockchaincc_synor-testnet
    external: true
