import { type LoggerBindings, createLogger } from '@aztec/foundation/log'; import { createStore } from '@aztec/kv-store/lmdb-v2'; import { type BootnodeConfig, BootstrapNode } from '@aztec/p2p'; import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client'; import Koa from 'koa'; import Router from 'koa-router'; const { HTTP_PORT } = process.env; /** * The application entry point. */ async function main( config: BootnodeConfig, telemetryClient: TelemetryClient = getTelemetryClient(), bindings?: LoggerBindings, ) { const logger = createLogger('p2p-bootstrap:bootstrap_node', bindings); const store = await createStore('p2p-bootstrap', 1, config, bindings); const bootstrapNode = new BootstrapNode(store, telemetryClient, bindings); await bootstrapNode.start(config); logger.info('DiscV5 Bootnode started'); const httpApp = new Koa(); const router = new Router(); router.get('/health', (ctx: Koa.Context) => { ctx.status = 200; }); httpApp.use(router.routes()).use(router.allowedMethods()); httpApp.listen(HTTP_PORT, () => { logger.info(`HTTP server listening on port ${HTTP_PORT}`); }); const stop = async () => { logger.debug('Stopping bootstrap node...'); await bootstrapNode.stop(); logger.info('Node stopped'); process.exit(0); }; // eslint-disable-next-line @typescript-eslint/no-misused-promises process.on('SIGTERM', stop); // eslint-disable-next-line @typescript-eslint/no-misused-promises process.on('SIGINT', stop); } export default main;