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

fix: fix archiver's cleanup of non checkpoint roots #5439

Merged
merged 2 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions packages/beacon-node/src/chain/archiver/archiveBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ export function getParentRootFromSignedBlock(bytes: Uint8Array): Uint8Array {

/**
*
* @param blocks sequence of linear blocks, from ancestor to child.
* In ProtoArray.getAllAncestorNodes child nodes are pushed to the returned array.
* @param blocks sequence of linear blocks, from child to ancestor.
* In ProtoArray.getAllAncestorNodes child nodes are pushed first to the returned array.
*/
export function getNonCheckpointBlocks<T extends {slot: Slot}>(blocks: T[]): T[] {
// Iterate from lowest child to highest ancestor
Expand All @@ -223,9 +223,8 @@ export function getNonCheckpointBlocks<T extends {slot: Slot}>(blocks: T[]): T[]
// This function must return only blocks that are guaranteed to never become checkpoints.
let epochPtrHasFirstSlot = false;

// blocks order: from ancestor to child, increasing slot
// Iterate in reverse: from child to ancestor, decreasing slot
for (let i = blocks.length - 1; i >= 0; i--) {
// blocks order: from child to ancestor, decreasing slot
for (let i = 0; i < blocks.length; i++) {
let isCheckpoint = false;
const block = blocks[i];
const blockEpoch = computeEpochAtSlot(block.slot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ describe("chain / archive / getNonCheckpointBlocks", () => {
const checkpointBlocksSet = new Set(checkpointBlocks);
const nonAncestorSlots = blocks.filter((slot) => !checkpointBlocksSet.has(slot));

const nonAncestorBlocks = getNonCheckpointBlocks(blocks.map(toProtoBlock));
// blocks are to be passed in reverse order as thats how they would be recieved in
// ProtoArray.getAllAncestorNodes
const nonAncestorBlocks = getNonCheckpointBlocks(blocks.reverse().map(toProtoBlock));

expect(sort(nonAncestorBlocks.map((block) => block.slot))).to.deep.equal(sort(nonAncestorSlots));
});
Expand Down