---
x-logging-defaults: &logging-defaults
  driver: json-file
  options:
    max-size: "10m"
    max-file: "3"
# statesync is great. if you are too far behind after a restart then you can just delete the volume and start again.
# statesync will need a few hours to complete tho.
# if you want to test the current lag you could try it under the RPC endpoint, for example XXXX:26657/lag_status

# 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:sei/sei/sei-testnet-sei-pruned.yml
#
# docker compose up -d
#
# curl -X POST https://${IP}.traefik.me/sei-testnet-sei-pruned \
#   -H "Content-Type: application/json" \
#   --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

services:
  sei-testnet-sei-pruned:
    build:
      context: ./sei
      dockerfile: sei.Dockerfile
      args:
        SEI_VERSION: ${SEI_TESTNET_SEI_VERSION:-v6.2.5}
        SEI_IMAGE: ${SEI_TESTNET_SEI_IMAGE:-ghcr.io/sei-protocol/sei}
    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:
      - 10889:10889
      - 10889:10889/udp
    expose:
      - 8545
      - 8546
    env_file:
      - ./sei/testnet.env
    environment:
      - IP=${IP}
      - MONIKER=d${DOMAIN:-local}
      - P2P_PORT=10889
      - PEERS=${SEI_TESTNET_SEI_PEERS:-b2664ccaa84a04b67683093fefb802b172ead6d1@sei-a2-rpc.p2p.brocha.in:30612,babc3f3f7804933265ec9c40ad94f4da8e9e0017@testnet-seed.rhinostake.com:11956}
    restart: unless-stopped
    stop_grace_period: 5m
    networks:
      - chains
    volumes:
      - ${SEI_TESTNET_SEI_PRUNED_DATA:-sei-testnet-sei-pruned}:/root/.sei
      - /slowdisk:/slowdisk
    logging: *logging-defaults
    labels:
      - prometheus-scrape.enabled=false
      - traefik.enable=true
      - traefik.http.middlewares.sei-testnet-sei-pruned-stripprefix.stripprefix.prefixes=/sei-testnet-sei-pruned
      - traefik.http.services.sei-testnet-sei-pruned.loadbalancer.server.port=8545
      - ${NO_SSL:-traefik.http.routers.sei-testnet-sei-pruned.entrypoints=websecure}
      - ${NO_SSL:-traefik.http.routers.sei-testnet-sei-pruned.tls.certresolver=myresolver}
      - ${NO_SSL:-traefik.http.routers.sei-testnet-sei-pruned.rule=Host(`$DOMAIN`) && (Path(`/sei-testnet-sei-pruned`) || Path(`/sei-testnet-sei-pruned/`))}
      - ${NO_SSL:+traefik.http.routers.sei-testnet-sei-pruned.rule=Path(`/sei-testnet-sei-pruned`) || Path(`/sei-testnet-sei-pruned/`)}
      - traefik.http.routers.sei-testnet-sei-pruned.middlewares=sei-testnet-sei-pruned-stripprefix, ipallowlist
      - traefik.http.routers.sei-testnet-sei-pruned.priority=50   # gets any request that is not GET with UPGRADE header
      - traefik.http.routers.sei-testnet-sei-pruned-ws.priority=100   # answers GET requests first
      - traefik.http.services.sei-testnet-sei-pruned-ws.loadbalancer.server.port=8546
      - traefik.http.routers.sei-testnet-sei-pruned-ws.service=sei-testnet-sei-pruned-ws
      - traefik.http.routers.sei-testnet-sei-pruned.service=sei-testnet-sei-pruned
      - ${NO_SSL:-traefik.http.routers.sei-testnet-sei-pruned-ws.entrypoints=websecure}
      - ${NO_SSL:-traefik.http.routers.sei-testnet-sei-pruned-ws.tls.certresolver=myresolver}
      - ${NO_SSL:-traefik.http.routers.sei-testnet-sei-pruned-ws.rule=Host(`$DOMAIN`) && (Path(`/sei-testnet-sei-pruned`) || Path(`/sei-testnet-sei-pruned/`)) && Headers(`Upgrade`, `websocket`)}
      - ${NO_SSL:+traefik.http.routers.sei-testnet-sei-pruned-ws.rule=(Path(`/sei-testnet-sei-pruned`) || Path(`/sei-testnet-sei-pruned/`)) && Headers(`Upgrade`, `websocket`)}
      - traefik.http.routers.sei-testnet-sei-pruned-ws.middlewares=sei-testnet-sei-pruned-stripprefix, ipallowlist

volumes:
  sei-testnet-sei-pruned:

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