diff --git a/package-lock.json b/package-lock.json index d715c60..f15e53e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@fastify/multipart": "^7.1.0", "@fastify/swagger": "^8.3.1", "@fastify/type-provider-typebox": "^3.2.0", - "@hirosystems/api-toolkit": "^1.4.0", + "@hirosystems/api-toolkit": "^1.7.0", "@hirosystems/chainhook-client": "^1.8.0", "@semantic-release/changelog": "^6.0.3", "@semantic-release/commit-analyzer": "^10.0.4", @@ -1250,13 +1250,14 @@ } }, "node_modules/@hirosystems/api-toolkit": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/@hirosystems/api-toolkit/-/api-toolkit-1.4.0.tgz", - "integrity": "sha512-n1LF5roEQ7LkfAvKw0Wucmbo+XhvQBp4ED9N/AyD76/wHQeU59nocDkVAoKSJzWzzCfHa2+G32d3zB3m6oMbIQ==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@hirosystems/api-toolkit/-/api-toolkit-1.7.0.tgz", + "integrity": "sha512-V2RfR3f1qvbF3kTzMZ23iLwjPCKXi49qNgmJikUXOloO1pBP7O1OpMS7VWtk6HOOQ9kkoNXasZsE1hQTlU+Swg==", "dependencies": { "@fastify/cors": "^8.0.0", "@fastify/swagger": "^8.3.1", "@fastify/type-provider-typebox": "^3.2.0", + "@sinclair/typebox": "^0.28.20", "fastify": "^4.3.0", "fastify-metrics": "^10.2.0", "node-pg-migrate": "^6.2.2", @@ -2910,8 +2911,7 @@ "node_modules/@sinclair/typebox": { "version": "0.28.20", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.28.20.tgz", - "integrity": "sha512-QCF3BGfacwD+3CKhGsMeixnwOmX4AWgm61nKkNdRStyLVu0mpVFYlDSY8gVBOOED1oSwzbJauIWl/+REj8K5+w==", - "peer": true + "integrity": "sha512-QCF3BGfacwD+3CKhGsMeixnwOmX4AWgm61nKkNdRStyLVu0mpVFYlDSY8gVBOOED1oSwzbJauIWl/+REj8K5+w==" }, "node_modules/@sinonjs/commons": { "version": "1.8.6", @@ -19724,13 +19724,14 @@ "requires": {} }, "@hirosystems/api-toolkit": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/@hirosystems/api-toolkit/-/api-toolkit-1.4.0.tgz", - "integrity": "sha512-n1LF5roEQ7LkfAvKw0Wucmbo+XhvQBp4ED9N/AyD76/wHQeU59nocDkVAoKSJzWzzCfHa2+G32d3zB3m6oMbIQ==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@hirosystems/api-toolkit/-/api-toolkit-1.7.0.tgz", + "integrity": "sha512-V2RfR3f1qvbF3kTzMZ23iLwjPCKXi49qNgmJikUXOloO1pBP7O1OpMS7VWtk6HOOQ9kkoNXasZsE1hQTlU+Swg==", "requires": { "@fastify/cors": "^8.0.0", "@fastify/swagger": "^8.3.1", "@fastify/type-provider-typebox": "^3.2.0", + "@sinclair/typebox": "^0.28.20", "fastify": "^4.3.0", "fastify-metrics": "^10.2.0", "node-pg-migrate": "^6.2.2", @@ -20919,8 +20920,7 @@ "@sinclair/typebox": { "version": "0.28.20", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.28.20.tgz", - "integrity": "sha512-QCF3BGfacwD+3CKhGsMeixnwOmX4AWgm61nKkNdRStyLVu0mpVFYlDSY8gVBOOED1oSwzbJauIWl/+REj8K5+w==", - "peer": true + "integrity": "sha512-QCF3BGfacwD+3CKhGsMeixnwOmX4AWgm61nKkNdRStyLVu0mpVFYlDSY8gVBOOED1oSwzbJauIWl/+REj8K5+w==" }, "@sinonjs/commons": { "version": "1.8.6", diff --git a/package.json b/package.json index 889db34..13126bb 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@fastify/multipart": "^7.1.0", "@fastify/swagger": "^8.3.1", "@fastify/type-provider-typebox": "^3.2.0", - "@hirosystems/api-toolkit": "^1.4.0", + "@hirosystems/api-toolkit": "^1.7.0", "@hirosystems/chainhook-client": "^1.8.0", "@semantic-release/changelog": "^6.0.3", "@semantic-release/commit-analyzer": "^10.0.4", diff --git a/src/env.ts b/src/env.ts index fc8f038..83ec68a 100644 --- a/src/env.ts +++ b/src/env.ts @@ -26,6 +26,8 @@ const schema = Type.Object({ EVENT_SERVER_BODY_LIMIT: Type.Integer({ default: 20971520 }), /** Hostname that will be reported to the ordhook node so it can call us back with events */ EXTERNAL_HOSTNAME: Type.String({ default: '127.0.0.1' }), + /** Port in which to serve the profiler */ + PROFILER_PORT: Type.Number({ default: 9119 }), /** Hostname of the ordhook node we'll use to register predicates */ ORDHOOK_NODE_RPC_HOST: Type.String({ default: '127.0.0.1' }), diff --git a/src/index.ts b/src/index.ts index 464a69d..9865e87 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,9 @@ -import { isProdEnv, logger, registerShutdownConfig } from '@hirosystems/api-toolkit'; +import { + buildProfilerServer, + isProdEnv, + logger, + registerShutdownConfig, +} from '@hirosystems/api-toolkit'; import { buildApiServer, buildPromServer } from './api/init'; import { startOrdhookServer } from './ordhook/server'; import { ENV } from './env'; @@ -56,6 +61,16 @@ async function initApp() { await initApiService(db); } + const profilerServer = await buildProfilerServer(); + registerShutdownConfig({ + name: 'Profiler Server', + forceKillable: false, + handler: async () => { + await profilerServer.close(); + }, + }); + await profilerServer.listen({ host: ENV.API_HOST, port: ENV.PROFILER_PORT }); + registerShutdownConfig({ name: 'DB', forceKillable: false,