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 reorg depth count #5160

Merged
merged 3 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions packages/fork-choice/src/forkChoice/forkChoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ export class ForkChoice implements IForkChoice {
return blocksAtSlot;
}

/** Returns the distance of common ancestor of nodes to newNode. Returns null if newNode is descendant of prevNode */
/** Returns the distance of common ancestor of nodes to the max of the newNode and the prevNode. Returns null if newNode is descendant of prevNode */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this null comment is stale. Can you just remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 781 suggests the noCommonAncestor error code is equivalent to a null response which is why I left it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that comment was from before we returned a AncestorResult.

wemeetagain marked this conversation as resolved.
Show resolved Hide resolved
getCommonAncestorDepth(prevBlock: ProtoBlock, newBlock: ProtoBlock): AncestorResult {
const prevNode = this.protoArray.getNode(prevBlock.blockRoot);
const newNode = this.protoArray.getNode(newBlock.blockRoot);
Expand All @@ -786,7 +786,7 @@ export class ForkChoice implements IForkChoice {
return {code: AncestorStatus.Descendant};
}

return {code: AncestorStatus.CommonAncestor, depth: newNode.slot - commonAncestor.slot};
return {code: AncestorStatus.CommonAncestor, depth: Math.max(newNode.slot, prevNode.slot) - commonAncestor.slot};
maschad marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/fork-choice/src/forkChoice/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export interface IForkChoice {
forwardIterateDescendants(blockRoot: RootHex): IterableIterator<ProtoBlock>;
getBlockSummariesByParentRoot(parentRoot: RootHex): ProtoBlock[];
getBlockSummariesAtSlot(slot: Slot): ProtoBlock[];
/** Returns the distance of common ancestor of nodes to newNode. Returns null if newNode is descendant of prevNode */
/** Returns the distance of common ancestor of nodes to the max of the newNode and the prevNode. Returns null if newNode is descendant of prevNode */
wemeetagain marked this conversation as resolved.
Show resolved Hide resolved
getCommonAncestorDepth(prevBlock: ProtoBlock, newBlock: ProtoBlock): AncestorResult;
/**
* Optimistic sync validate till validated latest hash, invalidate any decendant branch if invalidated branch decendant provided
Expand Down