Use quorum specified via command line: (#4489)

If `--quorum` setting is present on the command line, use the specified
value as the minimum quorum. This allows for the use of a potentially
fork-unsafe quorum, but it is sometimes necessary for small and test
networks.

Fix #4488.

---------

Co-authored-by: RichardAH <richard.holland@starstone.co.nz>
This commit is contained in:
Mark Travis
2023-04-20 11:36:18 -07:00
committed by GitHub
parent 1f417764c3
commit c5003969de
2 changed files with 15 additions and 18 deletions

View File

@@ -1710,6 +1710,15 @@ ValidatorList::calculateQuorum(
std::size_t effectiveUnlSize,
std::size_t seenSize)
{
// Use quorum if specified via command line.
if (minimumQuorum_ > 0)
{
JLOG(j_.warn()) << "Using potentially unsafe quorum of "
<< *minimumQuorum_
<< " as specified on the command line";
return *minimumQuorum_;
}
// Do not use achievable quorum until lists from all configured
// publishers are available
for (auto const& list : publisherLists_)
@@ -1752,21 +1761,8 @@ ValidatorList::calculateQuorum(
// Note that the negative UNL protocol introduced the
// AbsoluteMinimumQuorum which is 60% of the original UNL size. The
// effective quorum should not be lower than it.
auto quorum = static_cast<std::size_t>(std::max(
return static_cast<std::size_t>(std::max(
std::ceil(effectiveUnlSize * 0.8f), std::ceil(unlSize * 0.6f)));
// Use lower quorum specified via command line if the normal quorum
// appears unreachable based on the number of recently received
// validations.
if (minimumQuorum_ && *minimumQuorum_ < quorum && seenSize < quorum)
{
quorum = *minimumQuorum_;
JLOG(j_.warn()) << "Using unsafe quorum of " << quorum
<< " as specified in the command line";
}
return quorum;
}
TrustChanges

View File

@@ -1318,7 +1318,7 @@ private:
BEAST_EXPECT(changes.added == expectedTrusted);
BEAST_EXPECT(trustedKeys->quorum() == minQuorum);
// Use normal quorum when seen validators >= quorum
// Use configured quorum even when seen validators >= quorum
activeValidators.emplace(toBeSeen);
changes = trustedKeys->updateTrusted(
activeValidators,
@@ -1328,7 +1328,7 @@ private:
env.app().getHashRouter());
BEAST_EXPECT(changes.removed.empty());
BEAST_EXPECT(changes.added.empty());
BEAST_EXPECT(trustedKeys->quorum() == std::ceil(n * 0.8f));
BEAST_EXPECT(trustedKeys->quorum() == minQuorum);
}
{
// Remove expired published list
@@ -1828,7 +1828,8 @@ private:
env.app().getOPs(),
env.app().overlay(),
env.app().getHashRouter());
if (trustedKeys->quorum() == std::ceil(cfgKeys.size() * 0.8f))
if (minimumQuorum == trustedKeys->quorum() ||
trustedKeys->quorum() == std::ceil(cfgKeys.size() * 0.8f))
return trustedKeys;
}
return nullptr;
@@ -1980,7 +1981,7 @@ private:
env.app().getOPs(),
env.app().overlay(),
env.app().getHashRouter());
BEAST_EXPECT(validators->quorum() == 48);
BEAST_EXPECT(validators->quorum() == 30);
hash_set<PublicKey> nUnl;
it = unl.begin();
for (std::uint32_t i = 0; i < 20; ++i)