@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
27 lines • 1.45 kB
JavaScript
import { MAX_REQUEST_LIGHT_CLIENT_UPDATES } from "@lodestar/params";
import { LightClientServerErrorCode, RespStatus, ResponseError, } from "@lodestar/reqresp";
import { computeEpochAtSlot } from "@lodestar/state-transition";
import { assertLightClientServer } from "../../../node/utils/lightclient.js";
import { ReqRespMethod, responseSszTypeByMethod } from "../types.js";
export async function* onLightClientUpdatesByRange(requestBody, chain) {
assertLightClientServer(chain.lightClientServer);
const count = Math.min(MAX_REQUEST_LIGHT_CLIENT_UPDATES, requestBody.count);
for (let period = requestBody.startPeriod; period < requestBody.startPeriod + count; period++) {
try {
const update = await chain.lightClientServer.getUpdate(period);
const boundary = chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(update.signatureSlot));
const type = responseSszTypeByMethod[ReqRespMethod.LightClientUpdatesByRange](boundary.fork, 0);
yield {
data: type.serialize(update),
boundary,
};
}
catch (e) {
if (e.type?.code === LightClientServerErrorCode.RESOURCE_UNAVAILABLE) {
throw new ResponseError(RespStatus.RESOURCE_UNAVAILABLE, e.message);
}
throw new ResponseError(RespStatus.SERVER_ERROR, e.message);
}
}
}
//# sourceMappingURL=lightClientUpdatesByRange.js.map