Skip to content

Commit

Permalink
add supported chains and finalization thresholds for each to /health
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Dec 10, 2024
1 parent 3c1ce4a commit 98684d3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
}
```

Expand Down
24 changes: 24 additions & 0 deletions src/__tests__/routes/health.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions src/routes/health.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
};
}
);
Expand Down

0 comments on commit 98684d3

Please sign in to comment.