This PR splits of the first couple commits from #25268 that move the inbound eviction logic from net.{h,cpp} to eviction.{h,cpp}.
Please look at #25268 for motivation and conceptual review.
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
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.
44 | @@ -45,6 +45,12 @@ static inline constexpr NetPermissionFlags operator|(NetPermissionFlags a, NetPe 45 | return static_cast<NetPermissionFlags>(static_cast<t>(a) | static_cast<t>(b)); 46 | } 47 | 48 | +static inline constexpr NetPermissionFlags operator&(NetPermissionFlags a, NetPermissionFlags b) 49 | +{ 50 | + using t = typename std::underlying_type<NetPermissionFlags>::type; 51 | + return static_cast<NetPermissionFlags>(static_cast<t>(a) & static_cast<t>(b));
nit: Could write NetPermissionFlags{...} instead of static_cast?
Removed this commit entirely and took john's suggestion: #25500 (review)
347 | @@ -346,8 +348,10 @@ libbitcoin_node_a_SOURCES = \ 348 | blockfilter.cpp \ 349 | chain.cpp \ 350 | consensus/tx_verify.cpp \ 351 | + connection_types.cpp \ 352 | dbwrapper.cpp \ 353 | deploymentstatus.cpp \ 354 | + eviction.cpp \
nit: I wonder if the new files should be placed in node, as the lib is called libbitcoin_node_a_SOURCES
Seems reasonable. Same for connection_types.cpp|h.
Done.
26 | + bool fBloomFilter; 27 | + uint64_t nKeyedNetGroup; 28 | + bool prefer_evict; 29 | + bool m_is_local; 30 | + Network m_network; 31 | + NetPermissionFlags m_perm_flags;
Does the eviction logic need to know about all the permission flags? The logic only uses whether the NetPermissionFlags::NoBan bit is set. Perhaps this could be replaced with a m_noban bool?
Done.
27 | + uint64_t nKeyedNetGroup; 28 | + bool prefer_evict; 29 | + bool m_is_local; 30 | + Network m_network; 31 | + NetPermissionFlags m_perm_flags; 32 | + ConnectionType m_conn_type;
Likewise, only one bit of information is actually needed by the eviction logic. Would it be better to replace this with an m_inbound boolean?
Perhaps the eviction logic will be changed in future to use more permissions and connection types, but it'll be easy enough to change these internal interfaces when that happens.
Left this as is because the outbound eviction logic that gets moved to the eviction manager in #25500 does need the connection type.
Of course i could go with your suggestion here and add back the connection type in a later commit for the outbound logic. Let me know if you prefer that.
That sounds fine to me.
Concept ACK
0 | @@ -0,0 +1,27 @@ 1 | +// Copyright (c) 2009-2010 Satoshi Nakamoto
I'm pretty sure Satoshi didn't write any of this code (same for other files)
Done.
utACK 2eb7256b643012b00f98997150ad753aa6d0a22b
1260 | @@ -1261,6 +1261,7 @@ struct NodeEvictionCandidate 1261 | bool prefer_evict; 1262 | bool m_is_local; 1263 | Network m_network; 1264 | + bool m_noban;
At a high level, it's a little weird to add a flag to the eviction criteria that basically means "don't consider me for eviction". I assume this will prompt in future commits the reasonable question: should we bother adding nodes that can't be evicted to the eviction manager? (I don't know the answer to that question at this point, just pointing out that the discussion will come up later).
Hm, good point. I will leave this unresolved for now so other reviewers can chime in.
It's obviously correct here btw, I didn't mean to imply otherwise. Just a little weird :)
utACK 0101d2bc3c3bcf698d6cc2a237a680fc52395987
utACK 0101d2bc3c3bcf698d6cc2a237a680fc52395987. I quickly verified with git --color-moved that the move-only changes are indeed move-only.
8 | @@ -9,6 +9,7 @@ 9 | #include <chainparams.h> 10 | #include <common/bloom.h> 11 | #include <compat.h> 12 | +#include <node/connection_types.h>
nit: Just noticed these are now out of the recommended include order