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

IF: Unification: Implement get_best_qc in block_state #2076

Merged
merged 4 commits into from
Jan 16, 2024

Conversation

linh2931
Copy link
Member

@linh2931 linh2931 commented Jan 11, 2024

If pending_qc does not have a valid QC, return valid_qc. Otherwise, extract the valid QC from pending_qc. Compare that to valid_qc to determine which is better: Strong beats Weak. Break tie with valid_qc. Return the better one.

Resolved #2075

@linh2931 linh2931 requested review from greg7mdp and heifner January 11, 2024 21:08
@linh2931 linh2931 linked an issue Jan 11, 2024 that may be closed by this pull request
Comment on lines 112 to 113
return qc_data_t{ quorum_certificate{ block_number, valid_qc.value() },
qc_info_t{ block_number, valid_qc.value().is_strong() }};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return qc_data_t{ quorum_certificate{ block_number, valid_qc.value() },
qc_info_t{ block_number, valid_qc.value().is_strong() }};
return qc_data_t{ quorum_certificate{ block_number, *valid_qc },
qc_info_t{ block_number, valid_qc->is_strong() }};

Comment on lines 131 to 138
if( valid_qc.value().is_strong() && !valid_qc_from_pending.is_strong() ) {
valid_qc_is_better = true;
} else if( !valid_qc.value().is_strong() && valid_qc_from_pending.is_strong() ) {
valid_qc_is_better = false;
} else if( valid_qc.value().accumulated_weight() >= valid_qc_from_pending.accumulated_weight() ) {
valid_qc_is_better = true;
} else {
valid_qc_is_better = false;
Copy link
Contributor

@greg7mdp greg7mdp Jan 11, 2024

Choose a reason for hiding this comment

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

For modularity, I believe it would be better to have a comparison operator in valid_quorum_certificate, such as:

      bool operator<(const valid_quorum_certificate& o) const {
         if (is_strong() != o.is_strong())
            return o.is_strong();
         if (accumulated_weight() != o.accumulated_weight()) 
            return accumulated_weight() <  o.accumulated_weight();
         return false;
      }

and then get_best_qc can return std::max(*valid_qc, valid_qc_from_pending).

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

@linh2931 linh2931 requested a review from greg7mdp January 12, 2024 15:39
…ccumulated_weight from valid_quorum_certificate
@linh2931 linh2931 merged commit 51ef25d into hotstuff_integration Jan 16, 2024
26 checks passed
@linh2931 linh2931 deleted the get_best_qc branch January 16, 2024 23:31
@ericpassmore
Copy link
Contributor

Note:start
group: IF
category: INTERNALS
summary: Returns the most significant QC from the ancestors. Takes many factors into account when determining the QC to return.
Note: end

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.

IF: Unification: implement get_best_qc in block_state
5 participants