Skip to content

Commit

Permalink
deps: update fastify to v4.26.2 (#6626)
Browse files Browse the repository at this point in the history
* deps: update fastify to v4.26.2

* Retrieve operationId from route schema instead of config

* Use elapsedTime property to get response time

* Fix lint issues

* Add fastify to dev dependencies of cli package

* Add fastify to dev dependencies of light-client package
  • Loading branch information
nflaig committed Apr 4, 2024
1 parent fd6691d commit 2ee8ac6
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 86 deletions.
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@types/eventsource": "^1.1.11",
"@types/qs": "^6.9.7",
"ajv": "^8.12.0",
"fastify": "^4.19.0"
"fastify": "^4.26.2"
},
"keywords": [
"ethereum",
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"datastore-core": "^9.1.1",
"datastore-level": "^10.1.1",
"deepmerge": "^4.3.1",
"fastify": "^4.19.0",
"fastify": "^4.26.2",
"interface-datastore": "^8.2.7",
"it-all": "^3.0.4",
"it-pipe": "^3.0.1",
Expand Down
21 changes: 10 additions & 11 deletions packages/beacon-node/src/api/rest/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {parse as parseQueryString} from "qs";
import {FastifyInstance, fastify} from "fastify";
import {fastifyCors} from "@fastify/cors";
import bearerAuthPlugin from "@fastify/bearer-auth";
import {RouteConfig} from "@lodestar/api/beacon/server";
import {ErrorAborted, Gauge, Histogram, Logger} from "@lodestar/utils";
import {isLocalhostIP} from "../../util/ip.js";
import {ApiError, NodeIsSyncing} from "../impl/errors.js";
Expand Down Expand Up @@ -84,34 +83,34 @@ export class RestApiServer {
// Log all incoming request to debug (before parsing). TODO: Should we hook latter in the lifecycle? https://www.fastify.io/docs/latest/Lifecycle/
// Note: Must be an async method so fastify can continue the release lifecycle. Otherwise we must call done() or the request stalls
server.addHook("onRequest", async (req, _res) => {
const {operationId} = req.routeConfig as RouteConfig;
this.logger.debug(`Req ${req.id as string} ${req.ip} ${operationId}`);
const operationId = req.routeSchema.operationId as string;
this.logger.debug(`Req ${req.id} ${req.ip} ${operationId}`);
metrics?.requests.inc({operationId});
});

server.addHook("preHandler", async (req, _res) => {
const {operationId} = req.routeConfig as RouteConfig;
this.logger.debug(`Exec ${req.id as string} ${req.ip} ${operationId}`);
const operationId = req.routeSchema.operationId as string;
this.logger.debug(`Exec ${req.id} ${req.ip} ${operationId}`);
});

// Log after response
server.addHook("onResponse", async (req, res) => {
const {operationId} = req.routeConfig as RouteConfig;
this.logger.debug(`Res ${req.id as string} ${operationId} - ${res.raw.statusCode}`);
metrics?.responseTime.observe({operationId}, res.getResponseTime() / 1000);
const operationId = req.routeSchema.operationId as string;
this.logger.debug(`Res ${req.id} ${operationId} - ${res.raw.statusCode}`);
metrics?.responseTime.observe({operationId}, res.elapsedTime / 1000);
});

server.addHook("onError", async (req, _res, err) => {
// Don't log ErrorAborted errors, they happen on node shutdown and are not useful
// Don't log NodeISSyncing errors, they happen very frequently while syncing and the validator polls duties
if (err instanceof ErrorAborted || err instanceof NodeIsSyncing) return;

const {operationId} = req.routeConfig as RouteConfig;
const operationId = req.routeSchema.operationId as string;

if (err instanceof ApiError) {
this.logger.warn(`Req ${req.id as string} ${operationId} failed`, {reason: err.message});
this.logger.warn(`Req ${req.id} ${operationId} failed`, {reason: err.message});
} else {
this.logger.error(`Req ${req.id as string} ${operationId} error`, {}, err);
this.logger.error(`Req ${req.id} ${operationId} error`, {}, err);
}
metrics?.errors.inc({operationId});
});
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"@types/got": "^9.6.12",
"@types/inquirer": "^9.0.3",
"@types/proper-lockfile": "^4.1.4",
"@types/yargs": "^17.0.24"
"@types/yargs": "^17.0.24",
"fastify": "^4.26.2"
}
}
6 changes: 3 additions & 3 deletions packages/cli/test/utils/simulation/ExternalSignerServer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {fastify} from "fastify";
import {fromHexString} from "@chainsafe/ssz";
import type {SecretKey} from "@chainsafe/bls/types";
import {fromHexString} from "@chainsafe/ssz";
import {fastify, FastifyInstance} from "fastify";
import {EXTERNAL_SIGNER_BASE_PORT} from "./constants.js";

/* eslint-disable no-console */
Expand All @@ -11,7 +11,7 @@ export class ExternalSignerServer {
readonly address: string = "127.0.0.1";
readonly port: number;

private server: ReturnType<typeof fastify>;
private server: FastifyInstance;
private secretKeyMap = new Map<string, SecretKey>();

constructor(secretKeys: SecretKey[]) {
Expand Down
1 change: 1 addition & 0 deletions packages/light-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"devDependencies": {
"@chainsafe/as-sha256": "^0.4.1",
"@types/qs": "^6.9.7",
"fastify": "^4.26.2",
"qs": "^6.11.1",
"uint8arrays": "^5.0.1"
},
Expand Down
Loading

0 comments on commit 2ee8ac6

Please sign in to comment.