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

Add missing getSyncChainsDebugState rest route #2481

Merged
merged 3 commits into from
May 4, 2021
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/cli/src/options/beaconNodeOptions/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const options: ICliCommandOptions<IApiArgs> = {
description: "Pick namespaces to expose for HTTP API",
defaultDescription: JSON.stringify(defaultOptions.api.rest.api),
group: "api",
// Parse ["debug,lodestar"] to ["debug", "lodestar"]
coerce: (namespaces: string[]): string[] => namespaces.map((val) => val.split(",")).flat(1),
},

"api.rest.cors": {
Expand Down
63 changes: 63 additions & 0 deletions packages/cli/test/e2e/cmds/init.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import fs from "fs";
import {expect} from "chai";
import rimraf from "rimraf";
import {IBeaconNodeOptions} from "@chainsafe/lodestar";
import {ReturnType as InitReturnType} from "../../../src/cmds/init";
import {getBeaconPaths} from "../../../src/cmds/beacon/paths";
import {depositContractDeployBlock} from "../../../src/networks/pyrmont";
import {testFilesDir} from "../../utils";
import {getLodestarCliTestRunner} from "../commandRunner";
import {ApiNamespace} from "@chainsafe/lodestar/lib/api";

describe("cmds / init", function () {
const lodestar = getLodestarCliTestRunner();
Expand All @@ -14,6 +16,10 @@ describe("cmds / init", function () {
const networkName = "pyrmont";
const beaconPaths = getBeaconPaths({rootDir});

afterEach(() => {
rimraf.sync(rootDir);
});

it("should init beacon configuration with --network option", async function () {
await lodestar<InitReturnType>([
//
Expand All @@ -32,4 +38,61 @@ describe("cmds / init", function () {
"Wrong depositContractDeployBlock for --network pyrmont setting"
);
});

it("should parse --api.rest.api options as array", async function () {
await lodestar<InitReturnType>([
//
"init",
`--api.rest.api ${ApiNamespace.DEBUG} --api.rest.api ${ApiNamespace.LODESTAR}`,
`--rootDir ${rootDir}`,
]);

expect(fs.existsSync(beaconPaths.configFile), `Must write config file to ${beaconPaths.configFile}`).to.be.true;
const beaconConfig: IBeaconNodeOptions = JSON.parse(
fs.readFileSync(beaconPaths.configFile, "utf8")
) as IBeaconNodeOptions;

expect(beaconConfig.api.rest.api).to.deep.equal(
[ApiNamespace.DEBUG, ApiNamespace.LODESTAR],
"Wrong beaconConfig.api.rest.api"
);
});

it("should parse --api.rest.api options as array shortform", async function () {
await lodestar<InitReturnType>([
//
"init",
`--api.rest.api ${ApiNamespace.DEBUG} ${ApiNamespace.LODESTAR}`,
`--rootDir ${rootDir}`,
]);

expect(fs.existsSync(beaconPaths.configFile), `Must write config file to ${beaconPaths.configFile}`).to.be.true;
const beaconConfig: IBeaconNodeOptions = JSON.parse(
fs.readFileSync(beaconPaths.configFile, "utf8")
) as IBeaconNodeOptions;

expect(beaconConfig.api.rest.api).to.deep.equal(
[ApiNamespace.DEBUG, ApiNamespace.LODESTAR],
"Wrong beaconConfig.api.rest.api"
);
});

it("should parse --api.rest.api options as array CSV", async function () {
await lodestar<InitReturnType>([
//
"init",
`--api.rest.api=${ApiNamespace.DEBUG},${ApiNamespace.LODESTAR}`,
`--rootDir ${rootDir}`,
]);

expect(fs.existsSync(beaconPaths.configFile), `Must write config file to ${beaconPaths.configFile}`).to.be.true;
const beaconConfig: IBeaconNodeOptions = JSON.parse(
fs.readFileSync(beaconPaths.configFile, "utf8")
) as IBeaconNodeOptions;

expect(beaconConfig.api.rest.api).to.deep.equal(
[ApiNamespace.DEBUG, ApiNamespace.LODESTAR],
"Wrong beaconConfig.api.rest.api"
);
});
});
2 changes: 1 addition & 1 deletion packages/lodestar/src/api/rest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class RestApi {
if (_opts.enabled) {
try {
const address = await api.server.listen(_opts.port, _opts.host);
logger.info("Started rest api server", {address});
logger.info("Started rest api server", {address, namespaces: _opts.api});
} catch (e) {
logger.error("Failed to start rest api server", {host: _opts.host, port: _opts.port}, e);
throw e;
Expand Down
17 changes: 16 additions & 1 deletion packages/lodestar/src/api/rest/lodestar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,19 @@ export const createProof: ApiController<{paths: (string | number)[][]}, {stateId
},
};

export const lodestarRoutes = [getWtfNode, getLatestWeakSubjectivityCheckpointEpoch, createProof];
export const getSyncChainsDebugState: ApiController<{paths: (string | number)[][]}, {stateId: string}> = {
url: "/sync-chains-debug-state",
method: "GET",
id: "getSyncChainsDebugState",

handler: async function () {
return this.api.lodestar.getSyncChainsDebugState();
},
};

export const lodestarRoutes = [
getWtfNode,
getLatestWeakSubjectivityCheckpointEpoch,
createProof,
getSyncChainsDebugState,
];