bitcoin icon indicating copy to clipboard operation
bitcoin copied to clipboard

Make m_tip_block std::optional

Open Sjors opened this issue 1 year ago • 14 comments

Suggested in https://github.com/bitcoin/bitcoin/pull/31297#discussion_r1844244309

Sjors avatar Nov 19 '24 19:11 Sjors

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31325.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK tdb3, l0rinc, fjahr
Concept ACK BrandonOdiwuor
Stale ACK ryanofsky

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

DrahtBot avatar Nov 19 '24 19:11 DrahtBot

I dropped the use of has_value() https://github.com/bitcoin/bitcoin/pull/31325#discussion_r1851743969 as well as value() https://github.com/bitcoin/bitcoin/pull/31325#discussion_r1850680750. Except in the test, where throwing std::bad_optional_access is probably useful.

Added a comment: https://github.com/bitcoin/bitcoin/pull/31325/files#r1851747612

Dropped the word "kernel" and added a motivation to the commit message.

Sjors avatar Nov 21 '24 12:11 Sjors

ACK 2fff10a656edb8bec7d45433bf431fd233d0fd81

l0rinc avatar Nov 21 '24 12:11 l0rinc

Rebased (just in case) and shortened the comment: https://github.com/bitcoin/bitcoin/pull/31325#discussion_r1870138808

Sjors avatar Dec 06 '24 07:12 Sjors

ACK 5c48d098dc300ae47f2ffeb9305f58bd6352152d The only change was to the comment which I find less technical and more descriptive 👍

l0rinc avatar Dec 06 '24 12:12 l0rinc

ACK fe6487ca6ab005faab9f1d565740f2259c04cd16

l0rinc avatar Dec 06 '24 13:12 l0rinc

Not sure this is an improvement. Seems like a case of "two ways to be omitted" which has caused issues in the past.

luke-jr avatar Dec 09 '24 16:12 luke-jr

"two ways to be omitted"

If this change is merged, we should discourage the use of uint256::ZERO / uint256{}. But there are other places in the codebase that still use this pattern, which I didn't refactor here. I even found myself using it yesterday for an upcoming PR.

I pushed a commit that makes m_tip_block private, accessible through TipBlock(). I then added an Assert at the only place that sets it to ensure it's not ZERO.

Also modified the first commit to drop a redundant "for" from the m_tip_block comment.

Sjors avatar Dec 10 '24 03:12 Sjors

I switched from Assert to Assume.

Sjors avatar Dec 10 '24 10:12 Sjors

ACK fc0b5f3b77166aad9fb288b8eb9185bb2dc7496c

l0rinc avatar Dec 10 '24 11:12 l0rinc

Rebased after #31346.

Sjors avatar Dec 14 '24 04:12 Sjors

ACK 43f23cd29de13ea600bbe1172cf1ac0d535f66ee

l0rinc avatar Dec 15 '24 14:12 l0rinc

@maflcko thoughts, since you suggested it?

Sjors avatar Dec 16 '24 06:12 Sjors

I replaced the use of uint256{} with uint256::ZERO, since it makes the intention more clear. I also limited the not-ZERO check to just the setter and dropped the comment.

Also dropped the whitespace change in kernel_notifications.h in the first commit.

Sjors avatar Dec 17 '24 02:12 Sjors

re-ACK 81cea5d4ee0e226f7c7145072de85829f4166ec9

fjahr avatar Dec 19 '24 13:12 fjahr