fix: Set the peer limit total when per-direction limits are configured (#8220)

Co-authored-by: Bart <11445373+bthomee@users.noreply.github.com>
Co-authored-by: Vito Tumas <5780819+Tapanito@users.noreply.github.com>
This commit is contained in:
Bart
2026-09-15 13:14:12 +00:00
committed by GitHub
parent 1a4a40ebb8
commit e302e4eeed
4 changed files with 102 additions and 4 deletions

View File

@@ -1214,6 +1214,9 @@ TEST(PeerFinderConfig, applies_legacy_and_explicit_peer_limits)
.expectedOut = 10,
.expectedIn = 0,
.expectedIpLimit = 1},
// A port of zero disables incoming connections, so the configured
// inbound limit is dropped and the per-IP inbound limit collapses to
// one, exactly as in the legacy private case above.
{.name = "new in 100/out 10, private",
.maxPeers = {},
.maxIn = 100,
@@ -1221,7 +1224,7 @@ TEST(PeerFinderConfig, applies_legacy_and_explicit_peer_limits)
.port = 0,
.expectedOut = 10,
.expectedIn = 0,
.expectedIpLimit = 6}};
.expectedIpLimit = 1}};
for (auto const& testCase : cases)
{
@@ -1239,6 +1242,13 @@ TEST(PeerFinderConfig, applies_legacy_and_explicit_peer_limits)
EXPECT_EQ(counts.inMax(), testCase.expectedIn);
EXPECT_EQ(config.ipLimit, testCase.expectedIpLimit);
// The configuration itself carries the same per-direction allowances
// that the slot counts derive, and `maxPeers` is their total. Callers
// such as `Overlay::limit` read `maxPeers` directly.
EXPECT_EQ(config.outPeers, testCase.expectedOut);
EXPECT_EQ(config.inPeers, testCase.expectedIn);
EXPECT_EQ(config.maxPeers, config.inPeers + config.outPeers);
NiceMock<MockStore> store;
allowEmptyStore(store);
NiceMock<MockChecker> checker;