services:
  zksync-era-external-node-archive-db:
    image: "postgres:14"
    command: >
      postgres
      -c max_connections=200
      -c log_error_verbosity=terse
      -c shared_buffers=2GB
      -c effective_cache_size=4GB
      -c maintenance_work_mem=1GB
      -c checkpoint_completion_target=0.9
      -c random_page_cost=1.1
      -c effective_io_concurrency=200
      -c min_wal_size=4GB
      -c max_wal_size=16GB
      -c max_worker_processes=16
      -c checkpoint_timeout=1800
    expose:
      - 5430
    volumes:
      - ${ZKSYNC_ERA_MAINNET_EXTERNAL_NODE_ARCHIVE__DB_DATA:-zksync-era-mainnet-external-node-archive_db}:/var/lib/postgresql/data
    healthcheck:
      interval: 1s
      timeout: 3s
      test:
        [
          "CMD-SHELL",
          'psql -U postgres -c "select exists (select * from pg_stat_activity where datname = ''{{ database_name }}'' and application_name = ''pg_restore'')" | grep -e ".f$$"',
        ]
    environment:
      - POSTGRES_PASSWORD=notsecurepassword
      - PGPORT=5430
    networks:
      - chains

  zksync-era-external-node-archive-client:
    image: "matterlabs/external-node:v26.2.1"
    depends_on:
      - zksync-era-external-node-archive-db
    ports:
      - "127.0.0.1:3060:3060"
      - "127.0.0.1:3061:3061"
      - "127.0.0.1:3081:3081"
    volumes:
      - ${ZKSYNC_ERA_MAINNET_EXTERNAL_NODE_ARCHIVE__CLIENT_DATA:-zksync-era-mainnet-external-node-archive_client}:/db
    expose:
      - 3322
    environment:
      DATABASE_URL: "postgres://postgres:notsecurepassword@zksync-era-external-node-archive-db:5430/zksync_local_ext_node"
      DATABASE_POOL_SIZE: 10

      EN_HTTP_PORT: 3060
      EN_WS_PORT: 3061
      EN_HEALTHCHECK_PORT: 3081
      EN_PROMETHEUS_PORT: 3322
      EN_ETH_CLIENT_URL: ${ZKSYNC_ERA_L1_ETHEREUM_MAINNET_EXECUTION_RPC:-https://ethereum-rpc.publicnode.com}
      EN_MAIN_NODE_URL: https://zksync2-mainnet.zksync.io
      EN_L1_CHAIN_ID: 1
      EN_L2_CHAIN_ID: 324
      # EN_PRUNING_ENABLED: true

      EN_STATE_CACHE_PATH: "./db/ext-node/state_keeper"
      EN_MERKLE_TREE_PATH: "./db/ext-node/lightweight"
      EN_SNAPSHOTS_RECOVERY_ENABLED: "true"
      EN_SNAPSHOTS_OBJECT_STORE_BUCKET_BASE_URL: "zksync-era-mainnet-external-node-snapshots"
      EN_SNAPSHOTS_OBJECT_STORE_MODE: "GCSAnonymousReadOnly"
      RUST_LOG: "warn,zksync=info,zksync_core::metadata_calculator=debug,zksync_state=debug,zksync_utils=debug,zksync_web3_decl::client=error"
    networks:
      - chains

  zksync-era-external-node-archive:
    restart: unless-stopped           
    image: nginx
    depends_on:
      - zksync-era-external-node-archive-client
    expose:  
      - 80                                                                                    
    environment:                                                                                      
      PROXY_HOST: zksync-era-external-node-archive-client
      RPC_PORT: 3060
      RPC_PATH: ""
      WS_PORT: 3061
      WS_PATH: ""
    networks:         
      - chains 
    volumes:               
      - ./nginx-proxy:/etc/nginx/templates            
    labels:
      - "traefik.enable=true"
      - "traefik.http.middlewares.zksync-era-mainnet-external-node-archive-stripprefix.stripprefix.prefixes=/zksync-era-archive"
      - "traefik.http.services.zksync-era-mainnet-external-node-archive.loadbalancer.server.port=3060"
      - "${NO_SSL:-traefik.http.routers.zksync-era-mainnet-external-node-archive.entrypoints=websecure}"
      - "${NO_SSL:-traefik.http.routers.zksync-era-mainnet-external-node-archive.tls.certresolver=myresolver}"
      - "${NO_SSL:-traefik.http.routers.zksync-era-mainnet-external-node-archive.rule=Host(`$DOMAIN`) && PathPrefix(`/zksync-era-archive`)}"
      - "${NO_SSL:+traefik.http.routers.zksync-era-mainnet-external-node-archive.rule=PathPrefix(`/zksync-era-archive`)}"      
      - "traefik.http.routers.zksync-era-mainnet-external-node-archive.middlewares=zksync-era-mainnet-external-node-archive-stripprefix, ipwhitelist"


volumes:
  zksync-era-mainnet-external-node-archive_db: {}
  zksync-era-mainnet-external-node-archive_client: {}
