Properly transition state to disconnected:

If the number of peers a server has is below the configured
minimum peer limit, this commit will properly transition the
server's state to "disconnected".

The default limit for the minimum number of peers required was
0 meaning that a server that was connected but lost all its
peers would never transition to disconnected, since it could
never drop below zero peers.

This commit redefines the default minimum number of peers to 1
and produces a warning if the server is configured in a way
that will prevent it from ever achieving sufficient connectivity.
This commit is contained in:
Nik Bougalis
2019-02-13 20:11:11 -08:00
parent e974c7d8a4
commit 2529edd2b6
4 changed files with 35 additions and 17 deletions

View File

@@ -314,7 +314,7 @@ void Config::loadFromString (std::string const& fileContents)
PEER_PRIVATE = beast::lexicalCastThrow <bool> (strTemp);
if (getSingleSection (secConfig, SECTION_PEERS_MAX, strTemp, j_))
PEERS_MAX = std::max (0, beast::lexicalCastThrow <int> (strTemp));
PEERS_MAX = beast::lexicalCastThrow <std::size_t> (strTemp);
if (getSingleSection (secConfig, SECTION_NODE_SIZE, strTemp, j_))
{
@@ -360,7 +360,7 @@ void Config::loadFromString (std::string const& fileContents)
"and [" SECTION_VALIDATOR_TOKEN "] config sections");
if (getSingleSection (secConfig, SECTION_NETWORK_QUORUM, strTemp, j_))
NETWORK_QUORUM = beast::lexicalCastThrow <std::size_t> (strTemp);
NETWORK_QUORUM = beast::lexicalCastThrow<std::size_t>(strTemp);
if (getSingleSection (secConfig, SECTION_FEE_ACCOUNT_RESERVE, strTemp, j_))
FEE_ACCOUNT_RESERVE = beast::lexicalCastThrow <std::uint64_t> (strTemp);
@@ -539,6 +539,24 @@ void Config::loadFromString (std::string const& fileContents)
"Unknown feature: " + s + " in config file.");
}
}
// This doesn't properly belong here, but check to make sure that the
// value specified for network_quorum is achievable:
{
auto pm = PEERS_MAX;
// FIXME this apparently magic value is actually defined as a constant
// elsewhere (see defaultMaxPeers) but we handle this check here.
if (pm == 0)
pm = 21;
if (NETWORK_QUORUM > pm)
{
Throw<std::runtime_error>(
"The minimum number of required peers (network_quorum) exceeds "
"the maximum number of allowed peers (peers_max)");
}
}
}
int Config::getSize (SizedItemName item) const