version: '3.8'

services:
  # Validator Nodes (5 nodes)
  besu-validator-1:
    image: hyperledger/besu:23.10.0
    container_name: besu-validator-1
    restart: unless-stopped
    volumes:
      - ./validators/validator-1/data:/data/besu
      - ./validators/validator-1/config:/etc/besu
      - ./validators/validator-1/keys:/keys
      - ./shared/genesis:/genesis
      - ./shared/permissions:/permissions
    ports:
      - "30303:30303"  # P2P
      - "9545:9545"    # Metrics
    command:
      - --config-file=/etc/besu/config-validator.toml
      - --data-path=/data/besu
      - --genesis-file=/genesis/genesis.json
    networks:
      - besu-network
    environment:
      - BESU_OPTS=-Xmx4g -Xms4g
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9545/metrics"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  besu-validator-2:
    image: hyperledger/besu:23.10.0
    container_name: besu-validator-2
    restart: unless-stopped
    volumes:
      - ./validators/validator-2/data:/data/besu
      - ./validators/validator-2/config:/etc/besu
      - ./validators/validator-2/keys:/keys
      - ./shared/genesis:/genesis
      - ./shared/permissions:/permissions
    ports:
      - "30304:30303"  # P2P (different host port)
      - "9546:9545"    # Metrics
    command:
      - --config-file=/etc/besu/config-validator.toml
      - --data-path=/data/besu
      - --genesis-file=/genesis/genesis.json
    networks:
      - besu-network
    environment:
      - BESU_OPTS=-Xmx4g -Xms4g
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9545/metrics"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  besu-validator-3:
    image: hyperledger/besu:23.10.0
    container_name: besu-validator-3
    restart: unless-stopped
    volumes:
      - ./validators/validator-3/data:/data/besu
      - ./validators/validator-3/config:/etc/besu
      - ./validators/validator-3/keys:/keys
      - ./shared/genesis:/genesis
      - ./shared/permissions:/permissions
    ports:
      - "30305:30303"
      - "9547:9545"
    command:
      - --config-file=/etc/besu/config-validator.toml
      - --data-path=/data/besu
      - --genesis-file=/genesis/genesis.json
    networks:
      - besu-network
    environment:
      - BESU_OPTS=-Xmx4g -Xms4g
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9545/metrics"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  besu-validator-4:
    image: hyperledger/besu:23.10.0
    container_name: besu-validator-4
    restart: unless-stopped
    volumes:
      - ./validators/validator-4/data:/data/besu
      - ./validators/validator-4/config:/etc/besu
      - ./validators/validator-4/keys:/keys
      - ./shared/genesis:/genesis
      - ./shared/permissions:/permissions
    ports:
      - "30306:30303"
      - "9548:9545"
    command:
      - --config-file=/etc/besu/config-validator.toml
      - --data-path=/data/besu
      - --genesis-file=/genesis/genesis.json
    networks:
      - besu-network
    environment:
      - BESU_OPTS=-Xmx4g -Xms4g
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9545/metrics"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  besu-validator-5:
    image: hyperledger/besu:23.10.0
    container_name: besu-validator-5
    restart: unless-stopped
    volumes:
      - ./validators/validator-5/data:/data/besu
      - ./validators/validator-5/config:/etc/besu
      - ./validators/validator-5/keys:/keys
      - ./shared/genesis:/genesis
      - ./shared/permissions:/permissions
    ports:
      - "30307:30303"
      - "9549:9545"
    command:
      - --config-file=/etc/besu/config-validator.toml
      - --data-path=/data/besu
      - --genesis-file=/genesis/genesis.json
    networks:
      - besu-network
    environment:
      - BESU_OPTS=-Xmx4g -Xms4g
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9545/metrics"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  # Sentry Nodes (4 nodes)
  besu-sentry-1:
    image: hyperledger/besu:23.10.0
    container_name: besu-sentry-1
    restart: unless-stopped
    volumes:
      - ./sentries/sentry-1/data:/data/besu
      - ./sentries/sentry-1/config:/etc/besu
      - ./sentries/sentry-1/keys:/keys
      - ./shared/genesis:/genesis
      - ./shared/permissions:/permissions
    ports:
      - "30308:30303"
      - "9550:9545"
    command:
      - --config-file=/etc/besu/config-sentry.toml
      - --data-path=/data/besu
      - --genesis-file=/genesis/genesis.json
    networks:
      - besu-network
    environment:
      - BESU_OPTS=-Xmx2g -Xms2g
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9545/metrics"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  besu-sentry-2:
    image: hyperledger/besu:23.10.0
    container_name: besu-sentry-2
    restart: unless-stopped
    volumes:
      - ./sentries/sentry-2/data:/data/besu
      - ./sentries/sentry-2/config:/etc/besu
      - ./sentries/sentry-2/keys:/keys
      - ./shared/genesis:/genesis
      - ./shared/permissions:/permissions
    ports:
      - "30309:30303"
      - "9551:9545"
    command:
      - --config-file=/etc/besu/config-sentry.toml
      - --data-path=/data/besu
      - --genesis-file=/genesis/genesis.json
    networks:
      - besu-network
    environment:
      - BESU_OPTS=-Xmx2g -Xms2g
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9545/metrics"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  besu-sentry-3:
    image: hyperledger/besu:23.10.0
    container_name: besu-sentry-3
    restart: unless-stopped
    volumes:
      - ./sentries/sentry-3/data:/data/besu
      - ./sentries/sentry-3/config:/etc/besu
      - ./sentries/sentry-3/keys:/keys
      - ./shared/genesis:/genesis
      - ./shared/permissions:/permissions
    ports:
      - "30310:30303"
      - "9552:9545"
    command:
      - --config-file=/etc/besu/config-sentry.toml
      - --data-path=/data/besu
      - --genesis-file=/genesis/genesis.json
    networks:
      - besu-network
    environment:
      - BESU_OPTS=-Xmx2g -Xms2g
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9545/metrics"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  besu-sentry-4:
    image: hyperledger/besu:23.10.0
    container_name: besu-sentry-4
    restart: unless-stopped
    volumes:
      - ./sentries/sentry-4/data:/data/besu
      - ./sentries/sentry-4/config:/etc/besu
      - ./sentries/sentry-4/keys:/keys
      - ./shared/genesis:/genesis
      - ./shared/permissions:/permissions
    ports:
      - "30311:30303"
      - "9553:9545"
    command:
      - --config-file=/etc/besu/config-sentry.toml
      - --data-path=/data/besu
      - --genesis-file=/genesis/genesis.json
    networks:
      - besu-network
    environment:
      - BESU_OPTS=-Xmx2g -Xms2g
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9545/metrics"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  # RPC Nodes (3 nodes)
  besu-rpc-1:
    image: hyperledger/besu:23.10.0
    container_name: besu-rpc-1
    restart: unless-stopped
    volumes:
      - ./rpc/rpc-1/data:/data/besu
      - ./rpc/rpc-1/config:/etc/besu
      - ./rpc/rpc-1/keys:/keys
      - ./shared/genesis:/genesis
      - ./shared/permissions:/permissions
    ports:
      - "8545:8545"    # HTTP RPC
      - "8546:8546"    # WS RPC
      - "30312:30303"  # P2P
      - "9554:9545"    # Metrics
    command:
      - --config-file=/etc/besu/config-rpc.toml
      - --data-path=/data/besu
      - --genesis-file=/genesis/genesis.json
    networks:
      - besu-network
    environment:
      - BESU_OPTS=-Xmx8g -Xms8g
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8545"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 120s

  besu-rpc-2:
    image: hyperledger/besu:23.10.0
    container_name: besu-rpc-2
    restart: unless-stopped
    volumes:
      - ./rpc/rpc-2/data:/data/besu
      - ./rpc/rpc-2/config:/etc/besu
      - ./rpc/rpc-2/keys:/keys
      - ./shared/genesis:/genesis
      - ./shared/permissions:/permissions
    ports:
      - "8547:8545"    # HTTP RPC
      - "8548:8546"    # WS RPC
      - "30313:30303"  # P2P
      - "9555:9545"    # Metrics
    command:
      - --config-file=/etc/besu/config-rpc.toml
      - --data-path=/data/besu
      - --genesis-file=/genesis/genesis.json
    networks:
      - besu-network
    environment:
      - BESU_OPTS=-Xmx8g -Xms8g
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8545"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 120s

  besu-rpc-3:
    image: hyperledger/besu:23.10.0
    container_name: besu-rpc-3
    restart: unless-stopped
    volumes:
      - ./rpc/rpc-3/data:/data/besu
      - ./rpc/rpc-3/config:/etc/besu
      - ./rpc/rpc-3/keys:/keys
      - ./shared/genesis:/genesis
      - ./shared/permissions:/permissions
    ports:
      - "8549:8545"    # HTTP RPC
      - "8550:8546"    # WS RPC
      - "30314:30303"  # P2P
      - "9556:9545"    # Metrics
    command:
      - --config-file=/etc/besu/config-rpc.toml
      - --data-path=/data/besu
      - --genesis-file=/genesis/genesis.json
    networks:
      - besu-network
    environment:
      - BESU_OPTS=-Xmx8g -Xms8g
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8545"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 120s

networks:
  besu-network:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.0.0/16

