-
Notifications
You must be signed in to change notification settings - Fork 73
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
Conversation
libraries/chain/block_state.cpp
Outdated
return qc_data_t{ quorum_certificate{ block_number, valid_qc.value() }, | ||
qc_info_t{ block_number, valid_qc.value().is_strong() }}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() }}; |
libraries/chain/block_state.cpp
Outdated
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; |
There was a problem hiding this comment.
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)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
…ccumulated_weight from valid_quorum_certificate
Note:start |
If
pending_qc
does not have a valid QC, return valid_qc. Otherwise, extract the valid QC frompending_qc
. Compare that tovalid_qc
to determine which is better: Strong beats Weak. Break tie withvalid_qc
. Return the better one.Resolved #2075