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: make qc_info in instant_finality_extension non-optional #2145

Merged
merged 18 commits into from
Jan 29, 2024

Conversation

greg7mdp
Copy link
Contributor

Resolves #2128.

@greg7mdp greg7mdp marked this pull request as draft January 26, 2024 17:00
@greg7mdp greg7mdp marked this pull request as ready for review January 26, 2024 17:36
@greg7mdp greg7mdp linked an issue Jan 26, 2024 that may be closed by this pull request
block_validate_exception,
"QC block number (${n1}) in block extension does not match last_qc_block_num (${n2}) in header extension. Block number: ${b}",
("n1", qc_proof.block_height)("n2", qc_claim.last_qc_block_num)("b", b->block_num()) );
EOS_ASSERT( qc_proof.block_num == qc_claim.last_qc_block_num, block_validate_exception,
Copy link
Member

Choose a reason for hiding this comment

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

The original way placing block_validate_exception in a separate line looks better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess it is a matter of preference, I personally prefer the code to me more compact if possible, but as you originally wrote this code I'll switch back to using an extra line.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, I personally prefer the more compact as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@linh2931 I'll defer to you, would you be OK with me switching back to the more compact form?

I agree that 4 lines is more legible, but basically all the EOS_ASSERT follow the same pattern of 4 arguments, and typically the name of the exception is not critical to understanding what the assert does, so I feel that having it more compact is beneficial, as it allows to see more of the code in one screen.

Copy link
Member

Choose a reason for hiding this comment

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

Originally I crammed all into one line. As Kevin pointed out, it did not look good. I think for shorter ones, a single line is better. But for longer ones, a separate lines are better. If we do separate lines, each argument should be on a separate line so it is easy to see.

Copy link
Member

Choose a reason for hiding this comment

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

I think line 1 (the condition) and line 3 (the description) are important and nice when they stand out on separate lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we do separate lines, each argument should be on a separate line so it is easy to see.

I don't agree that we sould constrain ourselves to either a single line, or as many lines as we have arguments. I feel that we should try to make the code as nice to read as possible.

Copy link
Member

Choose a reason for hiding this comment

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

That's why I said shorter ones single line, longer ones separate lines. Those are all personal preferences. I look at the code in different terminals. Separate ones do look better.

("b", block_num) );

EOS_ASSERT( !prev_header_ext, block_validate_exception,
"Block #${b} doesn't have a finality header extension even though its predecessor does. Block number: ${b}",
Copy link
Member

Choose a reason for hiding this comment

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

Block number: ${b} is redunant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixing.

block_validate_exception,
"A block must have QC claim if it provides QC block extension. Block number: ${b}",
("b", b->block_num()) );
assert(header_ext);
Copy link
Member

Choose a reason for hiding this comment

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

Why this assert? The function already returned if (!header_ext).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is just a way to document (in a way that is checked at run time) that at this point in the function, we have a header_ext. Same as later I have assert(header_ext && prev_header_ext);.
Yes it is true that you can deduct it from reading the previous code, but I think this makes it nicely explicit.

.clang-format Outdated Show resolved Hide resolved
@@ -2854,16 +2854,17 @@ struct controller_impl {

static std::optional<qc_data_t> extract_qc_data(const signed_block_ptr& b) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems we should name this validate_and_extract_qc_data as it is calling the validate_and_extract methods of extensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hum, I think it could be misleading, it does the generic extension validation, but not the actual qc_data validation implemented in verify_qc_claim.

@greg7mdp greg7mdp self-assigned this Jan 29, 2024
@greg7mdp greg7mdp added this to the Leap v6.0.0 Cusp milestone Jan 29, 2024
@ericpassmore
Copy link
Contributor

Note:start
group: IF
category: INTERNALS
summary: Leveraging information in previous claims, qc_info is always populated in the block header extension. Previously it was an optional field.
Note: end

@greg7mdp greg7mdp merged commit 0fb7f5d into hotstuff_integration Jan 29, 2024
26 checks passed
@greg7mdp greg7mdp deleted the gh_2028 branch January 29, 2024 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

IF: make qc_info in instant_finality_extension non-optional
5 participants