Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize fastify bodyLimit #4541

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/beacon-node/src/api/rest/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type RestApiServerOpts = {
cors?: string;
address?: string;
bearerToken?: string;
bodyLimit?: number;
};

export type RestApiServerModules = {
Expand Down Expand Up @@ -42,6 +43,7 @@ export class RestApiServer {
logger: false,
ajv: {customOptions: {coerceTypes: "array"}},
querystringParser: querystring.parse,
bodyLimit: opts.bodyLimit,
});

this.activeSockets = new HttpActiveSocketsTracker(server.server, metrics);
Expand Down
9 changes: 4 additions & 5 deletions packages/beacon-node/src/api/rest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ import {registerRoutes} from "@lodestar/api/beacon/server";
import {ErrorAborted, ILogger} from "@lodestar/utils";
import {IChainForkConfig} from "@lodestar/config";
import {NodeIsSyncing} from "../impl/errors.js";
import {RestApiServer, RestApiServerModules, RestApiServerMetrics} from "./base.js";
import {RestApiServer, RestApiServerModules, RestApiServerMetrics, RestApiServerOpts} from "./base.js";
export {allNamespaces} from "@lodestar/api";

export type BeaconRestApiServerOpts = {
export type BeaconRestApiServerOpts = Omit<RestApiServerOpts, "bearerToken"> & {
enabled: boolean;
api: (keyof Api)[];
port: number;
cors?: string;
address?: string;
};

export const beaconRestApiServerOpts: BeaconRestApiServerOpts = {
Expand All @@ -21,6 +18,8 @@ export const beaconRestApiServerOpts: BeaconRestApiServerOpts = {
address: "127.0.0.1",
port: 9596,
cors: "*",
// beacon -> validator API is trusted, and for large amounts of keys the payload is multi-MB
bodyLimit: 10 * 1024 * 1024, // 10MB
};

export type BeaconRestApiServerModules = RestApiServerModules & {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/cmds/validator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export async function validatorHandler(args: IValidatorCliArgs & IGlobalArgs): P
port: args["keymanager.port"],
cors: args["keymanager.cors"],
isAuthEnabled: args["keymanager.authEnabled"],
bodyLimit: args["keymanager.bodyLimit"],
tokenDir: dbPath,
},
{config, logger, api: keymanagerApi, metrics: metrics ? metrics.keymanagerApiRest : null}
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/cmds/validator/keymanager/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const keymanagerRestApiServerOptsDefault: KeymanagerRestApiServerOpts = {
port: 5062,
cors: "*",
isAuthEnabled: true,
// Slashing protection DB has been reported to be 3MB https://github.com/ChainSafe/lodestar/issues/4530
bodyLimit: 20 * 1024 * 1024, // 20MB
};

export type KeymanagerRestApiServerModules = RestApiServerModules & {
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/cmds/validator/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type KeymanagerArgs = {
"keymanager.port"?: number;
"keymanager.address"?: string;
"keymanager.cors"?: string;
"keymanager.bodyLimit"?: number;
};

export const keymanagerOptions: ICliCommandOptions<KeymanagerArgs> = {
Expand Down Expand Up @@ -89,6 +90,11 @@ export const keymanagerOptions: ICliCommandOptions<KeymanagerArgs> = {
defaultDescription: keymanagerRestApiServerOptsDefault.cors,
group: "keymanager",
},
"keymanager.bodyLimit": {
hidden: true,
type: "number",
description: "Defines the maximum payload, in bytes, the server is allowed to accept",
},
};

export const validatorOptions: ICliCommandOptions<IValidatorCliArgs> = {
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/src/options/beaconNodeOptions/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface IApiArgs {
rest: boolean;
"rest.address": string;
"rest.port": number;
"rest.bodyLimit": number;
}

export function parseArgs(args: IApiArgs): IBeaconNodeOptions["api"] {
Expand All @@ -21,6 +22,7 @@ export function parseArgs(args: IApiArgs): IBeaconNodeOptions["api"] {
enabled: args["rest"],
address: args["rest.address"],
port: args["rest.port"],
bodyLimit: args["rest.bodyLimit"],
},
};
}
Expand Down Expand Up @@ -75,4 +77,9 @@ export const options: ICliCommandOptions<IApiArgs> = {
defaultDescription: String(defaultOptions.api.rest.port),
group: "api",
},
"rest.bodyLimit": {
hidden: true,
type: "number",
description: "Defines the maximum payload, in bytes, the server is allowed to accept",
},
};
2 changes: 2 additions & 0 deletions packages/cli/test/unit/options/beaconNodeOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe("options / beaconNodeOptions", () => {
rest: true,
"rest.address": "127.0.0.1",
"rest.port": 7654,
"rest.bodyLimit": 30e6,

"chain.blsVerifyAllMultiThread": true,
"chain.blsVerifyAllMainThread": true,
Expand Down Expand Up @@ -82,6 +83,7 @@ describe("options / beaconNodeOptions", () => {
enabled: true,
address: "127.0.0.1",
port: 7654,
bodyLimit: 30e6,
},
},
chain: {
Expand Down