---
x-logging-defaults: &logging-defaults
  driver: json-file
  options:
    max-size: "10m"
    max-file: "3"
# you should backup the peers of your beacond node frequently.
# docker exec -it rpc-berachain-bartio-reth-node-1 curl http://localhost:26657/net_info | jq -r '
#  .result.peers[]
#  | "\(.node_info.id)@\(.remote_ip):\(.node_info.listen_addr | split(":") | last)"
#' | paste -sd,
# and then set the PERSISTENT_PEERS environment variable for the beacon node which will be inserted into the config toml by the init script...
# SEEDS are published in the official repository https://github.com/berachain/beacon-kit/tree/main/testing/networks/80084/cl-seeds.txt
# if that file is found then the init script will merge them into any configured seeds from the environment variable.
# If the environment variable is empty and the file is found then the init script will use the seeds from the config.toml file that was
# downloaded in initialization from the repo above.
#
# something wild that appeared to me was that I had to delete /var/lib/docker/volumes/rpc_berachain-bepolia-reth-archive-trace_config/_data/genesis.json
# after a fork of the chain to trigger a redownload of the genesis.json file and init of the node datadir.
#
# also it may be necessary to update the static peers and bootnodes from the repository to get it going again.
#
# frequently reth complains about never seeing a beacon client pushing for new blocks to sync to while the beacon client
# complains about reth being synching and it can't push new block hashes. force-recreate helps.
#
# this is honestly the most flaky constructs of all of the chains in this repository. they expect you to run their refrence setup
# and git pull to update and if something doesn't work to get a new chaindata snapshot.
#
# sometimes the genesis has to be updated and is a parameter to the reth node
# force-recreate on chain fork would do the trick I guess...
#
# don't forget to docker compose build from time to time...
#
# ETH_GENESIS_URL="https://raw.githubusercontent.com/berachain/beacon-kit/main/testing/networks/$CHAINID/eth-genesis.json"
# curl -sL "$ETH_GENESIS_URL" -o "$CONFIG_DIR/eth-genesis.json"
#
# something like this needs to be done sometimes when there is a fork of the chain somehow. may or may not be automated.

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

