-
-
Notifications
You must be signed in to change notification settings - Fork 291
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
chore: typesafe options and cli args #4576
Conversation
Performance Report✔️ no performance regression detected Full benchmark results
|
Anyone understands what is this error?
The file referenced import { BeaconRestApiServerOpts } from "./rest/index.js";
export interface IApiOptions {
maxGindicesInProof?: number;
rest?: BeaconRestApiServerOpts & {
enabled?: boolean;
};
version?: string;
}
export declare const defaultApiOptions: {
maxGindicesInProof: number;
rest: {
enabled: boolean;
port: number;
address: string;
bodyLimit: number;
cors: string;
api: (keyof import("@lodestar/api/lib").Api)[];
};
}; and |
3443b1f
to
e9dfb46
Compare
packages/cli/src/util/command.ts
Outdated
@@ -1,6 +1,13 @@ | |||
import {Options, Argv} from "yargs"; | |||
|
|||
export type ICliCommandOptions<OwnArgs> = Required<{[key in keyof OwnArgs]: Options}>; | |||
export type ICliCommandOptions<OwnArgs> = Required< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is some nifty typescript! ❤️
const address = node.opts.api.rest.address || "localhost"; | ||
const port = node.opts.api.rest.port || 19596; | ||
const address = node.opts.api?.rest?.address ?? "localhost"; | ||
const port = node.opts.api?.rest?.port ?? 19596; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the beacon node api was being hosted at 19596
earlier
{ | ||
db: {name: tmpDir.name}, | ||
eth1: {enabled: false}, | ||
api: {rest: {api: ["beacon", "config", "events", "node", "validator"], port: 19596}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this endpoint has been removed, but validator still uses it
128fcfb
to
e3fc4a6
Compare
1e30ffc
to
8aaf742
Compare
Split original PR into two parts:
Previous branch with all parts before rebase: https://github.com/ChainSafe/lodestar/tree/dapplion/cli-typesafe-args_BACKUP |
8aaf742
to
ddea9f8
Compare
ddea9f8
to
4e3bf82
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved all conflicts and re-reviewed it. Updated PR description to not close #3758.
Thank you so much @nflaig ❤️ |
🎉 This PR is included in v1.10.0 🎉 |
Motivation
Our current approach to options and CLI arg processing is not typesafe.
Description
Problem: CLI args and options are defined such that it's not guaranteed for the arg to not be undefined.
This PR: modifies
ICliCommandOptions
to ensure that either a default is set or the option must be marked as optionalProblem: Programmatic use of BeaconNode class has bad DX since many non-essential options must be provided
This PR: Changed options definitions such that BeaconNode class can be instantiated without proving any option
Problem: BeaconNodeOptions current default merging strategy is not typesafe. Options that are typed as not optional may receive undefined
This PR: Remove option deepmerging at the CLI level, and let's each subclass to handle default option setting without nesting
Extra issues
Fix typo bad option merging, mixing retryAttempts and retryDelay
lodestar/packages/beacon-node/src/eth1/provider/jsonRpcHttpClient.ts
Line 129 in 34305f3
Set maxPeers to a value that greater than targetPeers if only the latter is set
Closes #4577