From 041ac4124a3916f7836f47f0048eddd3a1f23429 Mon Sep 17 00:00:00 2001 From: harkamal Date: Sun, 30 Apr 2023 20:30:34 +0530 Subject: [PATCH 1/2] fix: Fix archiver's cleanup of non checkpoint roots --- packages/beacon-node/src/chain/archiver/archiveBlocks.ts | 9 ++++----- .../test/unit/chain/archive/nonCheckpoint.test.ts | 4 +++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/beacon-node/src/chain/archiver/archiveBlocks.ts b/packages/beacon-node/src/chain/archiver/archiveBlocks.ts index 7c56172e24d4..21097e6660f4 100644 --- a/packages/beacon-node/src/chain/archiver/archiveBlocks.ts +++ b/packages/beacon-node/src/chain/archiver/archiveBlocks.ts @@ -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(blocks: T[]): T[] { // Iterate from lowest child to highest ancestor @@ -223,9 +223,8 @@ export function getNonCheckpointBlocks(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, increasing slot + for (let i = 0; i < blocks.length; i++) { let isCheckpoint = false; const block = blocks[i]; const blockEpoch = computeEpochAtSlot(block.slot); diff --git a/packages/beacon-node/test/unit/chain/archive/nonCheckpoint.test.ts b/packages/beacon-node/test/unit/chain/archive/nonCheckpoint.test.ts index 1f00c2b9ed75..ccd615b2006b 100644 --- a/packages/beacon-node/test/unit/chain/archive/nonCheckpoint.test.ts +++ b/packages/beacon-node/test/unit/chain/archive/nonCheckpoint.test.ts @@ -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)); }); From 1736b3a5c5745048b16d49f0017d673cca34e2b1 Mon Sep 17 00:00:00 2001 From: harkamal Date: Sun, 30 Apr 2023 20:53:13 +0530 Subject: [PATCH 2/2] fix comment --- packages/beacon-node/src/chain/archiver/archiveBlocks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/beacon-node/src/chain/archiver/archiveBlocks.ts b/packages/beacon-node/src/chain/archiver/archiveBlocks.ts index 21097e6660f4..e7266a7db62b 100644 --- a/packages/beacon-node/src/chain/archiver/archiveBlocks.ts +++ b/packages/beacon-node/src/chain/archiver/archiveBlocks.ts @@ -223,7 +223,7 @@ export function getNonCheckpointBlocks(blocks: T[]): T[] // This function must return only blocks that are guaranteed to never become checkpoints. let epochPtrHasFirstSlot = false; - // blocks order: from child to ancestor, increasing slot + // blocks order: from child to ancestor, decreasing slot for (let i = 0; i < blocks.length; i++) { let isCheckpoint = false; const block = blocks[i];