Skip to content

Commit de4c56e

Browse files
authored
Refactor get_ancestor in Gloas (#4802)
This PR improves the readability of the modified `get_ancestor` in Gloas. `get_ancestor` in Phase0 does only one job: find and return the root of a block that is `block.slot <= slot`. `get_ancestor` in Gloas is modified to do two jobs: 1) return `root` and `PAYLOAD_STATUS_PENDING` if the block with the given `root` has `block.slot <= slot`, otherwise 2) find and return the root of a block and its payload status that is `block.slot <= slot`. The first condition cannot be met during a recursion and hence it doesn't need to be part of it. Thus, I think using iteration here makes what this function does a bit clearer.
1 parent ef27ce4 commit de4c56e

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

specs/gloas/fork-choice.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,14 @@ def get_ancestor(store: Store, root: Root, slot: Slot) -> ForkChoiceNode:
244244
return ForkChoiceNode(root=root, payload_status=PAYLOAD_STATUS_PENDING)
245245

246246
parent = store.blocks[block.parent_root]
247-
if parent.slot > slot:
248-
return get_ancestor(store, block.parent_root, slot)
249-
else:
250-
return ForkChoiceNode(
251-
root=block.parent_root,
252-
payload_status=get_parent_payload_status(store, block),
253-
)
247+
while parent.slot > slot:
248+
block = parent
249+
parent = store.blocks[block.parent_root]
250+
251+
return ForkChoiceNode(
252+
root=block.parent_root,
253+
payload_status=get_parent_payload_status(store, block),
254+
)
254255
```
255256

256257
### Modified `get_checkpoint_block`

0 commit comments

Comments
 (0)