services:
  berachain-bartio-reth:
    image: ${BERACHAIN_RETH_IMAGE:-ghcr.io/berachain/bera-reth}:${BERACHAIN_BARTIO_RETH_VERSION:-v1.3.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)
      memlock: -1        # Disable memory locking limits (for in-memory DBs like MDBX)
    user: root
    ports:
      - 10527:10527
      - 10527:10527/udp
    expose:
      - 8545
      - 9001
      - 8551
    environment:
      - BOOTNODES=enode://0401e494dbd0c84c5c0f72adac5985d2f2525e08b68d448958aae218f5ac8198a80d1498e0ebec2ce38b1b18d6750f6e61a56b4614c5a6c6cf0981c39aed47dc@34.159.32.127:30303,enode://9b6c1eb143c9e3af0c7283262a9a38fe8bf844114b1f304673c2ac1c23e6bccfdaa8f4e9cb8c460bded495933fd92eeff30e6ab2e0538b56e249beea2c512906@35.234.88.149:30303,enode://e9675164b5e17b9d9edf0cc2bd79e6b6f487200c74d1331c220abb5b8ee80c2eefbf18213989585e9d0960683e819542e11d4eefb5f2b4019e1e49f9fd8fff18@berav2-bootnode.staketab.org:30303,enode://16e21c20f670d9e88570b8d3c580c7ef54f3515bffab864f1f3047c4125c3e7d98e782b990165808363a1b54ddca51c9dafaca9d6cd7ecca93e2e809ba522cae@berachain-testnet-v2.enode.l0vd.com:30304,enode://e31aa249638083d34817eed2b499ccd4b0718a332f0ea530e3062e13f624cb03a7d6b6e0460193ee87b5fc12e73a726070a3126ef53492ffbdc5e6c102f6dfb3@34.64.198.56:30303,enode://3f2f85e2e711f198fb7324b74fab6a0599b2534774f3aa26241dbbabe870b650574324da01aa98ee24ce97c8d76362a2db03034a6ddff43119ccfdc269663cbf@34.47.79.13:30303,enode://7a2f67d22b12e10c6ba9cd951866dda6471604be5fbd5102217dbad1cc56e590befd2009ecc99958a468a5b8e0dc28e14d9b6822491719c93199be6aa0319077@34.124.220.31:30303,enode://a96aac0b81c7e75fecc2ae613eaf13b27b2aaf3d46a90db904f94797d1746aa31e6593ae4cd476f81d5c6d1d2228ca60c885727978c369586c38871c63a330ee@35.240.182.27:30303,enode://dc44744074ac2dd76db0e0f9d95eb86cd558f6ba75e4a4af1303f2259624c8ce041198f976862a284165253b6dc6b2fa91b995cbca3ef2683879b6247e05e553@34.95.61.239:30303,enode://bf5364e1cf7ecd11646ccaea5c06b56622c04d52200d9cd141e01db9c9661237ceebecde1616e66e390a968ffd1c07e027531cad23044517b7bf36caa8b97f5f@34.152.41.26:30303,enode://f61e51c18fdb6ddf5e520209c53a0e60b2864d168eb0d3c02541050de9fee003b61818c7f70b32b61adee082280e7de4811fd3da47d87c87b3d17bf44e3bb76c@beacond-testnet.blacknodes.net:30303,enode://f24b54da77cf604e92aeb5ee5e79401fd3e66111563ca630e72330ccab6f385ccbbde5eba4577ee7bfb5e83347263d0e4cad042fd4c10468d0e38906fc82ba31@bera-testnet-seeds.nodeinfra.com:30303,enode://2e44e8e12b4666632dd2d4d555cfca5ceac4ca6cf6f45c46fc0ba27d1f9f7578dd598c74ae8b4189430a85b15d103c215a63cdbeafd41895fee1405a094fa77a@135.125.188.10:30303
      - CHAINID=80084
      - CHAINNAME=bartio
      - CHAIN_SPEC=testnet
    entrypoint: [/bin/bash, -c, "trap 'exit 0' SIGTERM; while [ ! -f /config/eth-genesis.json ] && [ ! -f /tmp/stop ]; do sleep 1 & wait $!; done; exec bera-reth node \"$@\"", --]
    command:
      - --bootnodes=enode://0401e494dbd0c84c5c0f72adac5985d2f2525e08b68d448958aae218f5ac8198a80d1498e0ebec2ce38b1b18d6750f6e61a56b4614c5a6c6cf0981c39aed47dc@34.159.32.127:30303,enode://9b6c1eb143c9e3af0c7283262a9a38fe8bf844114b1f304673c2ac1c23e6bccfdaa8f4e9cb8c460bded495933fd92eeff30e6ab2e0538b56e249beea2c512906@35.234.88.149:30303,enode://e9675164b5e17b9d9edf0cc2bd79e6b6f487200c74d1331c220abb5b8ee80c2eefbf18213989585e9d0960683e819542e11d4eefb5f2b4019e1e49f9fd8fff18@berav2-bootnode.staketab.org:30303,enode://16e21c20f670d9e88570b8d3c580c7ef54f3515bffab864f1f3047c4125c3e7d98e782b990165808363a1b54ddca51c9dafaca9d6cd7ecca93e2e809ba522cae@berachain-testnet-v2.enode.l0vd.com:30304,enode://e31aa249638083d34817eed2b499ccd4b0718a332f0ea530e3062e13f624cb03a7d6b6e0460193ee87b5fc12e73a726070a3126ef53492ffbdc5e6c102f6dfb3@34.64.198.56:30303,enode://3f2f85e2e711f198fb7324b74fab6a0599b2534774f3aa26241dbbabe870b650574324da01aa98ee24ce97c8d76362a2db03034a6ddff43119ccfdc269663cbf@34.47.79.13:30303,enode://7a2f67d22b12e10c6ba9cd951866dda6471604be5fbd5102217dbad1cc56e590befd2009ecc99958a468a5b8e0dc28e14d9b6822491719c93199be6aa0319077@34.124.220.31:30303,enode://a96aac0b81c7e75fecc2ae613eaf13b27b2aaf3d46a90db904f94797d1746aa31e6593ae4cd476f81d5c6d1d2228ca60c885727978c369586c38871c63a330ee@35.240.182.27:30303,enode://dc44744074ac2dd76db0e0f9d95eb86cd558f6ba75e4a4af1303f2259624c8ce041198f976862a284165253b6dc6b2fa91b995cbca3ef2683879b6247e05e553@34.95.61.239:30303,enode://bf5364e1cf7ecd11646ccaea5c06b56622c04d52200d9cd141e01db9c9661237ceebecde1616e66e390a968ffd1c07e027531cad23044517b7bf36caa8b97f5f@34.152.41.26:30303,enode://f61e51c18fdb6ddf5e520209c53a0e60b2864d168eb0d3c02541050de9fee003b61818c7f70b32b61adee082280e7de4811fd3da47d87c87b3d17bf44e3bb76c@beacond-testnet.blacknodes.net:30303,enode://f24b54da77cf604e92aeb5ee5e79401fd3e66111563ca630e72330ccab6f385ccbbde5eba4577ee7bfb5e83347263d0e4cad042fd4c10468d0e38906fc82ba31@bera-testnet-seeds.nodeinfra.com:30303,enode://2e44e8e12b4666632dd2d4d555cfca5ceac4ca6cf6f45c46fc0ba27d1f9f7578dd598c74ae8b4189430a85b15d103c215a63cdbeafd41895fee1405a094fa77a@135.125.188.10:30303
      - --chain=/config/eth-genesis.json
      - --datadir=/root/.local/share/reth
      - --discovery.port=10527
      - --engine.always-process-payload-attributes-on-canonical-head
      - --engine.cross-block-cache-size=${BERACHAIN_BARTIO_RETH_STATE_CACHE:-4096}
      - --engine.memory-block-buffer-target=0
      - --engine.persistence-threshold=0
      - --max-inbound-peers=50
      - --max-outbound-peers=50
      - --metrics=0.0.0.0:9001
      - --nat=extip:${IP}
      - --port=10527
      - --rpc-cache.max-blocks=10000
      - --rpc-cache.max-concurrent-db-requests=2048
      - --rpc.gascap=600000000
      - --rpc.max-blocks-per-filter=0
      - --rpc.max-connections=50000
      - --rpc.max-logs-per-response=0
      - --http
      - --http.addr=0.0.0.0
      - --http.api=admin,debug,eth,net,trace,txpool,web3,rpc,reth,ots,flashbots,mev
      - --http.corsdomain=*
      - --http.port=8545
      - --ws
      - --ws.addr=0.0.0.0
      - --ws.api=admin,debug,eth,net,trace,txpool,web3,rpc,reth,ots,flashbots,mev
      - --ws.origins=*
      - --ws.port=8545
      - --authrpc.addr=0.0.0.0
      - --authrpc.jwtsecret=/jwtsecret
    restart: unless-stopped
    stop_grace_period: 5m
    networks:
      - chains
    volumes:
      - ${BERACHAIN_BARTIO_RETH_ARCHIVE_TRACE_DATA:-berachain-bartio-reth-archive-trace}:/root/.local/share/reth
      - .jwtsecret:/jwtsecret:ro
      - /slowdisk:/slowdisk
      - berachain-bartio-reth-archive-trace_config:/config
    logging: *logging-defaults
    labels:
      - prometheus-scrape.enabled=true
      - prometheus-scrape.port=9001
      - prometheus-scrape.path=/metrics
      - traefik.enable=true
      - traefik.http.middlewares.berachain-bartio-reth-archive-trace-stripprefix.stripprefix.prefixes=/berachain-bartio-reth
      - traefik.http.services.berachain-bartio-reth-archive-trace.loadbalancer.server.port=8545
      - ${NO_SSL:-traefik.http.routers.berachain-bartio-reth-archive-trace.entrypoints=websecure}
      - ${NO_SSL:-traefik.http.routers.berachain-bartio-reth-archive-trace.tls.certresolver=myresolver}
      - ${NO_SSL:-traefik.http.routers.berachain-bartio-reth-archive-trace.rule=Host(`$DOMAIN`) && (Path(`/berachain-bartio-reth`) || Path(`/berachain-bartio-reth/`))}
      - ${NO_SSL:+traefik.http.routers.berachain-bartio-reth-archive-trace.rule=Path(`/berachain-bartio-reth`) || Path(`/berachain-bartio-reth/`)}
      - traefik.http.routers.berachain-bartio-reth-archive-trace.middlewares=berachain-bartio-reth-archive-trace-stripprefix, ipallowlist
    shm_size: 2gb

  berachain-bartio-reth-node:
    build:
      context: ./berachain
      dockerfile: beacon-kit.Dockerfile
      args:
        BEACONKIT_VERSION: ${BERACHAIN_BARTIO_BEACON_KIT_VERSION:-v1.3.4}
        BEACONKIT_IMAGE: ${BERACHAIN_BARTIO_BEACON_KIT_IMAGE:-ghcr.io/berachain/beacon-kit}
    ports:
      - 15527:15527
      - 15527:15527/udp
    environment:
      - AUTH_RPC=http://berachain-bartio-reth:8551
      - CHAINID=80084
      - CHAINNAME=bartio
      - CHAIN_SPEC=testnet
      - IP=${IP}
      - MONIKER=d${DOMAIN:-local}
      - P2P_PORT=15527
    restart: unless-stopped
    networks:
      - chains
    volumes:
      - ${BERACHAIN_BARTIO_RETH_ARCHIVE_TRACE__BEACON_KIT_DATA:-berachain-bartio-reth-archive-trace_beacon-kit}:/root/.beacond/data
      - .jwtsecret:/jwtsecret:ro
      - berachain-bartio-reth-archive-trace_config:/root/.beacond/config
    logging: *logging-defaults
    labels:
      - prometheus-scrape.enabled=false

volumes:
  berachain-bartio-reth-archive-trace:
  berachain-bartio-reth-archive-trace_beacon-kit:
  berachain-bartio-reth-archive-trace_config:

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