Skip to content

Commit

Permalink
Add dump state cache routes (#2964)
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion authored Aug 16, 2021
1 parent 80c248b commit c664482
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/api/src/routes/lodestar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export type BlockProcessorQueueItem = {
addedTimeMs: number;
};

export type StateCacheItem = {
slot: Slot;
root: Uint8Array;
};

export type Api = {
/** TODO: description */
getWtfNode(): Promise<{data: string}>;
Expand All @@ -60,6 +65,10 @@ export type Api = {
getRegenQueueItems(): Promise<RegenQueueItem[]>;
/** Dump all items in the block processor queue */
getBlockProcessorQueueItems(): Promise<BlockProcessorQueueItem[]>;
/** Dump a summary of the states in the StateContextCache */
getStateCacheItems(): Promise<StateCacheItem[]>;
/** Dump a summary of the states in the CheckpointStateCache */
getCheckpointStateCacheItems(): Promise<StateCacheItem[]>;
};

/**
Expand All @@ -73,6 +82,8 @@ export const routesData: RoutesData<Api> = {
getGossipQueueItems: {url: "/eth/v1/lodestar/gossip-queue-items/:gossipType", method: "GET"},
getRegenQueueItems: {url: "/eth/v1/lodestar/regen-queue-items/", method: "GET"},
getBlockProcessorQueueItems: {url: "/eth/v1/lodestar/block-processor-queue-items/", method: "GET"},
getStateCacheItems: {url: "/eth/v1/lodestar/state-cache-items/", method: "GET"},
getCheckpointStateCacheItems: {url: "/eth/v1/lodestar/checkpoint-state-cache-items/", method: "GET"},
};

export type ReqTypes = {
Expand All @@ -83,6 +94,8 @@ export type ReqTypes = {
getGossipQueueItems: {params: {gossipType: string}};
getRegenQueueItems: ReqEmpty;
getBlockProcessorQueueItems: ReqEmpty;
getStateCacheItems: ReqEmpty;
getCheckpointStateCacheItems: ReqEmpty;
};

export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
Expand All @@ -102,6 +115,8 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
},
getRegenQueueItems: reqEmpty,
getBlockProcessorQueueItems: reqEmpty,
getStateCacheItems: reqEmpty,
getCheckpointStateCacheItems: reqEmpty,
};
}

Expand All @@ -117,6 +132,13 @@ export function getReturnTypes(): ReturnTypes<Api> {
},
});

const StateCacheItem = new ContainerType<StateCacheItem>({
fields: {
slot: ssz.Slot,
root: ssz.Root,
},
});

return {
getWtfNode: sameType(),
writeHeapdump: sameType(),
Expand All @@ -125,5 +147,7 @@ export function getReturnTypes(): ReturnTypes<Api> {
getGossipQueueItems: ArrayOf(GossipQueueItem),
getRegenQueueItems: jsonType(),
getBlockProcessorQueueItems: jsonType(),
getStateCacheItems: ArrayOf(StateCacheItem),
getCheckpointStateCacheItems: ArrayOf(StateCacheItem),
};
}
16 changes: 16 additions & 0 deletions packages/lodestar/src/api/impl/lodestar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ export function getLodestarApi({
};
});
},

async getStateCacheItems() {
const states = (chain as BeaconChain)["stateCache"]["cache"].values();
return Array.from(states).map((state) => ({
slot: state.slot,
root: state.hashTreeRoot(),
}));
},

async getCheckpointStateCacheItems() {
const states = (chain as BeaconChain)["checkpointStateCache"]["cache"].values();
return Array.from(states).map((state) => ({
slot: state.slot,
root: state.hashTreeRoot(),
}));
},
};
}

Expand Down

0 comments on commit c664482

Please sign in to comment.