From 98684d353f65525b325881a3dbcea602c256e1c1 Mon Sep 17 00:00:00 2001 From: 0age <37939117+0age@users.noreply.github.com> Date: Mon, 9 Dec 2024 23:17:39 -0800 Subject: [PATCH] add supported chains and finalization thresholds for each to /health --- README.md | 19 ++++++++++++++++++- src/__tests__/routes/health.test.ts | 24 ++++++++++++++++++++++++ src/routes/health.ts | 24 ++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9deee4b..2a23698 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,24 @@ Example response: "status": "healthy", "allocatorAddress": "0x1234567890123456789012345678901234567890", "signingAddress": "0x9876543210987654321098765432109876543210", - "timestamp": "2024-03-07T12:00:00.000Z" + "timestamp": "2024-03-07T12:00:00.000Z", + "chainConfig": { + "defaultFinalizationThresholdSeconds": 3, + "supportedChains": [ + { + "chainId": "1", + "finalizationThresholdSeconds": 25 + }, + { + "chainId": "10", + "finalizationThresholdSeconds": 10 + }, + { + "chainId": "8453", + "finalizationThresholdSeconds": 2 + } + ] + } } ``` diff --git a/src/__tests__/routes/health.test.ts b/src/__tests__/routes/health.test.ts index 4229b8a..c518710 100644 --- a/src/__tests__/routes/health.test.ts +++ b/src/__tests__/routes/health.test.ts @@ -26,6 +26,30 @@ describe('Health Routes', () => { expect(body).toHaveProperty('allocatorAddress'); expect(body).toHaveProperty('signingAddress'); expect(body).toHaveProperty('timestamp'); + expect(body).toHaveProperty('chainConfig'); + + // Verify chain config structure and values + expect(body.chainConfig).toHaveProperty( + 'defaultFinalizationThresholdSeconds', + 3 + ); + expect(body.chainConfig).toHaveProperty('supportedChains'); + expect(Array.isArray(body.chainConfig.supportedChains)).toBe(true); + + // Verify specific chain configurations + const chainConfigs = new Map( + body.chainConfig.supportedChains.map( + (chain: { + chainId: string; + finalizationThresholdSeconds: number; + }) => [chain.chainId, chain.finalizationThresholdSeconds] + ) + ); + + expect(chainConfigs.get('1')).toBe(25); // Ethereum Mainnet + expect(chainConfigs.get('10')).toBe(10); // Optimism + expect(chainConfigs.get('8453')).toBe(2); // Base + expect(chainConfigs.size).toBe(3); // Ensure no unexpected chains // Verify timestamp is a valid ISO 8601 date expect(new Date(body.timestamp).toISOString()).toBe(body.timestamp); diff --git a/src/routes/health.ts b/src/routes/health.ts index 4575052..5fee765 100644 --- a/src/routes/health.ts +++ b/src/routes/health.ts @@ -1,4 +1,13 @@ import { FastifyInstance } from 'fastify'; +import { chainConfig } from '../chain-config'; + +interface ChainConfigResponse { + defaultFinalizationThresholdSeconds: number; + supportedChains: Array<{ + chainId: string; + finalizationThresholdSeconds: number; + }>; +} export async function setupHealthRoutes( server: FastifyInstance @@ -11,15 +20,30 @@ export async function setupHealthRoutes( allocatorAddress: string; signingAddress: string; timestamp: string; + chainConfig: ChainConfigResponse; }> => { if (!process.env.ALLOCATOR_ADDRESS || !process.env.SIGNING_ADDRESS) { throw new Error('Required environment variables are not set'); } + + // Transform chain config into the desired format + const chainConfigResponse: ChainConfigResponse = { + defaultFinalizationThresholdSeconds: + chainConfig.defaultFinalizationThreshold, + supportedChains: Object.entries(chainConfig.finalizationThresholds).map( + ([chainId, threshold]) => ({ + chainId, + finalizationThresholdSeconds: threshold, + }) + ), + }; + return { status: 'healthy', allocatorAddress: process.env.ALLOCATOR_ADDRESS, signingAddress: process.env.SIGNING_ADDRESS, timestamp: new Date().toISOString(), + chainConfig: chainConfigResponse, }; } );