Skip to content
Permalink
Browse files

[FOLD] Override minimum quorum from command line:

Make ValidatorList::quorum_ atomic
  • Loading branch information...
wilsonianb
wilsonianb committed Sep 14, 2016
1 parent 88ba1b6 commit 475cbf82fe8b6fc8c2783fe1b4f1646338538274
@@ -479,7 +479,8 @@ class ApplicationImp
logs_->journal("ManifestCache")))

, validators_ (std::make_unique<ValidatorList> (
*manifestCache_, get_io_service (), logs_->journal("ValidatorList")))
*manifestCache_, get_io_service (),
logs_->journal("ValidatorList"), config_->VALIDATION_QUORUM))

, serverHandler_ (make_ServerHandler (*this, *m_networkOPs, get_io_service (),
*m_jobQueue, *m_networkOPs, *m_resourceManager, *m_collectorManager))
@@ -215,6 +215,7 @@ int run (int argc, char** argv)
("unittest-arg", po::value <std::string> ()->implicit_value (""), "Supplies argument to unit tests.")
("parameters", po::value< vector<string> > (), "Specify comma separated parameters.")
("quiet,q", "Reduce diagnotics.")
("quorum", po::value <std::size_t> (), "Override the minimum validation quorum.")
("silent", "No output to the console after startup.")
("verbose,v", "Verbose logging.")
("load", "Load the current ledger from the local DB.")
@@ -374,6 +375,20 @@ int run (int argc, char** argv)
}
}

if (vm.count ("quorum"))
{
try
{
config->VALIDATION_QUORUM = vm["quorum"].as <std::size_t> ();
}
catch(std::exception const&)
{
std::cerr << "Invalid quorum = " <<
vm["quorum"].as <std::string> () << std::endl;
return -1;
}
}

// Construct the logs object at the configured severity
using namespace beast::severities;
Severity thresh = kInfo;
@@ -118,7 +118,8 @@ class ValidatorList
bool stopping_;

std::size_t fetchedLists_;
std::size_t quorum_;
std::atomic<std::size_t> quorum_;
boost::optional<std::size_t> minimumQuorum_;

// The configured list of URIs for fetching lists
std::vector<Site> sites_;
@@ -138,7 +139,8 @@ class ValidatorList
ValidatorList (
ManifestCache& manifests,
boost::asio::io_service& io_service,
beast::Journal j);
beast::Journal j,
boost::optional<std::size_t> minimumQuorum = boost::none);
~ValidatorList ();

/** Load configured site URIs and trusted keys.
@@ -229,12 +231,16 @@ class ValidatorList
@param nListed Number of keys included on any recommended lists
@param minQuorum Custom lower limit. Not recommended when connecting to
live network.
@return quorum value
*/
static std::size_t
calcQuorum (
std::uint32_t nTrusted,
std::uint32_t nListed);
std::uint32_t nListed,
boost::optional<std::size_t> minQuorum = boost::none);

/** Get quorum value for current trusted key set
@@ -35,7 +35,8 @@ auto constexpr DEFAULT_REFRESH_INTERVAL = std::chrono::minutes{5};
ValidatorList::ValidatorList (
ManifestCache& manifests,
boost::asio::io_service& io_service,
beast::Journal j)
beast::Journal j,
boost::optional<std::size_t> minimumQuorum)
: manifests_ (manifests)
, j_ (j)
, io_service_ (io_service)
@@ -45,6 +46,7 @@ ValidatorList::ValidatorList (
, stopping_ (false)
, fetchedLists_ (0)
, quorum_ (0)
, minimumQuorum_ (minimumQuorum)
{
}

@@ -320,14 +322,16 @@ ValidatorList::trustedPublisher (PublicKey const& identity) const
std::size_t
ValidatorList::calcQuorum (
std::uint32_t nTrusted,
std::uint32_t nListed)
std::uint32_t nListed,
boost::optional<std::size_t> minQuorum)
{
const std::vector<std::size_t> neededValidations{
0, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7};
auto constexpr quorumRatio = 0.8;

// Floor of 80% of minimum required overlap with all listed validators
auto quorum = std::ceil (
// Unless a custom minimum is provided, set floor to 80% of minimum required
// overlap with all listed validators
auto quorum = minQuorum ? *minQuorum : std::ceil (
quorumRatio *
std::ceil (
MINIMUM_NETWORK_OVERLAP *
@@ -154,6 +154,7 @@ class Config : public BasicConfig
// Validation
PublicKey VALIDATION_PUB;
SecretKey VALIDATION_PRIV;
boost::optional<size_t> VALIDATION_QUORUM; // Minimum validations to consider ledger authoritative

// Node Identity
std::string NODE_SEED;
@@ -1291,6 +1291,9 @@ class ValidatorList_test : public beast::unit_test::suite
// Allow the number of trusted validators to exceed
// the number of listed validators
BEAST_EXPECT(7 == ValidatorList::calcQuorum (10, 5));

// Use custom lower limit
BEAST_EXPECT(0 == ValidatorList::calcQuorum (0, 5, 0));
}

public:

0 comments on commit 475cbf8

Please sign in to comment.
You can’t perform that action at this time.