Skip to content

Conversation

@rebroad
Copy link
Contributor

@rebroad rebroad commented Apr 16, 2021

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++

@rebroad rebroad force-pushed the RefactorProcessNewBlock branch from 3e24a66 to 89e5e5a Compare April 16, 2021 23:49
@DrahtBot DrahtBot added the P2P label Apr 17, 2021
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

Probably just a typo

@sipa
Copy link
Member

sipa commented Apr 17, 2021

Looks obviously correct. utACK 89e5e5a67977588218c3c4309d9291b0cc5dd4ad

Copy link
Contributor

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.

Copy link
Contributor Author

@rebroad rebroad Apr 17, 2021

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

Copy link
Member

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

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 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.

@rebroad rebroad force-pushed the RefactorProcessNewBlock branch from 89e5e5a to 9a06535 Compare April 17, 2021 08:55
LOCK(cs_main);
mapBlockSource.erase(pblock->GetHash());
}
ProcessBlock(pfrom, pblock, /*fForceProcessing=*/true);
Copy link
Contributor

@promag promag Apr 17, 2021

Choose a reason for hiding this comment

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

Why not just ProcessBlock(pfrom, pblock)? nevermind.

Copy link
Contributor

@promag promag left a 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.

@DrahtBot
Copy link
Contributor

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

Conflicts

Reviewers, 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.

Copy link
Contributor

@theStack theStack left a 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 🌴

@maflcko
Copy link
Member

maflcko commented Apr 19, 2021

ACK 9a06535 💻

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

ACK 9a0653553a0ec403b4e7c6713466e0c7fa10ec94 💻
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUiYnAv/Q8in67v6vQkKBao81ya/jLVKWU/9q7/X3Hpcvsqy4eD0zr+dr/sVG2Yw
YBDoA2Owy9M2Y0e+gEBOzQmYfwgsMeeotFaRrZfFdUCrxQ9LYcZlU93FlNcdJEFk
NlbQwUlmuQ8PQ2ZuDoJQetkGvROh0SscH4F755GDxP3PUoG4FoE3rkJdvIucQi6M
LNH1kAcOQua8ftWJsrIN/tmnP4NFj5MM+baqwbd4rpPUE967/jjAPF1mrwOFJa/c
orRnm65vi9MIQsq1zCJDv0WOxFlTnMZCcNy743/oClnklAyxByLxaNOkpSSb1tz1
nZxiLw3ApRkIRxuZpgJUdCfNmLFbI3wfoU0xzL3bP84AGnUocyVyc2iFPRZcPLW8
5OXzzUowvVCIRa4Nn3bv7bHbwzhEJjKa0scm8+7wzX8VQjC1EmwHCJ1uvbU3I4vJ
kNE2+XgSlNA9vEqzxVn6QiioiI/gfO8RT0svmrr+tcpBbVnTrqQ5aDUW1+KGNR2/
lVlWmxbz
=4Pl6
-----END PGP SIGNATURE-----

Timestamp of file with hash a6152b70c0c6ef60deb64a857a8b598107e67ea657a7702b710dc476876d1c76 -

@maflcko maflcko merged commit 17b51cd into bitcoin:master Apr 19, 2021
@fanquake
Copy link
Member

Note that this PR changed the file permissions of src/net_processsing.cpp for no reason.

Copy link
Contributor

@jnewbery jnewbery left a 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);
Copy link
Contributor

@jnewbery jnewbery Apr 19, 2021

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:

Suggested change
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);
Copy link
Contributor

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;
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
bool fNewBlock = false;
bool new_block{false};

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 19, 2021
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
fanquake added a commit to bitcoin-core/gui that referenced this pull request Apr 20, 2021
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
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 20, 2021
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
@jamesob jamesob mentioned this pull request May 27, 2021
18 tasks
fanquake added a commit that referenced this pull request Jun 2, 2021
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
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 3, 2021
…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
@bitcoin bitcoin deleted a comment from arslan-raza-143 Apr 7, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Apr 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants