This is a simple RPC proxy server that forwards requests to an Ethereum RPC backend. It includes features like whitelisting, blacklisting, and rate limiting.
## Environment Variables
The following environment variables can be used to configure the proxy:
### General Configuration
-`ETH_RPC_BACKEND`: The URL of the real Ethereum RPC backend to forward requests to.
-`MYSQL_DSN`: The Data Source Name (DSN) for the MySQL database connection (e.g., `user:password@tcp(127.0.0.1:3306)/dbname`).
-`BLACKLIST_CONTRACT_ADDR`: The address of the blacklist contract on the Ethereum network.
-`WHITELIST_FILE`: The path to the file containing whitelisted IP addresses or domains.
-`BLACKLIST_CACHE_CLEANUP_INTERVAL`: The interval for cleaning up the blacklist cache (default: `5m`).
### Rate Limiting Configuration
The proxy implements a two-stage rate limiting mechanism: **Normal Mode** and **Penalty Mode**.
#### Normal Mode
Applies to all non-whitelisted IPs by default.
-`RATE_LIMIT_NORMAL`: The number of requests allowed per 15 minutes for normal usage (default: `1000`).
-`RATE_BURST_NORMAL`: The burst size for normal usage (default: `20`).
#### Penalty Mode
Applies to IPs that frequently exceed the rate limit.
-`RATE_LIMIT_PENALTY`: The number of requests allowed per 15 minutes for penalized IPs (default: `100`).
-`RATE_BURST_PENALTY`: The burst size for penalized IPs (default: `5`).
-`PENALTY_DURATION`: The duration an IP stays in penalty mode (default: `20m`).
-`PENALTY_TRIGGER_COUNT`: The number of consecutive rate limit violations required to trigger penalty mode (default: `5`).
## Usage
1. Set the required environment variables.
2. Run the proxy server.
3. The server listens on port `8545`.
## Whitelist File Format
The whitelist file should contain one entry per line. Lines starting with `#` or `//` are ignored.