---
x-logging-defaults: &logging-defaults
  driver: json-file
  options:
    max-size: "10m"
    max-file: "3"

# Usage:
#
# mkdir rpc && cd rpc
#
# git init
# git remote add origin https://github.com/StakeSquid/ethereum-rpc-docker.git
# git fetch origin vibe
# git checkout origin/vibe
#
# docker run --rm alpine sh -c "printf '0x'; head -c32 /dev/urandom | xxd -p -c 64" > .jwtsecret
#
# env
# ...
# IP=$(curl ipinfo.io/ip)
# DOMAIN=${IP}.traefik.me
# COMPOSE_FILE=base.yml:rpc.yml:viction/node/viction-testnet-node-archive-leveldb-hash.yml
#
# docker compose up -d
#
# curl -X POST https://${IP}.traefik.me/viction-testnet-node-archive \
#   -H "Content-Type: application/json" \
#   --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

services:
  viction-testnet-node-archive:
    image: ${VICTION_NODE_IMAGE:-buildonviction/node}:${VICTION_TESTNET_NODE_VERSION:-v2.5.1}
    sysctls:
      # TCP Performance
      net.ipv4.tcp_slow_start_after_idle: 0       # Disable slow start after idle
      net.ipv4.tcp_no_metrics_save: 1             # Disable metrics cache
      net.ipv4.tcp_rmem: 4096 87380 16777216      # Increase TCP read buffers
      net.ipv4.tcp_wmem: 4096 87380 16777216      # Increase TCP write buffers
      net.core.somaxconn: 32768                   # Higher connection queue
      # Memory/Connection Management
      # net.core.netdev_max_backlog: 50000          # Increase network buffer
      net.ipv4.tcp_max_syn_backlog: 30000         # More SYN requests
      net.ipv4.tcp_max_tw_buckets: 2000000        # Allow more TIME_WAIT sockets
    ulimits:
      nofile: 1048576    # Max open files (for RPC/WS connections)
    user: root
    ports:
      - 11689:11689
      - 11689:11689/udp
    expose:
      - 8545
      - 8546
    environment:
      BOOTNODES: enode://77c303c0d7cd03cb0fcfee0b7fc1b162d2fcaf667dc23b416e631196c8d7bed9b937944372b4673bc3d8dcede4b37bf8e7e8855bbda76c96bba3fb573a10f1ad@162.19.43.250:30304,enode://b9b5f61ab47f3681e75240d8b86d05ab451cd47f206d1d3cb69a87c71491236cec10b8a7740ec88616199d6a76d309f41a647e2802a63a8e449773ee3a920ba4@15.235.228.11:30304,enode://0f41c53da72e07e3514efd7ce9e3f758acc2066d8ae66955e540620f7108fff91f8ebdc734b89dca14db2a70cdaf8c957579ec94e3dfdfe91b2923272f1cc099@13.214.64.64:30601
      EXTIP: ${IP}
      NETWORK_ID: 89
      P2P_PORT: 11689
    command: --tomox --tomox.datadir /tomochain/data/tomox --gcmode archive --rpcapi eth,debug,net,db,admin,web3
    restart: unless-stopped
    stop_grace_period: 5m
    networks:
      - chains
    volumes:
      - ${VICTION_TESTNET_NODE_ARCHIVE_LEVELDB_HASH_DATA:-viction-testnet-node-archive-leveldb-hash}:/tomochain/data
      - /slowdisk:/slowdisk
    logging: *logging-defaults
    labels:
      - prometheus-scrape.enabled=false
      - traefik.enable=true
      - traefik.http.middlewares.viction-testnet-node-archive-leveldb-hash-stripprefix.stripprefix.prefixes=/viction-testnet-node-archive
      - traefik.http.services.viction-testnet-node-archive-leveldb-hash.loadbalancer.server.port=8545
      - ${NO_SSL:-traefik.http.routers.viction-testnet-node-archive-leveldb-hash.entrypoints=websecure}
      - ${NO_SSL:-traefik.http.routers.viction-testnet-node-archive-leveldb-hash.tls.certresolver=myresolver}
      - ${NO_SSL:-traefik.http.routers.viction-testnet-node-archive-leveldb-hash.rule=Host(`$DOMAIN`) && (Path(`/viction-testnet-node-archive`) || Path(`/viction-testnet-node-archive/`))}
      - ${NO_SSL:+traefik.http.routers.viction-testnet-node-archive-leveldb-hash.rule=Path(`/viction-testnet-node-archive`) || Path(`/viction-testnet-node-archive/`)}
      - traefik.http.routers.viction-testnet-node-archive-leveldb-hash.middlewares=viction-testnet-node-archive-leveldb-hash-stripprefix, ipallowlist
      - traefik.http.routers.viction-testnet-node-archive-leveldb-hash.priority=50   # gets any request that is not GET with UPGRADE header
      - traefik.http.routers.viction-testnet-node-archive-leveldb-hash-ws.priority=100   # answers GET requests first
      - traefik.http.services.viction-testnet-node-archive-leveldb-hash-ws.loadbalancer.server.port=8546
      - traefik.http.routers.viction-testnet-node-archive-leveldb-hash-ws.service=viction-testnet-node-archive-leveldb-hash-ws
      - traefik.http.routers.viction-testnet-node-archive-leveldb-hash.service=viction-testnet-node-archive-leveldb-hash
      - ${NO_SSL:-traefik.http.routers.viction-testnet-node-archive-leveldb-hash-ws.entrypoints=websecure}
      - ${NO_SSL:-traefik.http.routers.viction-testnet-node-archive-leveldb-hash-ws.tls.certresolver=myresolver}
      - ${NO_SSL:-traefik.http.routers.viction-testnet-node-archive-leveldb-hash-ws.rule=Host(`$DOMAIN`) && (Path(`/viction-testnet-node-archive`) || Path(`/viction-testnet-node-archive/`)) && Headers(`Upgrade`, `websocket`)}
      - ${NO_SSL:+traefik.http.routers.viction-testnet-node-archive-leveldb-hash-ws.rule=(Path(`/viction-testnet-node-archive`) || Path(`/viction-testnet-node-archive/`)) && Headers(`Upgrade`, `websocket`)}
      - traefik.http.routers.viction-testnet-node-archive-leveldb-hash-ws.middlewares=viction-testnet-node-archive-leveldb-hash-stripprefix, ipallowlist

volumes:
  viction-testnet-node-archive-leveldb-hash:

x-upstreams:
  - id: $${ID}
    labels:
      provider: $${PROVIDER}
    connection:
      generic:
        rpc:
          url: $${RPC_URL}
        ws:
          frameSize: 20Mb
          msgSize: 50Mb
          url: $${WS_URL}
    chain: viction-testnet
    method-groups:
      enabled:
        - debug
        - filter
    methods:
      disabled:
      enabled:
        - name: txpool_content # TODO: should be disabled for rollup nodes
...