#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    log                 stdout format raw local0
    maxconn             20000
    user                haproxy
    group               haproxy
    ssl-default-server-options force-tlsv12
    ssl-default-bind-options force-tlsv12
    ca-base             /etc/ssl/certs
    external-check
    insecure-fork-wanted

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                 tcp
    option               tcplog
    log                  global
    option               dontlognull
    timeout client       5m

#---------------------------------------------------------------------
# dedicated stats page
#---------------------------------------------------------------------
listen stats
    mode http
    bind :22222
    stats enable
    stats uri            /haproxy?stats
    stats realm          Haproxy\ Statistics
    stats auth           admin:YOURPW
    stats refresh        30s

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main_https_listen
    bind                *:443
    tcp-request inspect-delay 5s
    tcp-request content accept if { req_ssl_hello_type 1 }

#---------------------------------------------------------------------
# Common HAProxy nodes configuration
#---------------------------------------------------------------------

# -------------------------------
# ACLs
# -------------------------------

acl acl_ec           req.ssl_sni -i optimism-lb.example.com
acl acl_ecws         req.ssl_sni -i optimismws-lb.example.com

# -------------------------------
# Conditions
# -------------------------------

use_backend backend_ec if acl_ec
use_backend backend_ecws if acl_ecws

#---------------------------------------------------------------------
# Backends
#---------------------------------------------------------------------

# RPC execution client
backend backend_ec
    description Optimism L2Geth
    default-server init-addr libc no-tls-tickets check inter 10000 on-marked-down shutdown-sessions
    timeout connect 5s
    timeout server 30s
    retries      2
    balance first
    option external-check
    external-check path "/usr/bin:/bin"
    external-check command /var/lib/haproxy/check-ecsync.sh
    server optimism-a.example.com optimism-a.example.com:443
    server optimism-b.example.com optimism-b.example.com:443 backup

# WebSockets execution client
backend backend_ecws
    description Optimism L2Geth WebSockets
    default-server init-addr libc no-tls-tickets check inter 10000 on-marked-down shutdown-sessions
    timeout connect 5s
    timeout server 30s
    timeout tunnel 3600s
    retries      2
    balance first
    option external-check
    external-check path "/usr/bin:/bin"
    external-check command /var/lib/haproxy/check-ecsync.sh
    server optimism-a.example.com optimismws-a.example.com:443
    server optimism-b.example.com optimismws-b.example.com:443 backup

