Skip to content

Commit

Permalink
Deprecate BeaconBlocksByRange.step (#4499)
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion authored Sep 1, 2022
1 parent 9194e21 commit aa97981
Showing 1 changed file with 8 additions and 19 deletions.
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

0 comments on commit aa97981

Please sign in to comment.