services:
  #linea-erigon-init:
  #  image: alpine:latest
  #  entrypoint: ["/bin/sh", "-c"]
  #  command:
  #    - |
  #      apk add --no-cache openssl xxd;
  #      mkdir -p /config;
  #      if [ ! -f /config/nodekey ]; then
  #        echo "Generating new Geth node key...";
  #        openssl rand 32 | xxd -p -c 32 | tr -d '\n' > /configs/mainnet/shared/nodekey;
  #        echo "Node key generated: $(cat /config/nodekey)";
  #      else
  #        echo "Node key already exists, skipping generation.";
  #      fi
  #  volumes:
  #    - ./linea/shared:/configs/mainnet/shared
  #  init: true
  
  linea-erigon:
    image: erigontech/erigon:${ERIGON2_VERSION:-v2.61.3}
    user: root
    #depends_on:
    #  - linea-erigon-init
    expose:
      - "51262"
      - "9090"
      - "8545"
      - "8551"
    ports:
      - "30319:30319"
      - "30319:30319/udp"
      - "48799:48799"
      - "48799:48799/udp"
      - "18025:18025"
      - "18025:18025/udp"
    volumes:
      - ${LINEA_MAINNET_ERIGON_ARCHIVE_TRACE_DATA:-linea-mainnet-erigon-archive-trace}:/root/.local/share/erigon
      - ./linea/mainnet:/configs/mainnet/shared
      - ./linea/scripts/entrypoint.erigon.sh:/entrypoint.sh
      - .jwtsecret:/jwtsecret:ro
    networks:
      - chains
    entrypoint: /entrypoint.sh
    environment:
      - "IP=${IP}"
    command: >
      --chain=mainnet
      --networkid=59144
      --miner.gaslimit=61000000
      --txpool.accountqueue 50000
      --txpool.globalqueue 50000
      --txpool.globalslots 50000
      --txpool.pricelimit 1000000000
      --txpool.nolocals
      --nat=extip:${IP}
      --snapshots=false
      --port=30319
      --p2p.allowed-ports 18025                                                                                                                                             
      --p2p.allowed-ports 48799      
      --bootnodes=enode://069800db9e6e0ec9cadca670994ef1aea2cfd3d88133e63ecadbc1cdbd1a5847b09838ee08d8b5f02a9c32ee13abeb4d4104bb5514e5322c9d7ee19f41ff3e51@3.132.73.210:31002,enode://a8e03a71eab12ec4b47bb6e19169d8e4dc7a58373a2476969bbe463f2dded6003037fa4dd5f71e15027f7fc8d7340956fbbefed67ddd116ac19a7f74da034b61@3.132.73.210:31003,enode://97706526cf79df9d930003644f9156805f6c8bd964fc79e083444f7014ce10c9bdd2c5049e63b58040dca1d4c82ebef970822198cf0714de830cff4111534ff1@18.223.198.165:31004,enode://24e1c654a801975a96b7f54ebd7452ab15777fc635c1db25bdbd4425fdb04e7f4768e9e838a87ab724320a765e41631d5d37758c933ad0e8668693558125c8aa@18.223.198.165:31000,enode://27010891d960f73d272a553f72b6336c6698db3ade98d631f09c764e57674a797be5ebc6829ddbb65ab564f439ebc75215d20aa98b6f351d12ea623e7d139ac3@3.132.73.210:31001,enode://228e1b8a4931e46f383e30721dac21fb8fb4e5e1b32c870e13b25478c82db3dc1cd9e7ceb93d302a766466b55638cc9c5cbfc43aa48fa41ced19baf365951f76@3.1.142.64:31002,enode://c22eb0d40fc3ad5ea710aeddea906567778166bfe18c157955e8c39b23a46c45db18a0fa2ba07f2b64c81178a8c796aec2a29151533920ead06fcdfc6d8d03c6@47.128.192.57:31004,enode://8ce733abe39fd7ae0a278b9893f85c1193c611a3886168690dd843435460f22cc4d61f9e8d0ace7f5905836a665319a31cccdaacdada2acc69972c382ecce7db@3.1.142.64:31003,enode://b7c1b2bed65a855f7a2104aac9a14674dfdf018fdac763415b373b29ce18cdb81d36328ba4e5c9f12629f3a50c3e8f9ee048f22dbdbe93a82813da89c6b81334@51.20.235.126:31004,enode://95270e0550848a72fb141cf27f1c4ea10714edde365b411dc0fa06c81c0f282ce155eb9fa472b6b8bb9ee98395eeaf4c5a7b02a01fe58b37ea98ba152eda4c37@13.50.94.193:31000,enode://72013391755f24f08567b932feeeec4c893c06e0b1fb480890c83bf87fd277ad86a5ab9cb586db9ae9970371a2f8cb0c96f6c9f69045abca0fb801db7f047138@51.20.235.126:31001
      --metrics --metrics.addr=0.0.0.0 --metrics.port=6060
      --private.api.addr=0.0.0.0:9090
      --pprof
      --pprof.addr=0.0.0.0
      --pprof.port=6061
      --authrpc.addr=0.0.0.0
      --authrpc.vhosts=*
      --authrpc.jwtsecret=/jwtsecret
      --http.addr=0.0.0.0
      --http.vhosts=*
      --http.corsdomain=*
      --http.api=eth,erigon,web3,net,debug,trace,txpool,admin
      --rpc.returndata.limit=1000000
      --rpc.gascap=5000000000
      --ws
      --ws.port=8545
    restart: unless-stopped
    stop_grace_period: 1m
    labels:
      - traefik.enable=true
      - traefik.http.middlewares.linea-mainnet-erigon-archive-trace-stripprefix.stripprefix.prefixes=/linea-mainnet-erigon
      - traefik.http.services.linea-mainnet-erigon-archive-trace.loadbalancer.server.port=8545
      - ${NO_SSL:-traefik.http.routers.linea-mainnet-erigon-archive-trace.entrypoints=websecure}
      - ${NO_SSL:-traefik.http.routers.linea-mainnet-erigon-archive-trace.tls.certresolver=myresolver}
      - ${NO_SSL:-traefik.http.routers.linea-mainnet-erigon-archive-trace.rule=Host(`$DOMAIN`) && (Path(`/linea-mainnet-erigon`) || Path(`/linea-mainnet-erigon/`))}
      - ${NO_SSL:+traefik.http.routers.linea-mainnet-erigon-archive-trace.rule=Path(`/linea-mainnet-erigon`) || Path(`/linea-mainnet-erigon/`)}
      - traefik.http.routers.linea-mainnet-erigon-archive-trace.middlewares=linea-mainnet-erigon-archive-trace-stripprefix, ipallowlist
    shm_size: 2gb
    
  linea-erigon-node:
    build:
      context: ./linea
      dockerfile: maru.Dockerfile
      args:
        MARU_IMAGE: ${LINEA_MAINNET_MARU_IMAGE:-consensys/maru}
        MARU_VERSION: ${LINEA_MAINNET_MARU_VERSION:-9737a45}
    ports:
      - 15060:15060
      - 15060:15060/udp
    expose:
      - 8080
    environment:
      - EL_HOST=linea-erigon
      - IP=${IP}
      - L1_RPC=${ETHEREUM_MAINNET_EXECUTION_RPC}
      - P2P_PORT=15060
      - SEQUENCER=https://rpc.linea.build
    entrypoint: [/bin/bash, -c]
    command:
      - |
        envsubst < /config/maru/config.toml.template > /config.toml
        exec java -Dlog4j2.configurationFile=/config/maru/log4j.xml -jar /opt/consensys/maru/maru.jar --config=/config.toml --maru-genesis-file=/config/maru/genesis.json "$@"
    restart: unless-stopped
    networks:
      - chains
    volumes:
      - ${LINEA_MAINNET_ERIGON_ARCHIVE_TRACE__MARU_DATA:-linea-mainnet-erigon-archive-trace_maru}:/opt/maru/data
      - ./linea/mainnet:/config
      - .jwtsecret:/jwtsecret:ro
    labels:
      - prometheus-scrape.enabled=true
      - prometheus-scrape.port=9090
      - prometheus-scrape.path=/debug/metrics/prometheus

volumes:
  linea-mainnet-erigon-archive-trace:
  linea-mainnet-erigon-archive-trace_maru:
