Skip to content

Commit

Permalink
fix: Fix archiver's cleanup of non checkpoint roots (#5439)
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech authored May 1, 2023
1 parent 4981f5e commit 229b77b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
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

0 comments on commit 229b77b

Please sign in to comment.