-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Refactor ProcessNewBlock to reduce code duplication #21713
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
Conversation
3e24a66 to
89e5e5a
Compare
src/net_processing.cpp
Outdated
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.
Nit: you can turn pblock into a const reference argument (const std::shared_ptr<const CBlock>& pblock), which will avoid an atomic shared_ptr copy at runtime.
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. changed. If I may ask, why doesn't ProcessNewBlock() also do this?
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.
Probably just a typo
|
Looks obviously correct. utACK 89e5e5a67977588218c3c4309d9291b0cc5dd4ad |
src/net_processing.cpp
Outdated
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.
chainparams is not being used in the function body. m_chainparams is used however.
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.
curious... I wonder why the tests aren't failing then... I guess it inherits m_chainparams from the class, and therefore the parameter can be removed altogether from the function
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.
I wonder why the tests aren't failing then
We have no tests to detect unused parameters, IIRC
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.
I thought the compiler would at least give a warning - I've seen it warn about unused variables before, so I wonder why it doesn't do this for unused parameters too.
89e5e5a to
9a06535
Compare
| LOCK(cs_main); | ||
| mapBlockSource.erase(pblock->GetHash()); | ||
| } | ||
| ProcessBlock(pfrom, pblock, /*fForceProcessing=*/true); |
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.
Why not just nevermind.ProcessBlock(pfrom, pblock)?
promag
left a comment
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.
Code review ACK 9a06535.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
theStack
left a comment
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.
Code-review ACK 9a06535 🌴
|
ACK 9a06535 💻 Show signature and timestampSignature: Timestamp of file with hash |
|
Note that this PR changed the file permissions of |
jnewbery
left a comment
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.
Functionality looks correct. It would have been nice to follow the style guide for the new code.
|
|
||
| void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc) EXCLUSIVE_LOCKS_REQUIRED(peer.m_getdata_requests_mutex) LOCKS_EXCLUDED(::cs_main); | ||
|
|
||
| void ProcessBlock(CNode& pfrom, const std::shared_ptr<const CBlock>& pblock, bool fForceProcessing); |
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.
The project style is to not use hungarian notation, and use snake case for parameter/variable names:
| void ProcessBlock(CNode& pfrom, const std::shared_ptr<const CBlock>& pblock, bool fForceProcessing); | |
| void ProcessBlock(CNode& node, const std::shared_ptr<const CBlock>& block, bool force_processing); |
|
|
||
| void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc) EXCLUSIVE_LOCKS_REQUIRED(peer.m_getdata_requests_mutex) LOCKS_EXCLUDED(::cs_main); | ||
|
|
||
| void ProcessBlock(CNode& pfrom, const std::shared_ptr<const CBlock>& pblock, bool fForceProcessing); |
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.
New functions should have doxygen comments.
|
|
||
| void PeerManagerImpl::ProcessBlock(CNode& pfrom, const std::shared_ptr<const CBlock>& pblock, bool fForceProcessing) | ||
| { | ||
| bool fNewBlock = 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.
| bool fNewBlock = false; | |
| bool new_block{false}; |
9a06535 Refactor ProcessNewBlock to reduce code duplication (R E Broadley) Pull request description: There are probably a few issues with this code (maybe there's even a reason this code is duplicated as it currently is), so apologies in advance that I'm still a little (maybe very) bad with C++ ACKs for top commit: MarcoFalke: ACK 9a06535 💻 promag: Code review ACK 9a06535. theStack: Code-review ACK 9a06535 🌴 Tree-SHA512: f8634ffad4b2370204d1a0945db4e27248b9e579d9912784da432b8ee3303cae424fa9f7500000dcfb31e6d29d04a8f7d322d17a6fe3d4adaddd10c539458a8c
f2f2541 remove executable flag for src/net_processing.cpp (Sebastian Falbesoner) Pull request description: The file permissions for `src/net_processing.cpp` have been changed in #21713, as discovered by fanquake (bitcoin/bitcoin#21713 (comment)). This PR removes the executable flag again. ACKs for top commit: kiminuo: ACK f2f2541 :) jnewbery: ACK f2f2541 promag: ACK f2f2541. Tree-SHA512: 1d5a62afb1152029e69fccea2ae53dcb262a91724a5c03dfc4de8c409b280814d0c211c2f9a71f1a6e927f4ed571ba4ac311de9de8ebb797eaf1051674241bdb
f2f2541 remove executable flag for src/net_processing.cpp (Sebastian Falbesoner) Pull request description: The file permissions for `src/net_processing.cpp` have been changed in bitcoin#21713, as discovered by fanquake (bitcoin#21713 (comment)). This PR removes the executable flag again. ACKs for top commit: kiminuo: ACK f2f2541 :) jnewbery: ACK f2f2541 promag: ACK f2f2541. Tree-SHA512: 1d5a62afb1152029e69fccea2ae53dcb262a91724a5c03dfc4de8c409b280814d0c211c2f9a71f1a6e927f4ed571ba4ac311de9de8ebb797eaf1051674241bdb
e12f287 net: cleanup newly added PeerManagerImpl::ProcessNewBlock (fanquake) 610151f validation: change ProcessNewBlock() to take a CBlock reference (fanquake) Pull request description: Addresses some [post-merge comments](#21713 (review)) from #21713. Also makes `ChainstateManager::ProcessNewBlock` take a const reference argument, as it [was asked](#21713 (comment)) why it was not the case in that PR. ACKs for top commit: jnewbery: Code review ACK e12f287 MarcoFalke: review ACK e12f287 🚚 Tree-SHA512: 9c3e7353240c862d50bce2a0f58741c109dd628040b56ed46250103f8ebe9009238b131da710486791e28e3a83c985057b7be0a32aed1a929269b43097c7425b
…itcoin#21713 e12f287 net: cleanup newly added PeerManagerImpl::ProcessNewBlock (fanquake) 610151f validation: change ProcessNewBlock() to take a CBlock reference (fanquake) Pull request description: Addresses some [post-merge comments](bitcoin#21713 (review)) from bitcoin#21713. Also makes `ChainstateManager::ProcessNewBlock` take a const reference argument, as it [was asked](bitcoin#21713 (comment)) why it was not the case in that PR. ACKs for top commit: jnewbery: Code review ACK e12f287 MarcoFalke: review ACK e12f287 🚚 Tree-SHA512: 9c3e7353240c862d50bce2a0f58741c109dd628040b56ed46250103f8ebe9009238b131da710486791e28e3a83c985057b7be0a32aed1a929269b43097c7425b
There are probably a few issues with this code (maybe there's even a reason this code is duplicated as it currently is), so apologies in advance that I'm still a little (maybe very) bad with C++