Skip to content

Commit

Permalink
feat: add new getHistoricalSummaries endpoint to debug namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Nov 26, 2024
1 parent b78cb92 commit b45bdd8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
17 changes: 17 additions & 0 deletions packages/api/src/beacon/routes/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ export type Endpoints = {
BeaconState,
ExecutionOptimisticFinalizedAndVersionMeta
>;
getHistoricalSummaries: Endpoint<
"GET",
EmptyArgs,
EmptyRequest,
ValueOf<typeof ssz.capella.HistoricalSummaries>,
EmptyMeta
>;
};

export function getDefinitions(_config: ChainForkConfig): RouteDefinitions<Endpoints> {
Expand Down Expand Up @@ -196,5 +203,15 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions<Endpo
timeoutMs: 5 * 60 * 1000,
},
},
getHistoricalSummaries: {
url: "/eth/v1/debug/historical_summaries",
method: "GET",
req: EmptyRequestCodec,
resp: {
data: ssz.capella.HistoricalSummaries,
meta: EmptyMetaCodec,
onlySupport: WireFormat.ssz,
},
},
};
}
16 changes: 15 additions & 1 deletion packages/beacon-node/src/api/impl/debug/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {routes} from "@lodestar/api";
import {ApplicationMethods} from "@lodestar/api/server";
import {ExecutionStatus} from "@lodestar/fork-choice";
import {ZERO_HASH_HEX} from "@lodestar/params";
import {ForkSeq, ZERO_HASH_HEX} from "@lodestar/params";
import {BeaconStateCapella} from "@lodestar/state-transition";
import {BeaconState} from "@lodestar/types";
import {isOptimisticBlock} from "../../../util/forkChoice.js";
import {getStateSlotFromBytes} from "../../../util/multifork.js";
Expand Down Expand Up @@ -85,5 +86,18 @@ export function getDebugApi({
},
};
},
async getHistoricalSummaries() {
const {state} = await getStateResponseWithRegen(chain, "head");
let slot: number;
if (state instanceof Uint8Array) {
slot = getStateSlotFromBytes(state);
} else {
slot = state.slot;
}
if (config.getForkSeq(slot) < ForkSeq.capella) {
throw new Error("Historical summaries are not supported before Capella");
}
return {data: (state as BeaconStateCapella).historicalSummaries.serialize()};
},
};
}
6 changes: 5 additions & 1 deletion packages/types/src/capella/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ export const HistoricalSummary = new ContainerType(
{typeName: "HistoricalSummary", jsonCase: "eth2"}
);

export const HistoricalSummaries = new ListCompositeType(HistoricalSummary, HISTORICAL_ROOTS_LIMIT, {
typeName: "HistoricalSummaries",
});

// we don't reuse bellatrix.BeaconState fields since we need to replace some keys
// and we cannot keep order doing that
export const BeaconState = new ContainerType(
Expand Down Expand Up @@ -168,7 +172,7 @@ export const BeaconState = new ContainerType(
nextWithdrawalIndex: WithdrawalIndex, // [New in Capella]
nextWithdrawalValidatorIndex: ValidatorIndex, // [New in Capella]
// Deep history valid from Capella onwards
historicalSummaries: new ListCompositeType(HistoricalSummary, HISTORICAL_ROOTS_LIMIT), // [New in Capella]
historicalSummaries: HistoricalSummaries, // [New in Capella]
},
{typeName: "BeaconState", jsonCase: "eth2"}
);
Expand Down

0 comments on commit b45bdd8

Please sign in to comment.