Mainnet:
rpc.celo-community.org
Baklava:
baklava-rpc.celo-community.org
Alfajores:
alfajores-rpc.celo-community.org
This repository contains Cloudflare Workers that serve as reverse proxies for Celo blockchain RPC endpoints. The workers distribute requests across multiple backend RPC nodes to improve reliability and performance.
The repository is organized by network, with each network having its own directory:
celo-community-rpc/
├── .github/
│ └── workflows/
│ ├── deploy-workers.yml # Workflow for deploying workers
│ ├── deploy-github-pages.yml # Workflow for deploying the website
│ └── update-rpc-servers.yml # Workflow for updating RPC servers
├── mainnet/ # Mainnet RPC proxy
│ ├── config.js # Main request handling logic
│ ├── index.js # Worker entry point
│ ├── rpc-servers.js # RPC endpoint configuration
│ └── wrangler.toml # Cloudflare Worker configuration
├── baklava/ # Baklava testnet RPC proxy
│ ├── config.js
│ ├── index.js
│ ├── rpc-servers.js
│ └── wrangler.toml
├── alfajores/ # Alfajores testnet RPC proxy
│ ├── config.js
│ ├── index.js
│ ├── rpc-servers.js
│ └── wrangler.toml
├── public/ # Website files
│ ├── index.html # Main HTML file
│ ├── styles.css # CSS styles
│ ├── script.js # JavaScript for interactivity
│ └── favicon.svg # Website favicon
├── health-check-worker.js # Active health check worker
├── health-check-worker-wrangler.toml # Configuration for health check worker
├── HEALTH-CHECK-README.md # Documentation for health check system
├── test-health-checks.js # Test script for health checks
├── update-rpc-servers.js # Script to update RPC servers
└── package.json # Project dependencies
Each network directory contains the following files:
index.js
: The entry point for the Cloudflare Worker, which imports and uses thehandleRequest
function fromconfig.js
.config.js
: Contains the main logic for handling RPC requests, including request validation, forwarding to backends, error handling, and CORS. It imports thebackendList
fromrpc-servers.js
.rpc-servers.js
: Contains the list of backend RPC endpoints. This file can be updated by "celcli call" to fetch registered RPC servers and check their health.wrangler.toml
: Cloudflare Worker configuration file.
The worker uses a round-robin strategy to select endpoints from the backendList
for each request, providing load balancing and failover capabilities. If a request fails, the worker will retry with a different endpoint.
This repository uses GitHub Actions to automatically deploy the workers to Cloudflare. The workflow is defined in deploy-workers.yml
.
To deploy the workers, you need to set up the following GitHub secrets:
CLOUDFLARE_API_TOKEN
: Your Cloudflare API token with Worker deployment permissionsCLOUDFLARE_ACCOUNT_ID
: Your Cloudflare account IDCLOUDFLARE_ZONE_ID
: The zone ID for your domainHEALTH_KV_ID
: The ID of your Cloudflare KV namespace for health checksHEALTH_KV_PREVIEW_ID
: The preview ID of your Cloudflare KV namespace (can be the same as HEALTH_KV_ID)
For the automatic RPC server updates workflow, you also need:
GH_PAT
: A GitHub Personal Access Token withrepo
scope (for creating pull requests)
-
Create a KV namespace in your Cloudflare dashboard:
- Go to Workers & Pages > KV
- Click "Create namespace"
- Name it (e.g., "celo-health-checks")
- Note the ID that appears in the dashboard
-
Add the KV namespace ID as a GitHub secret:
- Go to your GitHub repository > Settings > Secrets and variables > Actions
- Add a new repository secret named
HEALTH_KV_ID
with the value of your KV namespace ID - Add another secret named
HEALTH_KV_PREVIEW_ID
with the same value
-
(Optional) If you want to use separate KV namespaces for each network:
- Create three KV namespaces in Cloudflare (one for each network)
- Add the following secrets to GitHub:
MAINNET_HEALTH_KV_ID
andMAINNET_HEALTH_KV_PREVIEW_ID
BAKLAVA_HEALTH_KV_ID
andBAKLAVA_HEALTH_KV_PREVIEW_ID
ALFAJORES_HEALTH_KV_ID
andALFAJORES_HEALTH_KV_PREVIEW_ID
- Uncomment the relevant sections in the GitHub Actions workflow file
To set up these secrets:
- Go to your GitHub repository
- Click on "Settings" > "Secrets and variables" > "Actions"
- Click on "New repository secret"
- Add each of the required secrets
For the GH_PAT:
- Go to your GitHub account settings
- Navigate to Developer settings > Personal access tokens > Fine-grained tokens (or Classic tokens)
- Create a new token with
repo
scope permissions - Copy the generated token and add it as a repository secret named
GH_PAT
You can also deploy the workers manually using the Wrangler CLI:
-
Install Wrangler:
npm install -g wrangler
-
Authenticate with Cloudflare:
wrangler login
-
Deploy a specific worker:
cd mainnet wrangler publish
To add a new RPC endpoint to a network:
- Open the network's
rpc-servers.js
file - Add the new endpoint URL to the
backendList
array
Example:
export const backendList = [
'https://forno.celo.org',
'https://your-new-endpoint.example.com',
// Add additional RPC endpoints here
];
The rpc-servers.js
file can also be updated automatically using the automated process described in the "Automatic RPC Server Updates" section below.
The RPC proxy includes information about which backend server processed the request in the response headers:
- For single requests: An
X-Backend-Server
header contains the URL of the backend server that processed the request. - For batch requests: An
X-Backend-Servers
header contains a comma-separated list of all backend servers that processed the requests in the batch.
These headers are useful for debugging, monitoring, and troubleshooting purposes, allowing you to identify which backend server handled a specific request.
Example response headers:
Content-Type: application/json
X-Backend-Server: https://forno.celo.org
Access-Control-Allow-Origin: *
The RPC proxy implements different strategies for handling request failures depending on whether it's a single request or a batch request:
- The system implements a retry mechanism with up to 2 retries
- If a request fails, it selects a different backend from the
backendList
using round-robin selection - It tries the request again with the new backend
- If all retries fail, it returns a JSON-RPC error response
- Each request in the batch is processed independently
- There is no retry mechanism for individual requests within a batch
- Failed requests return error responses within the batch, while other requests may still succeed
The RPC proxy includes a comprehensive health check system that automatically detects and excludes unhealthy backends from the rotation. This improves reliability by ensuring that requests are only sent to healthy backends.
The health check system consists of two components:
-
Passive Health Checks: Implemented directly in the RPC proxy workers
- Detect failures during actual user requests
- Immediately mark failing backends as unhealthy in Cloudflare KV
- Exclude unhealthy backends from the rotation for a cooldown period (5 minutes)
- Automatically reinstate backends after the cooldown period
-
Active Health Checks: Implemented as a separate scheduled worker
- Runs every 15 minutes
- Proactively checks the health of all backends
- Verifies that backends are fully synced and responsive
- Marks unhealthy backends in Cloudflare KV
The health check system provides a public endpoint that shows the current health status of all backends:
https://health.celo-community.org/
This endpoint returns a JSON response with information about healthy and unhealthy backends for each network. It's useful for monitoring and debugging purposes.
The health status endpoint implements a sophisticated multi-level caching strategy to optimize performance and reduce resource usage:
-
Cloudflare Edge Caching: Leverages Cloudflare's global CDN for ultra-fast responses
- Responses are cached at edge locations worldwide
- Direct cache purging using the Cache API during scheduled health checks
- Real-time cache purging when a backend is marked as unhealthy
- No external API calls required for cache management
-
KV Store Caching: Provides a fallback when edge cache misses occur
- Complete response caching reduces KV read operations
- Only updated during scheduled health checks (every 15 minutes)
-
HTTP Cache Headers: Enable browser and proxy caching
- ETag and Last-Modified headers for conditional requests
- 304 Not Modified responses for unchanged content
- Proper Vary headers for different encodings and origins
-
Client-side Features:
- Force refresh option with the refresh button
- Transparent UI showing all relevant timestamps
- Cache status indicators in the interface
This approach significantly reduces KV reads while still providing timely health status information.
The health check system includes several optimizations:
- Longer Health Check Interval: The health check worker runs every 15 minutes
- HTTP Response Caching: Responses are cached for 5 minutes
- KV Caching: Validator addresses are cached for 1 hour
- KV Expiration: Data is stored with appropriate TTLs to clean up stale information
- Increased Timeout: Health check timeout is set to 10 seconds
- Improved Reliability: Unhealthy backends are automatically excluded from the rotation
- Faster Response Times: Requests are only sent to healthy backends
- Automatic Recovery: Backends are automatically reinstated after the cooldown period
- Proactive Issue Detection: Active health checks detect issues before they affect users
- Monitoring: Public health status endpoint for monitoring and debugging
- Efficient Resource Usage: Caching strategy reduces KV operations while maintaining data freshness
For detailed information about the health check system, see HEALTH-CHECK-README.md.
This repository includes an automated system to keep the RPC server lists up-to-date by querying the blockchain for registered community RPC servers and performing health checks.
The update-rpc-servers.js
script:
- Queries the blockchain using
celocli network:rpc-urls --node <network>
to get registered RPC servers - Performs health checks on all RPC servers (existing and new)
- Updates the appropriate
rpc-servers.js
files with healthy servers - Maintains a history of health checks to avoid removing servers that might be temporarily unavailable
A GitHub Actions workflow (update-rpc-servers.yml
) runs the script daily and creates a pull request with any changes:
- The workflow runs at midnight UTC every day
- It can also be triggered manually from the Actions tab
- It creates a pull request with the updated RPC server lists (requires the
GH_PAT
secret) - The pull request can be reviewed and merged by a maintainer
Note: The workflow requires a GitHub Personal Access Token (stored as
GH_PAT
secret) to create pull requests, as the defaultGITHUB_TOKEN
may have limited permissions depending on repository settings.
You can also run the update script manually:
-
Install dependencies:
npm install
-
Install celocli:
npm install -g @celo/celocli
-
Run the script:
node update-rpc-servers.js
You need to configure DNS records to point to your Cloudflare Workers:
rpc.celo-community.org
→ Mainnet Workerbaklava-rpc.celo-community.org
→ Baklava Workeralfajores-rpc.celo-community.org
→ Alfajores Worker
health.celo-community.org
→ Health Check Worker
This is handled automatically when using Cloudflare as your DNS provider and setting up the routes in the wrangler.toml
files.
This repository includes a modern, responsive website that provides information about the Celo Community RPC service. The website is deployed using GitHub Pages and can be accessed at: https://celo-community.org
- Displays RPC URLs for all three networks (Mainnet, Alfajores, Baklava)
- Shows backend servers for each network
- Provides usage examples for Web3.js, ethers.js, and celo-cli
- Responsive design that works on mobile and desktop
- Dark mode support
To run the website locally:
# Clone the repository
git clone https://github.com/atweb3-io/celo-community-rpc.git
cd celo-community-rpc
# Open the website in your browser
open public/index.html
The website is automatically deployed to GitHub Pages when changes are pushed to the main branch. The deployment is handled by the GitHub Actions workflow defined in .github/workflows/deploy-github-pages.yml
.