This repository contains the code for a proxy that acts as a gateway on the validator side. The goal is to prevent requests made on the API server from being rejected on miners side. This happens because their IPs are not in the whitelist and miners have set up firewalls against DDoS attacks. The solution is to setup a proxy on the validator side (acting as a gateway between API server and the miner) to use the validator IP which is registered.
- Pin a
tunnel
on Cloudflare for the secure connection between the validator and the API server. - Setup the proxy on the validator server and configure the proxy.
- Run cloudflare daemon (
cloudflared
) on API server to query the network through the validator.
- Domain on Cloudflare for the proxy
- Validator server registered on the network
- API server serving any kind of API that requires access to the network
- Proxy that supports
connect
method
-
Create a Cloudflare tunnel More...
-
Install
cloudflared
on validator server More... (In my case, I'm using Ubuntu 22.04)sudo mkdir -p --mode=0755 /usr/share/keyrings curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared jammy main' | sudo tee /etc/apt/sources.list.d/cloudflared.list
sudo apt-get update && sudo apt-get install cloudflared
cloudflared -V
pm2 start "cloudflared tunnel run --token <YOUR-TUNNEL-TOKEN>" --name cloudflared
-
Install
cloudflared
on API server (In my case, I'm using Ubuntu 22.04)curl -L --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared.deb
pm2 start cloudflared -- access tcp --hostname <YOUR-DOMAIN> --url localhost:8888
-
Install proxy on validator server
git clone https://github.com/BitAPAI/proxy.openvalidator.git
cd proxy.openvalidator PROXY_USERNAME=<PROXY_USERNAME> PROXY_PASSWORD=<PROXY_PASSWORD> pm2 start python --name proxy -- main.py
wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz export PATH=$PATH:/usr/local/go/bin
git clone https://github.com/adriansmares/connect.git
cd connect PROXY_USERNAME=<PROXY_USERNAME> PROXY_PASSWORD=<PROXY_PASSWORD> pm2 start --name connect go -- run main.go
-
Start API server (via
cloudflared
)
HTTP_PROXY=http://<PROXY_USERNAME>:<PROXY_PASSWORD>@localhost:8888 pm2 start python --name api -- main.py