Remove impossible branch in forkchoice#4892
Conversation
Replace an impossible branch in forkchoice with an assert of this impossibility. The message's slot being >= than the block slot is asserted in `validate_on_attestation`.k
| @@ -290,8 +289,7 @@ def is_supporting_vote(store: Store, node: ForkChoiceNode, message: LatestMessag | |||
| if node.root == message.root: | |||
| if node.payload_status == PAYLOAD_STATUS_PENDING: | |||
| return True | |||
There was a problem hiding this comment.
Seems like the == case was/is not impossible.
To separate the two cases:
-
message.slot < block.slotwas impossible because ofconsensus-specs/specs/gloas/fork-choice.md
Line 562 in 7e33b9f
-
Returning false on
message.slot == block.slotwas a bug?
|
Like Kev said, the
With current code:
With this, in both cases we return
The first case is wrong, this vote should not support This would be correct: assert message.slot >= block.slot
if message.slot == block.slot:
return False |
|
Now I'm not sure if the PR is even worth merging. The assert was mostly to show that we can't really be dealing with attestations from the future. But the fact that we still need to deal with same slot attestations and return a consistent value on both branches for empty and full, perhaps as it's currently implemented ends up being more readable than with this extra assert. |
|
This is not the first PR that tries to refactor this code to improve readability. (See this for another example.) I think we can improve it by separating
# `block` should be part of the chain that the `message` supports.
assert message.slot >= block.slot
if message.slot == block.slot:
# Same slot attestation cannot support `PAYLOAD_STATUS_FULL` or `PAYLOAD_STATUS_EMPTY`.
return False
if message.slot < block.slot:
# `block` should be part of the chain that the `message` supports.
return False
if message.slot == block.slot:
# Same slot attestation cannot support `PAYLOAD_STATUS_FULL` or `PAYLOAD_STATUS_EMPTY`.
return False Comments are auxiliary so we can remove it. |
Replace an impossible branch in forkchoice with an assert of this impossibility.
The message's slot being >= than the block slot is asserted in
validate_on_attestation.k