Repository navigation
Closed
Description
From what I can tell the connection eviction logic is not covered by our test suite (functional and unit tests).
More specifically the following is never executed with nInbound >= nMaxInbound:
Lines 962 to 970 in ed9a2a3
| if (nInbound >= nMaxInbound) | |
| { | |
| if (!AttemptToEvictConnection()) { | |
| // No connection to evict, disconnect the new connection | |
| LogPrint(BCLog::NET, "failed to find an eviction candidate - connection dropped (full)\n"); | |
| CloseSocket(hSocket); | |
| return; | |
| } | |
| } |
Context:
Lines 800 to 808 in ed9a2a3
| /** Try to find a connection to evict when the node is full. | |
| * Extreme care must be taken to avoid opening the node to attacker | |
| * triggered network partitioning. | |
| * The strategy used here is to protect a small number of peers | |
| * for each of several distinct characteristics which are difficult | |
| * to forge. In order to partition a node the attacker must be | |
| * simultaneously better at all of them than honest peers. | |
| */ | |
| bool CConnman::AttemptToEvictConnection() |
A test would be nice here :-)
Due to AttemptToEvictConnection not being tested the following net.cpp functions -- which are only called directly or indirectly via AttemptToEvictConnection -- are currently untested:
static bool ReverseCompareNodeMinPingTime(const NodeEvictionCandidate& a, const NodeEvictionCandidate& b)
static bool ReverseCompareNodeTimeConnected(const NodeEvictionCandidate& a, const NodeEvictionCandidate& b)
static bool CompareNetGroupKeyed(const NodeEvictionCandidate& a, const NodeEvictionCandidate& b)
static bool CompareNodeBlockTime(const NodeEvictionCandidate& a, const NodeEvictionCandidate& b)
static bool CompareNodeTXTime(const NodeEvictionCandidate& a, const NodeEvictionCandidate& b)
static void EraseLastKElements(std::vector<T>& elements, Comparator comparator, size_t k)
Activity
maflcko commentedon Aug 21, 2019
Closing as duplicate of #14210
practicalswift commentedon Aug 21, 2019
@MarcoFalke
Do you know if we have any tests for the eviction logic? Perhaps my measurements are incorrect.
AFAICT the eviction logic is by far the most critical code path not covered at all by any test. I mean "at all" in the most literal sense: the code path it isn't even entered (if my measurements are correct) when running the full test suite :-)
I'm not super convinced that this very specific observation/issue is a duplicate of the general observation/issue "we could do better network testing in general" (#14210). Fixing the former can be done quickly - fixing the latter will take quite some time. Don't you think? :-)
maflcko commentedon Aug 21, 2019
Fixing #14210 is a requirement for fixing this issue. This issue is also mentioned as motivating example in #14210.
practicalswift commentedon Aug 21, 2019
I can see the dependency on #14210 for functional testing, but unit tests could easily be written to cover these functions AFAICT:
That would be good even if #14210 takes time to resolve :-)
mzumsande commentedon Aug 23, 2019
I think that parts of the eviction logic could be tested in a functional test also prior to #14210 being solved.
The eviction logic applies to inbound peers and ignores outbound peers - we can simulate inbound connections with
P2PInterface, and don't need outbound peers to actually exist.I don't see how the logic based on address/netgroup could be tested, but other parts can.
There is a draft version of a functional test that partially covers the logic of
CConnman::AttemptToEvictConnectionin mzumsande/bitcoin@56d38d0I intend to open a PR based on this in the next days, but for that PR I will also add a commit with unit tests (unless @practicalswift you are working on that?).
practicalswift commentedon Aug 23, 2019
@mzumsande Oh, that's excellent news! Very glad to hear that you're working on this! Thanks!
No, I'm just sharing my observation: I was quite surprised to see that the code eviction code path wasn't exercised at all when running the full test suite given how important it is that we get this logic correct. An error in this code could lead to attacker triggered network partitioning.
@MarcoFalke Would you mind re-opening this ticket?
practicalswift commentedon May 19, 2020
Closing due to lack of progress/interest :)
jnewbery commentedon May 31, 2020
#16756 has received some good review over the last two weeks, and we're covering it in review club next week (https://bitcoincore.reviews/16756.html)
I don't think we need to re-open this issue, but it's certainly not true that there isn't progress/interest in this :)
practicalswift commentedon May 31, 2020
Great news! :)
15 remaining items
Merge bitcoin#16756: test: Connection eviction logic tests
Merge bitcoin#16756: test: Connection eviction logic tests
Merge bitcoin#16756: test: Connection eviction logic tests
Merge #16756: test: Connection eviction logic tests