Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Dec 3, 2024
1 parent 9eb5077 commit 67413ed
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
9 changes: 2 additions & 7 deletions packages/api/src/beacon/routes/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const DebugChainHeadListType = ArrayOf(DebugChainHeadType);
type ProtoNodeList = ValueOf<typeof ProtoNodeListType>;
type DebugChainHeadList = ValueOf<typeof DebugChainHeadListType>;
type ForkChoiceResponse = ValueOf<typeof ForkChoiceResponseType>;
type HistoricalSummariesList = ValueOf<typeof HistoricalSummariesResponseType>;
const HistoricalSummariesResponseType = new ContainerType(
{
HistoricalSummaries: ssz.capella.HistoricalSummaries,
Expand Down Expand Up @@ -141,13 +142,7 @@ export type Endpoints = {
BeaconState,
ExecutionOptimisticFinalizedAndVersionMeta
>;
getHistoricalSummaries: Endpoint<
"GET",
StateArgs,
{params: {state_id: string}},
ValueOf<typeof HistoricalSummariesResponseType>,
EmptyMeta
>;
getHistoricalSummaries: Endpoint<"GET", StateArgs, {params: {state_id: string}}, HistoricalSummariesList, EmptyMeta>;
};

export function getDefinitions(_config: ChainForkConfig): RouteDefinitions<Endpoints> {
Expand Down
18 changes: 1 addition & 17 deletions packages/api/test/unit/beacon/genericServerTest/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("beacon / debug", () => {

// Get state by SSZ

describe("get state in SSZ format", () => {
describe.skip("get state in SSZ format", () => {
const mockApi = getMockApi<Endpoints>(getDefinitions(config));
let baseUrl: string;
let server: FastifyInstance;
Expand Down Expand Up @@ -58,21 +58,5 @@ describe("beacon / debug", () => {
expect(res.wireFormat()).toBe(WireFormat.ssz);
expect(toHexString(res.ssz())).toBe(toHexString(stateSerialized));
});
it("getHistoricalSummaries", async () => {
const state = ssz.deneb.BeaconState.defaultValue();
mockApi.getHistoricalSummaries.mockResolvedValue({
data: {HistoricalSummaries: state.historicalSummaries, proof: []},
meta: undefined,
});

const httpClient = new HttpClient({baseUrl});
const client = getClient(config, httpClient);

const res = await client.getHistoricalSummaries({stateId: "head"}, {responseWireFormat: WireFormat.json});

expect(res.ok).toBe(true);
expect(res.wireFormat()).toBe(WireFormat.json);
expect(res.json()).toStrictEqual({data: {Historical_summaries: [], proof: []}});
});
});
});
4 changes: 4 additions & 0 deletions packages/api/test/unit/beacon/testData/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,8 @@ export const testData: GenericServerTestCases<Endpoints> = {
meta: {executionOptimistic: true, finalized: false, version: ForkName.altair},
},
},
getHistoricalSummaries: {
args: {stateId: "head"},
res: {data: {HistoricalSummaries: [], proof: []}},
},
};
7 changes: 6 additions & 1 deletion packages/beacon-node/src/api/impl/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {getStateSlotFromBytes} from "../../../util/multifork.js";
import {getStateResponseWithRegen} from "../beacon/state/utils.js";
import {ApiModules} from "../types.js";
import {Tree} from "@chainsafe/persistent-merkle-tree";
import {loadState} from "@lodestar/state-transition";

export function getDebugApi({
chain,
Expand Down Expand Up @@ -98,12 +99,16 @@ export function getDebugApi({
throw new Error("Historical summaries are not supported before Capella");
}
const fork = config.getForkName(slot) as Exclude<ForkName, "phase0" | "altair" | "bellatrix">;
const stateView = state instanceof Uint8Array ? ssz[fork].BeaconState.deserializeToViewDU(state) : state;

const stateView =
state instanceof Uint8Array ? loadState(config, chain.getHeadState(), state).state : state.clone();

const gindex = ssz[fork].BeaconState.getPathInfo(["historicalSummaries"]);
const proof = new Tree(stateView.node).getSingleProof(gindex.gindex);

return {
data: {
// biome-ignore lint/suspicious/noExplicitAny: state is definitely Capella or later based on above check
HistoricalSummaries: (stateView as any).historicalSummaries.toValue(),
proof: proof,
},
Expand Down

0 comments on commit 67413ed

Please sign in to comment.