Skip to content

Commit

Permalink
Only check parent for maybeUpdateBestChildAndDescendant
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed May 30, 2023
1 parent 8490369 commit edb4145
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions packages/fork-choice/src/protoArray/protoArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,18 @@ export class ProtoArray {
bestDescendant: undefined,
};

let nodeIndex = this.nodes.length;

const nodeIndex = this.nodes.length;
this.indices.set(node.blockRoot, nodeIndex);
this.nodes.push(node);

let parentIndex = node.parent;
// If this node is valid, lets propagate the valid status up the chain
// and throw error if we counter invalid, as this breaks consensus
if (node.executionStatus === ExecutionStatus.Valid && parentIndex !== undefined) {
this.propagateValidExecutionStatusByIndex(parentIndex);
}
if (node.parent !== undefined) {
this.maybeUpdateBestChildAndDescendant(node.parent, nodeIndex, currentSlot);

let n: ProtoNode | undefined = node;
while (parentIndex !== undefined) {
this.maybeUpdateBestChildAndDescendant(parentIndex, nodeIndex, currentSlot);
nodeIndex = parentIndex;
n = this.getNodeByIndex(nodeIndex);
parentIndex = n?.parent;
// If this node is valid, lets propagate the valid status up the chain
// and throw error if we counter invalid, as this breaks consensus
if (node.executionStatus === ExecutionStatus.Valid) {
this.propagateValidExecutionStatusByIndex(node.parent);
}
}
}

Expand Down

0 comments on commit edb4145

Please sign in to comment.