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

feat: add debug_getHistoricalSummaries endpoint #7245

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
nflaig marked this conversation as resolved.
Show resolved Hide resolved
method: "GET",
req: EmptyRequestCodec,
resp: {
data: ssz.capella.HistoricalSummaries,
meta: EmptyMetaCodec,
onlySupport: WireFormat.ssz,
nflaig marked this conversation as resolved.
Show resolved Hide resolved
},
},
};
}
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");
nflaig marked this conversation as resolved.
Show resolved Hide resolved
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
Loading