-
Notifications
You must be signed in to change notification settings - Fork 37.7k
[net processing] Various tidying up of PeerManagerImpl ctor #21562
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
[net processing] Various tidying up of PeerManagerImpl ctor #21562
Conversation
Cirrus failures: In file included from init.cpp:55:
./txorphanage.h:50:28: error: reading variable 'm_orphans' requires holding mutex 'g_cs_orphans' [-Werror,-Wthread-safety-analysis]
size_t Size() { return m_orphans.size(); };
^
1 error generated.
make[2]: *** [libbitcoin_server_a-init.o] Error 1
make[2]: *** Waiting for unfinished jobs....
CXX libbitcoin_server_a-net_processing.o
In file included from net_processing.cpp:29:
./txorphanage.h:50:28: error: reading variable 'm_orphans' requires holding mutex 'g_cs_orphans' [-Werror,-Wthread-safety-analysis]
size_t Size() { return m_orphans.size(); };
^
net_processing.cpp:410:59: error: expected ';' at end of declaration list
CRollingBloomFilter m_recent_rejects{120000, 0.000001} GUARDED_BY(cs_main);
^
;
net_processing.cpp:429:73: error: expected ';' at end of declaration list
CRollingBloomFilter m_recent_confirmed_transactions{48000, 0.000001} GUARDED_BY(m_recent_confirmed_transactions_mutex);
^
;
3 errors generated. |
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. |
94b5fea
to
b458400
Compare
Strong Concept ACK I find the suggested code easier to reason about from a safety and correctness perspective. |
b458400
to
44c05f7
Compare
The build failure is because |
44c05f7
to
a1f2f65
Compare
Thanks Marco! I've just reverted these checks to |
@jnewbery Help me to understand the motivation for "[net processing] Move consistency checks to PeerManagerImpl dtor" commit please. My current understanding is following. A consistency is an invariant that the |
I think that's fair. My reasoning was that these invariant checks are all test/development asserts. We'd hope that they'd never be hit in the wild. They currently run when the peer count drops to zero, but if there's an inconsistency then, we'd expect those invariants to also be false when the PeerManagerImpl is destructed on shutdown. My motivation is that I want to pull some of these members out from being guarded by cs_main. The global counts like |
src/net_processing.cpp
Outdated
PeerManagerImpl::~PeerManagerImpl() | ||
{ | ||
// Do consistency checks on shutdown | ||
LOCK(cs_main); |
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.
Only one thread has an access to the object while a dtor is called. Why lock?
🕵️ @sipa has been requested to review this pull request as specified in the REVIEWERS file. |
a1f2f65
to
b26a5ad
Compare
@hebasto - there are various changes to net_processing logging happening in 21527, so I've removed the changes to the destructor here until those land. Let me know if you think the remaining changes to the constructor in this PR are worth keeping. Also rebased on current master. |
Code review ACK b26a5ad I was confused by the asserts prior to this PR. Also there are two typos in the commit messages "contetx" should be "context"? |
b26a5ad
to
d6cef4d
Compare
Thanks @Crypt-iQ. I've corrected the typos in the commit logs.
These were to ensure that |
d6cef4d
to
93e881f
Compare
Rebased on master to fix fuzz CI timeout. |
Code review ACK 93e881f Commit message 9e6bf78 has a typo: rejectRejects should be recentRejects |
Rebased.
Fixed. Thank you! |
93e881f
to
d5dd3fa
Compare
review ACK d5dd3fa 🔠 Show signature and timestampSignature:
Timestamp of file with hash |
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.
ACK d5dd3fa
While touching the net_processing.cpp
, also a typo which was introduced in #22141 could be fixed:
bitcoin/src/net_processing.cpp
Line 470 in 5c2e2af
* - the block has been recieved from a peer |
recieved
==> received
cr ACK d5dd3fa |
d5dd3fa
to
214e91a
Compare
Thanks for the reviews @MarcoFalke, @hebasto, @practicalswift. I've addressed all of the review comments from @hebasto so this is now ready for re-review.
I was too slow. It's been fixed in #22323. |
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 214e91a
one stylistic/readability-improvement nit: could also use the digit separators (') for the floating point numeral for the CRollingBloomFilter (valid since C++14 according to https://en.cppreference.com/w/cpp/language/floating_literal):
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 25fbd33b5..772ea2ced 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -453,7 +453,7 @@ private:
*
* Memory used: 1.3 MB
*/
- CRollingBloomFilter m_recent_rejects GUARDED_BY(::cs_main){120'000, 0.000001};
+ CRollingBloomFilter m_recent_rejects GUARDED_BY(::cs_main){120'000, 0.000'001};
uint256 hashRecentRejectsChainTip GUARDED_BY(cs_main);
/*
@@ -472,7 +472,7 @@ private:
* same probability that we have in the reject filter).
*/
Mutex m_recent_confirmed_transactions_mutex;
- CRollingBloomFilter m_recent_confirmed_transactions GUARDED_BY(m_recent_confirmed_transactions_mutex){48'000, 0.000001};
+ CRollingBloomFilter m_recent_confirmed_transactions GUARDED_BY(m_recent_confirmed_transactions_mutex){48'000, 0.000'001};
/** Have we requested this block from a peer */
bool IsBlockRequested(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
When removing the final peer, assert that m_tx_orphanage is empty.
Now that recentRejects is owned by PeerManagerImpl, and PeerManagerImpl's lifetime is managed by the node context, we can just default initialize recentRejects during object initialization. We can also remove the unique_ptr indirection.
-BEGIN VERIFY SCRIPT- ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); } ren recentRejects m_recent_rejects -END VERIFY SCRIPT-
Now that m_recent_confirmed_transactions is owned by PeerManagerImpl, and PeerManagerImpl's lifetime is managed by the node context, we can just default initialize m_recent_confirmed_transactions during object initialization. We can also remove the unique_ptr indirection.
214e91a
to
fde1bf4
Compare
Thanks for the review @theStack. I didn't realize that the digit separator was permitted after the decimal point. I've taken your suggestion and rebased on master. |
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.
re-ACK fde1bf4
checked via git range-diff 214e91a3...fde1bf4f
that since my previous ACK, the only non-rebase-related change is using the digit separator also for floating points now, as suggested.
ACK fde1bf4 👞 Show signature and timestampSignature:
Timestamp of file with hash |
…erImpl ctor fde1bf4 [net processing] Default initialize m_recent_confirmed_transactions (John Newbery) 37dcd12 scripted-diff: Rename recentRejects (John Newbery) cd9902a [net processing] Default initialize recentRejects (John Newbery) a28bfd1 [net processing] Default initialize m_stale_tip_check_time (John Newbery) 9190b01 [net processing] Add Orphanage empty consistency check (John Newbery) Pull request description: - Use default initialization of PeerManagerImpl members where possible - Remove unique_ptr indirection where it's not needed ACKs for top commit: MarcoFalke: ACK fde1bf4 👞 theStack: re-ACK fde1bf4 Tree-SHA512: 7ddedcc972df8e933e1fbe5c88b8ea17df89e1e58fc769518512c5540e49dc8eddb3f47e78d1329a6fc5644d2c1d11c981f681fd633f5218bfa4b3e6a86f3d7b
Uh oh!
There was an error while loading. Please reload this page.