Skip to content

Commit c52e23a

Browse files
authored
feat: Enable gRPC Endpoint Fallback Functionality [DEV-5132] (#386)
* feat: Enable gRPC Endpoint Fallback Functionality * Format and fix linter issues * Remove deprecated methods while keeping health checks functional * Address PR review comments * Fix linter issues
1 parent b654344 commit c52e23a

File tree

10 files changed

+930
-86
lines changed

10 files changed

+930
-86
lines changed

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ To configure the resolver, modify the values under the `environment` section of
4141
2. `useTls`: Specify whether gRPC connection to ledger should use secure or insecure pulls. Default is `true` since gRPC uses HTTP/2 with TLS as the transport mechanism.
4242
3. `timeout`: Timeout (in seconds) to wait for before any ledger requests are considered to have time out.
4343
2. **`TESTNET_ENDPOINT`** : Testnet Network endpoint as string with the following format" `<networks>,<useTls>,<timeout>`. Example: `grpc.cheqd.network:443,true,5s`
44-
3. **`RESOLVER_LISTENER`**`: A string with address and port where the resolver listens for requests from clients.
45-
4. **`LOG_LEVEL`**: `debug`/`warn`/`info`/`error` - to define the application log level.
44+
3. **`ENABLE_FALLBACK_ENDPOINTS`** : Enable/disable fallback functionalities. Default is `false`.
45+
4. **`MAINNET_ENDPOINT_FALLBACK`** : Fallback mainnet endpoint with the same format as `MAINNET_ENDPOINT`. Used when primary endpoint is unavailable.
46+
5. **`TESTNET_ENDPOINT_FALLBACK`** : Fallback testnet endpoint with the same format as `TESTNET_ENDPOINT`. Used when primary endpoint is unavailable.
47+
6. **`RESOLVER_LISTENER`**`: A string with address and port where the resolver listens for requests from clients.
48+
7. **`LOG_LEVEL`**: `debug`/`warn`/`info`/`error` - to define the application log level.
4649

4750
#### gRPC Endpoints used by DID Resolver
4851

@@ -62,6 +65,28 @@ address = "0.0.0.0:9090"
6265

6366
**Note**: If you're pointing a DID Resolver to your own node instance, by default `cheqd-node` instance gRPC endpoints are _not_ served up with a TLS certificate. This means the `useTls` property would need to be set to `false`, unless you're otherwise using a load balancer that provides TLS connections to the gRPC port.
6467

68+
#### Fallback Endpoint Feature
69+
70+
The DID Resolver supports automatic fallback to backup gRPC endpoints when the primary endpoints are unavailable. This feature provides high availability and fault tolerance.
71+
72+
**How it works:**
73+
74+
- When `ENABLE_FALLBACK_ENDPOINTS=true`, the resolver will automatically try fallback endpoints if the primary endpoint fails
75+
- Health checks are performed on startup and periodically (each 60s), to ensue the most accurate endpoints status
76+
- If a request fails on the primary endpoint between periodic health checks, it will automatically retry request on fallback endpoint
77+
- When the primary endpoint becomes healthy again, it will be used for new requests
78+
- The fallback feature works independently for mainnet and testnet endpoints and both fallback endpoints are required when `ENABLE_FALLBACK_ENDPOINTS` is enabled
79+
80+
**Example configuration:**
81+
82+
```yaml
83+
ENABLE_FALLBACK_ENDPOINTS: "true"
84+
MAINNET_ENDPOINT: "grpc.cheqd.net:443,true,5s"
85+
MAINNET_ENDPOINT_FALLBACK: "grpc-fallback.cheqd.net:443,true,5s"
86+
TESTNET_ENDPOINT: "grpc.cheqd.network:443,true,5s"
87+
TESTNET_ENDPOINT_FALLBACK: "grpc-fallback.cheqd.network:443,true,5s"
88+
```
89+
6590
## 🧑‍💻 Building your own Docker image
6691
6792
### Using Docker Build

docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ RUN addgroup --system $USER \
4141
# Set environment variables with default values
4242
ENV MAINNET_ENDPOINT="grpc.cheqd.net:443,true,5s"
4343
ENV TESTNET_ENDPOINT="grpc.cheqd.network:443,true,5s"
44+
ENV ENABLE_FALLBACK_ENDPOINTS="false"
4445
ENV LOG_LEVEL="warn"
4546
ENV RESOLVER_LISTENER="0.0.0.0:8080"
4647

docker/docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ services:
2828
MAINNET_ENDPOINT: "grpc.cheqd.net:443,true,5s"
2929
TESTNET_ENDPOINT: "grpc.cheqd.network:443,true,5s"
3030

31+
# Fallback endpoints (optional)
32+
ENABLE_FALLBACK_ENDPOINTS: "false"
33+
MAINNET_ENDPOINT_FALLBACK: "grpc-fallback.cheqd.net:443,true,5s"
34+
TESTNET_ENDPOINT_FALLBACK: "grpc-fallback.cheqd.network:443,true,5s"
35+
3136
# Logging level
3237
LOG_LEVEL: "warn"
3338

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ func serve() {
2121
config := types.GetConfig()
2222
// Setup logger
2323
types.SetupLogger(config)
24+
25+
// Initialize endpoint manager
26+
endpointManager := services.NewEndpointManager(config)
27+
2428
// Services
25-
ledgerService := services.NewLedgerService()
29+
ledgerService := services.NewLedgerService(endpointManager)
2630
didService := services.NewDIDDocService(types.DID_METHOD, ledgerService)
2731
resourceService := services.NewResourceService(types.DID_METHOD, ledgerService)
2832

0 commit comments

Comments
 (0)