From d0be90012325021be31f9bfa3a0c62e47a9c3e48 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Mon, 14 Aug 2023 15:51:20 +0700 Subject: [PATCH] fix: handle no vote in prune() --- packages/fork-choice/src/forkChoice/forkChoice.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/fork-choice/src/forkChoice/forkChoice.ts b/packages/fork-choice/src/forkChoice/forkChoice.ts index 62a8af368b62..6dda2c639df2 100644 --- a/packages/fork-choice/src/forkChoice/forkChoice.ts +++ b/packages/fork-choice/src/forkChoice/forkChoice.ts @@ -672,6 +672,11 @@ export class ForkChoice implements IForkChoice { const prunedNodes = this.protoArray.maybePrune(finalizedRoot); const prunedCount = prunedNodes.length; for (const vote of this.votes) { + // validator has never voted + if (vote === undefined) { + continue; + } + if (vote.currentIndex !== null) { if (vote.currentIndex >= prunedCount) { vote.currentIndex -= prunedCount; @@ -680,6 +685,7 @@ export class ForkChoice implements IForkChoice { vote.currentIndex = null; } } + if (vote.nextIndex !== null) { if (vote.nextIndex >= prunedCount) { vote.nextIndex -= prunedCount;