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

Deprecate BeaconBlocksByRange.step #4499

Merged
merged 1 commit into from
Sep 1, 2022
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,19 @@ export async function* onBeaconBlocksByRange(
throw new ResponseError(RespStatus.INVALID_REQUEST, "startSlot < genesis");
}

if (step > 1) {
// step > 1 is deprecated, see https://github.com/ethereum/consensus-specs/pull/2856
count = 1;
}

if (count > MAX_REQUEST_BLOCKS) {
count = MAX_REQUEST_BLOCKS;
}

const lt = startSlot + count * step;
let archivedBlocksStream: AsyncIterable<ReqRespBlockResponse>;
const lt = startSlot + count;

if (step > 1) {
const slots = [];
for (let slot = startSlot; slot < lt; slot += step) {
slots.push(slot);
}
archivedBlocksStream = getFinalizedBlocksAtSlots(slots, db);
} else {
// step < 1 was validated above
archivedBlocksStream = getFinalizedBlocksByRange(startSlot, lt, db);
}
// step < 1 was validated above
const archivedBlocksStream = getFinalizedBlocksByRange(startSlot, lt, db);

yield* injectRecentBlocks(archivedBlocksStream, chain, db, requestBody);
}
Expand Down Expand Up @@ -81,13 +77,6 @@ export async function* injectRecentBlocks(
}
}

async function* getFinalizedBlocksAtSlots(slots: Slot[], db: IBeaconDb): AsyncIterable<ReqRespBlockResponse> {
for (const slot of slots) {
const bytes = await db.blockArchive.getBinary(slot);
if (bytes !== null) yield {slot, bytes};
}
}

async function* getFinalizedBlocksByRange(gte: number, lt: number, db: IBeaconDb): AsyncIterable<ReqRespBlockResponse> {
const binaryEntriesStream = db.blockArchive.binaryEntriesStream({
gte,
Expand Down