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

turbine::broadcast_stage: then_some/ok_or_else => if #1301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ilya-bobyr
Copy link

Problem

A few spots could be clarified.

Summary of Changes

if/else seems easier to follow, as it produces less nesting.

Assignment of self.chained_merkle_root into chained_merkle_root, that is then assigned back into self.chained_merkle_root is a no-op. While I can see how it is separating the computation of the chained_merkle_root for the current step from the update of the self, I think, overall, it is more confusing than helpful.

The Finish previous slot ... comment is actually part of a multi-paragraph sequence of steps, that document the whole process_receive_results(). Step number was accidentally removed in #1057.

@ilya-bobyr ilya-bobyr requested a review from behzadnouri May 11, 2024 04:46
@codecov-commenter
Copy link

codecov-commenter commented May 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.5%. Comparing base (af6930d) to head (9e25cbd).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##           master    #1301     +/-   ##
=========================================
- Coverage    81.6%    81.5%   -0.1%     
=========================================
  Files         867      867             
  Lines      368900   368901      +1     
=========================================
- Hits       301052   300999     -53     
- Misses      67848    67902     +54     

Comment on lines 247 to 249
self.slot = bank.slot();
self.parent = bank.parent_slot();
if self.slot != bank.parent_slot() {

Choose a reason for hiding this comment

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

This does not look right. This is effectively checking:

if bank.slot() != bank.parent_slot() {

which is not equivalent to the old code.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

Thank you for double-checking.
I moved the assignment into the "update state" block and missed the point that self.slot was updated %)

@ilya-bobyr ilya-bobyr force-pushed the pr/turbine-StandardBroadcastRun-use-if branch 2 times, most recently from e8630cd to de24b90 Compare May 13, 2024 22:04
`if/else` seems easier to follow, as it produces less nesting.

Assignment of `self.chained_merkle_root` into `chained_merkle_root`,
that is then assigned back into `self.chained_merkle_root` is a no-op.
While I can see how it is separating the computation of the
`chained_merkle_root` for the current step from the update of the
`self`, I think, overall, it is more confusing then helpful.

The `Finish previous slot ...` comment is actually part of a
multi-paragraph sequence of steps, that document the whole
`process_receive_results()`.  Step number was accidentally removed in
`anza-xyz#1057`:

    commit 6b45dc9
    Author: behzad nouri <[email protected]>
    Date:   Fri May 3 20:20:10 2024 +0000

        retains chained Merkle root across leader slots (anza-xyz#1057)
@ilya-bobyr ilya-bobyr force-pushed the pr/turbine-StandardBroadcastRun-use-if branch from de24b90 to 9e25cbd Compare May 14, 2024 03:03
@ilya-bobyr ilya-bobyr requested a review from behzadnouri May 15, 2024 00:27
)
})

if self.slot != bank.parent_slot() {

Choose a reason for hiding this comment

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

As mentioned on slack, I appreciate you looking into this code, and it is always good to have more eyes on the code and try to spot bugs or inefficiencies.

However this is only a "style" change and people's personal preference on what style is better can be different.
I personally prefer the old code because it avoids this if branch which changes state, whereas the old code uses an "expression". This type of state changing if branches tend to be a source of bugs and errors and I personally rather avoid them when possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants