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

services:
  fantom-testnet-opera-pruned:
    build:
      context: ./fantom
      dockerfile: opera.Dockerfile
      args:
        VERSION: v1.1.3-rc.5
        REPO: https://github.com/Fantom-foundation/go-opera.git
    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:
      - 10846:10846
      - 10846:10846/udp
    expose:
      - 8545
      - 6060
    environment:
      - FANTOM_HOME=/datadir
      - GENESIS=https://download.fantom.network/opera/testnet/testnet-6226-no-history.g
    command:
      - --bootnodes=enode://2411cdad2780bf969c0bd6f19b53ac6683710d50f19a7604248d8a6a810d3d6369dffb08535530095c151ecad143393e4fbca2d11f62377fe15b3df4d9883053@34.172.30.235:5050,enode://6f434dc43f826f7c3c817ba7fbe7842aa47c50d1e77a6b57ec51313fd88c7f006240baa105b795712922a05e1b548d413ea6d32d8c1c8feb9ffc206a6c9e37ce@34.55.131.153:5050,enode://64e69ec1f30be48aa8d5f3e6cadf15d06d846d40918f3906e6efbc4a3421f0cc04e3e4f88569b5c90306bbc16ca15df6898ad71b8a73aa36284f1c3076f2956e@35.195.64.211:5050,enode://a76d94105f12d3fb5c31df5a59448d95b723d94543620a02f72ee990e048c43df940f4969ab06d436ef8976c49ec9c2a671c2f5af8d93af911cef63de329a8b8@35.239.100.93:5050,enode://baea3b72d091cb361283af4933da32406d707d3bb077a42c77a58cf98e27b546da837e6e9524d8588f414e1886a3b17e036b86fd2d723170db93831a22324252@35.241.219.197:5050,enode://544f06ceaddcf508a13326d95518a524e14f4980723c9dc5cb8560635a7faa7f8f91483faed19dacd7d251abf72b4a1b0bcacaced1255deb93414d097221a9bc@35.224.88.189:5050,enode://baea3b72d091cb361283af4933da32406d707d3bb077a42c77a58cf98e27b546da837e6e9524d8588f414e1886a3b17e036b86fd2d723170db93831a22324252@35.241.219.197:5050,enode://2cd3fcfe9671d81c0e8bb76bc81a430882ce5d99199c20a004da97bec48e9b03c02c3b6d95edb77498ce2dd8e090c4ce76349e775af7540b04a6e9303e5b69cd@104.155.31.23:5050
      - --cache=${FANTOM_TESTNET_OPERA_PRUNED_CACHE_MB:-16000}
      - --db.migration.mode=reformat
      - --db.preset=pbl-1
      - --http
      - --http.addr=0.0.0.0
      - --http.api=admin,debug,web3,eth,dag,txpool,personal,abft,net,trace,ftm
      - --http.port=8545
      - --http.vhosts=*
      - --maxpeers=50
      - --metrics
      - --metrics.addr=0.0.0.0
      - --metrics.port=6060
      - --nat=extip:${IP}
      - --port=10846
      - --rpc.gascap=600000000
      - --rpc.txfeecap=0
      - --syncmode=snap
      - --ws
      - --ws.addr=0.0.0.0
      - --ws.api=admin,debug,web3,eth,dag,txpool,personal,abft,net,trace,ftm
      - --ws.origins=*
      - --ws.port=8545
    restart: unless-stopped
    stop_grace_period: 5m
    networks:
      - chains
    volumes:
      - ${FANTOM_TESTNET_OPERA_PRUNED_DATA:-fantom-testnet-opera-pruned}:/datadir
      - /slowdisk:/slowdisk
    logging: *logging-defaults
    labels:
      - prometheus-scrape.enabled=true
      - prometheus-scrape.port=6060
      - prometheus-scrape.path=/debug/metrics/prometheus
      - traefik.enable=true
      - traefik.http.middlewares.fantom-testnet-opera-pruned-stripprefix.stripprefix.prefixes=/fantom-testnet-opera-pruned
      - traefik.http.services.fantom-testnet-opera-pruned.loadbalancer.server.port=8545
      - ${NO_SSL:-traefik.http.routers.fantom-testnet-opera-pruned.entrypoints=websecure}
      - ${NO_SSL:-traefik.http.routers.fantom-testnet-opera-pruned.tls.certresolver=myresolver}
      - ${NO_SSL:-traefik.http.routers.fantom-testnet-opera-pruned.rule=Host(`$DOMAIN`) && (Path(`/fantom-testnet-opera-pruned`) || Path(`/fantom-testnet-opera-pruned/`))}
      - ${NO_SSL:+traefik.http.routers.fantom-testnet-opera-pruned.rule=Path(`/fantom-testnet-opera-pruned`) || Path(`/fantom-testnet-opera-pruned/`)}
      - traefik.http.routers.fantom-testnet-opera-pruned.middlewares=fantom-testnet-opera-pruned-stripprefix, ipallowlist

volumes:
  fantom-testnet-opera-pruned:

x-upstreams:
  - id: $${ID}
    labels:
      provider: $${PROVIDER}
    connection:
      generic:
        rpc:
          url: $${RPC_URL}
        ws:
          frameSize: 20Mb
          msgSize: 50Mb
          url: $${WS_URL}
    chain: fantom-testnet
    method-groups:
      enabled:
        - debug
        - filter
    methods:
      disabled:
      enabled:
        - name: txpool_content # TODO: should be disabled for rollup nodes
        # standard geth only
        - name: debug_getRawBlock
        - name: debug_getRawTransaction
        - name: debug_getRawReceipts
        - name: debug_getRawHeader
        - name: debug_getBadBlocks
        # non standard geth only slightly dangerous
        - name: debug_intermediateRoots
        - name: debug_dumpBlock
        # standard geth and erigon
        - name: debug_accountRange
        - name: debug_getModifiedAccountsByNumber
        - name: debug_getModifiedAccountsByHash
        # non standard geth and erigon
        - name: eth_getRawTransactionByHash
        - name: eth_getRawTransactionByBlockHashAndIndex
...