mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-28 22:45:49 +00:00
Format first-party source according to .clang-format
This commit is contained in:
committed by
manojsdoshi
parent
65dfc5d19e
commit
50760c6935
@@ -17,12 +17,12 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/app/misc/ValidatorList.h>
|
||||
#include <ripple/app/misc/HashRouter.h>
|
||||
#include <ripple/basics/base64.h>
|
||||
#include <ripple/app/misc/ValidatorList.h>
|
||||
#include <ripple/basics/FileUtilities.h>
|
||||
#include <ripple/basics/Slice.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/basics/base64.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <ripple/overlay/Overlay.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
@@ -60,74 +60,73 @@ to_string(ListDisposition disposition)
|
||||
|
||||
const std::string ValidatorList::filePrefix_ = "cache.";
|
||||
|
||||
ValidatorList::ValidatorList (
|
||||
ValidatorList::ValidatorList(
|
||||
ManifestCache& validatorManifests,
|
||||
ManifestCache& publisherManifests,
|
||||
TimeKeeper& timeKeeper,
|
||||
std::string const& databasePath,
|
||||
beast::Journal j,
|
||||
boost::optional<std::size_t> minimumQuorum)
|
||||
: validatorManifests_ (validatorManifests)
|
||||
, publisherManifests_ (publisherManifests)
|
||||
, timeKeeper_ (timeKeeper)
|
||||
: validatorManifests_(validatorManifests)
|
||||
, publisherManifests_(publisherManifests)
|
||||
, timeKeeper_(timeKeeper)
|
||||
, dataPath_(databasePath)
|
||||
, j_ (j)
|
||||
, quorum_ (minimumQuorum.value_or(1)) // Genesis ledger quorum
|
||||
, minimumQuorum_ (minimumQuorum)
|
||||
, j_(j)
|
||||
, quorum_(minimumQuorum.value_or(1)) // Genesis ledger quorum
|
||||
, minimumQuorum_(minimumQuorum)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
ValidatorList::load (
|
||||
ValidatorList::load(
|
||||
PublicKey const& localSigningKey,
|
||||
std::vector<std::string> const& configKeys,
|
||||
std::vector<std::string> const& publisherKeys)
|
||||
{
|
||||
static boost::regex const re (
|
||||
"[[:space:]]*" // skip leading whitespace
|
||||
"([[:alnum:]]+)" // node identity
|
||||
"(?:" // begin optional comment block
|
||||
"[[:space:]]+" // (skip all leading whitespace)
|
||||
"(?:" // begin optional comment
|
||||
"(.*[^[:space:]]+)" // the comment
|
||||
"[[:space:]]*" // (skip all trailing whitespace)
|
||||
")?" // end optional comment
|
||||
")?" // end optional comment block
|
||||
static boost::regex const re(
|
||||
"[[:space:]]*" // skip leading whitespace
|
||||
"([[:alnum:]]+)" // node identity
|
||||
"(?:" // begin optional comment block
|
||||
"[[:space:]]+" // (skip all leading whitespace)
|
||||
"(?:" // begin optional comment
|
||||
"(.*[^[:space:]]+)" // the comment
|
||||
"[[:space:]]*" // (skip all trailing whitespace)
|
||||
")?" // end optional comment
|
||||
")?" // end optional comment block
|
||||
);
|
||||
|
||||
std::unique_lock<std::shared_timed_mutex> read_lock{mutex_};
|
||||
|
||||
JLOG (j_.debug()) <<
|
||||
"Loading configured trusted validator list publisher keys";
|
||||
JLOG(j_.debug())
|
||||
<< "Loading configured trusted validator list publisher keys";
|
||||
|
||||
std::size_t count = 0;
|
||||
for (auto key : publisherKeys)
|
||||
{
|
||||
JLOG (j_.trace()) <<
|
||||
"Processing '" << key << "'";
|
||||
JLOG(j_.trace()) << "Processing '" << key << "'";
|
||||
|
||||
auto const ret = strUnHex (key);
|
||||
auto const ret = strUnHex(key);
|
||||
|
||||
if (! ret || ! publicKeyType(makeSlice(*ret)))
|
||||
if (!ret || !publicKeyType(makeSlice(*ret)))
|
||||
{
|
||||
JLOG (j_.error()) <<
|
||||
"Invalid validator list publisher key: " << key;
|
||||
JLOG(j_.error()) << "Invalid validator list publisher key: " << key;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto id = PublicKey(makeSlice(*ret));
|
||||
|
||||
if (publisherManifests_.revoked (id))
|
||||
if (publisherManifests_.revoked(id))
|
||||
{
|
||||
JLOG (j_.warn()) <<
|
||||
"Configured validator list publisher key is revoked: " << key;
|
||||
JLOG(j_.warn())
|
||||
<< "Configured validator list publisher key is revoked: "
|
||||
<< key;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (publisherLists_.count(id))
|
||||
{
|
||||
JLOG (j_.warn()) <<
|
||||
"Duplicate validator list publisher key: " << key;
|
||||
JLOG(j_.warn())
|
||||
<< "Duplicate validator list publisher key: " << key;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -135,40 +134,35 @@ ValidatorList::load (
|
||||
++count;
|
||||
}
|
||||
|
||||
JLOG (j_.debug()) <<
|
||||
"Loaded " << count << " keys";
|
||||
JLOG(j_.debug()) << "Loaded " << count << " keys";
|
||||
|
||||
localPubKey_ = validatorManifests_.getMasterKey (localSigningKey);
|
||||
localPubKey_ = validatorManifests_.getMasterKey(localSigningKey);
|
||||
|
||||
// Treat local validator key as though it was listed in the config
|
||||
if (localPubKey_.size())
|
||||
keyListings_.insert ({ localPubKey_, 1 });
|
||||
keyListings_.insert({localPubKey_, 1});
|
||||
|
||||
JLOG (j_.debug()) <<
|
||||
"Loading configured validator keys";
|
||||
JLOG(j_.debug()) << "Loading configured validator keys";
|
||||
|
||||
count = 0;
|
||||
PublicKey local;
|
||||
for (auto const& n : configKeys)
|
||||
{
|
||||
JLOG (j_.trace()) <<
|
||||
"Processing '" << n << "'";
|
||||
JLOG(j_.trace()) << "Processing '" << n << "'";
|
||||
|
||||
boost::smatch match;
|
||||
|
||||
if (!boost::regex_match (n, match, re))
|
||||
if (!boost::regex_match(n, match, re))
|
||||
{
|
||||
JLOG (j_.error()) <<
|
||||
"Malformed entry: '" << n << "'";
|
||||
JLOG(j_.error()) << "Malformed entry: '" << n << "'";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto const id = parseBase58<PublicKey>(
|
||||
TokenType::NodePublic, match[1]);
|
||||
auto const id = parseBase58<PublicKey>(TokenType::NodePublic, match[1]);
|
||||
|
||||
if (!id)
|
||||
{
|
||||
JLOG (j_.error()) << "Invalid node identity: " << match[1];
|
||||
JLOG(j_.error()) << "Invalid node identity: " << match[1];
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -176,10 +170,10 @@ ValidatorList::load (
|
||||
if (*id == localPubKey_ || *id == localSigningKey)
|
||||
continue;
|
||||
|
||||
auto ret = keyListings_.insert ({*id, 1});
|
||||
if (! ret.second)
|
||||
auto ret = keyListings_.insert({*id, 1});
|
||||
if (!ret.second)
|
||||
{
|
||||
JLOG (j_.warn()) << "Duplicate node identity: " << match[1];
|
||||
JLOG(j_.warn()) << "Duplicate node identity: " << match[1];
|
||||
continue;
|
||||
}
|
||||
auto it = publisherLists_.emplace(
|
||||
@@ -194,8 +188,7 @@ ValidatorList::load (
|
||||
++count;
|
||||
}
|
||||
|
||||
JLOG (j_.debug()) <<
|
||||
"Loaded " << count << " entries";
|
||||
JLOG(j_.debug()) << "Loaded " << count << " entries";
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -207,14 +200,14 @@ ValidatorList::GetCacheFileName(PublicKey const& pubKey)
|
||||
}
|
||||
|
||||
void
|
||||
ValidatorList::CacheValidatorFile(PublicKey const& pubKey,
|
||||
ValidatorList::CacheValidatorFile(
|
||||
PublicKey const& pubKey,
|
||||
PublisherList const& publisher)
|
||||
{
|
||||
if (dataPath_.empty())
|
||||
return;
|
||||
|
||||
boost::filesystem::path const filename =
|
||||
GetCacheFileName(pubKey);
|
||||
boost::filesystem::path const filename = GetCacheFileName(pubKey);
|
||||
|
||||
boost::system::error_code ec;
|
||||
|
||||
@@ -230,13 +223,8 @@ ValidatorList::CacheValidatorFile(PublicKey const& pubKey,
|
||||
if (ec)
|
||||
{
|
||||
// Log and ignore any file I/O exceptions
|
||||
JLOG(j_.error()) <<
|
||||
"Problem writing " <<
|
||||
filename <<
|
||||
" " <<
|
||||
ec.value() <<
|
||||
": " <<
|
||||
ec.message();
|
||||
JLOG(j_.error()) << "Problem writing " << filename << " " << ec.value()
|
||||
<< ": " << ec.message();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,8 +239,8 @@ ValidatorList::applyListAndBroadcast(
|
||||
Overlay& overlay,
|
||||
HashRouter& hashRouter)
|
||||
{
|
||||
auto const result = applyList(manifest, blob, signature,
|
||||
version, std::move(siteUri), hash);
|
||||
auto const result =
|
||||
applyList(manifest, blob, signature, version, std::move(siteUri), hash);
|
||||
auto const disposition = result.disposition;
|
||||
|
||||
bool broadcast = disposition == ListDisposition::accepted ||
|
||||
@@ -304,7 +292,7 @@ ValidatorList::applyListAndBroadcast(
|
||||
}
|
||||
|
||||
ValidatorList::PublisherListStats
|
||||
ValidatorList::applyList (
|
||||
ValidatorList::applyList(
|
||||
std::string const& manifest,
|
||||
std::string const& blob,
|
||||
std::string const& signature,
|
||||
@@ -315,13 +303,13 @@ ValidatorList::applyList (
|
||||
using namespace std::string_literals;
|
||||
|
||||
if (version != requiredListVersion)
|
||||
return PublisherListStats{ ListDisposition::unsupported_version };
|
||||
return PublisherListStats{ListDisposition::unsupported_version};
|
||||
|
||||
std::unique_lock<std::shared_timed_mutex> lock{mutex_};
|
||||
|
||||
Json::Value list;
|
||||
PublicKey pubKey;
|
||||
auto const result = verify (list, pubKey, manifest, blob, signature);
|
||||
auto const result = verify(list, pubKey, manifest, blob, signature);
|
||||
if (result != ListDisposition::accepted)
|
||||
{
|
||||
if (result == ListDisposition::same_sequence &&
|
||||
@@ -330,17 +318,17 @@ ValidatorList::applyList (
|
||||
// We've seen this valid list already, so return
|
||||
// what we know about it.
|
||||
auto const& publisher = publisherLists_[pubKey];
|
||||
return PublisherListStats{ result, pubKey,
|
||||
publisher.available, publisher.sequence };
|
||||
return PublisherListStats{
|
||||
result, pubKey, publisher.available, publisher.sequence};
|
||||
}
|
||||
return PublisherListStats{ result };
|
||||
return PublisherListStats{result};
|
||||
}
|
||||
|
||||
// Update publisher's list
|
||||
Json::Value const& newList = list["validators"];
|
||||
auto& publisher = publisherLists_[pubKey];
|
||||
publisher.available = true;
|
||||
publisher.sequence = list["sequence"].asUInt ();
|
||||
publisher.sequence = list["sequence"].asUInt();
|
||||
publisher.expiration = TimeKeeper::time_point{
|
||||
TimeKeeper::duration{list["expiration"].asUInt()}};
|
||||
publisher.siteUri = std::move(siteUri);
|
||||
@@ -348,66 +336,62 @@ ValidatorList::applyList (
|
||||
publisher.rawBlob = blob;
|
||||
publisher.rawSignature = signature;
|
||||
publisher.rawVersion = version;
|
||||
if(hash)
|
||||
if (hash)
|
||||
publisher.hash = *hash;
|
||||
std::vector<PublicKey>& publisherList = publisher.list;
|
||||
|
||||
PublisherListStats const applyResult{ result, pubKey,
|
||||
publisher.available, publisher.sequence };
|
||||
PublisherListStats const applyResult{
|
||||
result, pubKey, publisher.available, publisher.sequence};
|
||||
|
||||
std::vector<PublicKey> oldList = publisherList;
|
||||
publisherList.clear ();
|
||||
publisherList.reserve (newList.size ());
|
||||
publisherList.clear();
|
||||
publisherList.reserve(newList.size());
|
||||
std::vector<std::string> manifests;
|
||||
for (auto const& val : newList)
|
||||
{
|
||||
if (val.isObject() &&
|
||||
val.isMember ("validation_public_key") &&
|
||||
val["validation_public_key"].isString ())
|
||||
if (val.isObject() && val.isMember("validation_public_key") &&
|
||||
val["validation_public_key"].isString())
|
||||
{
|
||||
boost::optional<Blob> const ret = strUnHex(val["validation_public_key"].asString());
|
||||
boost::optional<Blob> const ret =
|
||||
strUnHex(val["validation_public_key"].asString());
|
||||
|
||||
if (! ret || ! publicKeyType(makeSlice(*ret)))
|
||||
if (!ret || !publicKeyType(makeSlice(*ret)))
|
||||
{
|
||||
JLOG (j_.error()) <<
|
||||
"Invalid node identity: " <<
|
||||
val["validation_public_key"].asString ();
|
||||
JLOG(j_.error()) << "Invalid node identity: "
|
||||
<< val["validation_public_key"].asString();
|
||||
}
|
||||
else
|
||||
{
|
||||
publisherList.push_back (
|
||||
PublicKey(Slice{ ret->data (), ret->size() }));
|
||||
publisherList.push_back(
|
||||
PublicKey(Slice{ret->data(), ret->size()}));
|
||||
}
|
||||
|
||||
if (val.isMember ("manifest") && val["manifest"].isString ())
|
||||
manifests.push_back(val["manifest"].asString ());
|
||||
if (val.isMember("manifest") && val["manifest"].isString())
|
||||
manifests.push_back(val["manifest"].asString());
|
||||
}
|
||||
}
|
||||
|
||||
// Update keyListings_ for added and removed keys
|
||||
std::sort (
|
||||
publisherList.begin (),
|
||||
publisherList.end ());
|
||||
std::sort(publisherList.begin(), publisherList.end());
|
||||
|
||||
auto iNew = publisherList.begin ();
|
||||
auto iOld = oldList.begin ();
|
||||
while (iNew != publisherList.end () ||
|
||||
iOld != oldList.end ())
|
||||
auto iNew = publisherList.begin();
|
||||
auto iOld = oldList.begin();
|
||||
while (iNew != publisherList.end() || iOld != oldList.end())
|
||||
{
|
||||
if (iOld == oldList.end () ||
|
||||
(iNew != publisherList.end () &&
|
||||
*iNew < *iOld))
|
||||
if (iOld == oldList.end() ||
|
||||
(iNew != publisherList.end() && *iNew < *iOld))
|
||||
{
|
||||
// Increment list count for added keys
|
||||
++keyListings_[*iNew];
|
||||
++iNew;
|
||||
}
|
||||
else if (iNew == publisherList.end () ||
|
||||
(iOld != oldList.end () && *iOld < *iNew))
|
||||
else if (
|
||||
iNew == publisherList.end() ||
|
||||
(iOld != oldList.end() && *iOld < *iNew))
|
||||
{
|
||||
// Decrement list count for removed keys
|
||||
if (keyListings_[*iOld] <= 1)
|
||||
keyListings_.erase (*iOld);
|
||||
keyListings_.erase(*iOld);
|
||||
else
|
||||
--keyListings_[*iOld];
|
||||
++iOld;
|
||||
@@ -421,28 +405,25 @@ ValidatorList::applyList (
|
||||
|
||||
if (publisherList.empty())
|
||||
{
|
||||
JLOG (j_.warn()) <<
|
||||
"No validator keys included in valid list";
|
||||
JLOG(j_.warn()) << "No validator keys included in valid list";
|
||||
}
|
||||
|
||||
for (auto const& valManifest : manifests)
|
||||
{
|
||||
auto m = deserializeManifest(base64_decode(valManifest));
|
||||
|
||||
if (! m || ! keyListings_.count (m->masterKey))
|
||||
if (!m || !keyListings_.count(m->masterKey))
|
||||
{
|
||||
JLOG (j_.warn()) <<
|
||||
"List for " << strHex(pubKey) <<
|
||||
" contained untrusted validator manifest";
|
||||
JLOG(j_.warn()) << "List for " << strHex(pubKey)
|
||||
<< " contained untrusted validator manifest";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (auto const r = validatorManifests_.applyManifest (std::move(*m));
|
||||
if (auto const r = validatorManifests_.applyManifest(std::move(*m));
|
||||
r == ManifestDisposition::invalid)
|
||||
{
|
||||
JLOG (j_.warn()) <<
|
||||
"List for " << strHex(pubKey) <<
|
||||
" contained invalid validator manifest";
|
||||
JLOG(j_.warn()) << "List for " << strHex(pubKey)
|
||||
<< " contained invalid validator manifest";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,10 +451,9 @@ ValidatorList::loadLists()
|
||||
if (publisher.available)
|
||||
continue;
|
||||
|
||||
boost::filesystem::path const filename =
|
||||
GetCacheFileName(pubKey);
|
||||
boost::filesystem::path const filename = GetCacheFileName(pubKey);
|
||||
|
||||
auto const fullPath{ canonical(filename, ec) };
|
||||
auto const fullPath{canonical(filename, ec)};
|
||||
if (ec)
|
||||
continue;
|
||||
|
||||
@@ -488,10 +468,9 @@ ValidatorList::loadLists()
|
||||
continue;
|
||||
|
||||
std::string const prefix = [&fullPath]() {
|
||||
#if _MSC_VER // MSVC: Windows paths need a leading / added
|
||||
#if _MSC_VER // MSVC: Windows paths need a leading / added
|
||||
{
|
||||
return fullPath.root_path() == "/"s ?
|
||||
"file://" : "file:///";
|
||||
return fullPath.root_path() == "/"s ? "file://" : "file:///";
|
||||
}
|
||||
#else
|
||||
{
|
||||
@@ -508,7 +487,7 @@ ValidatorList::loadLists()
|
||||
}
|
||||
|
||||
ListDisposition
|
||||
ValidatorList::verify (
|
||||
ValidatorList::verify(
|
||||
Json::Value& list,
|
||||
PublicKey& pubKey,
|
||||
std::string const& manifest,
|
||||
@@ -517,35 +496,34 @@ ValidatorList::verify (
|
||||
{
|
||||
auto m = deserializeManifest(base64_decode(manifest));
|
||||
|
||||
if (! m || ! publisherLists_.count (m->masterKey))
|
||||
if (!m || !publisherLists_.count(m->masterKey))
|
||||
return ListDisposition::untrusted;
|
||||
|
||||
pubKey = m->masterKey;
|
||||
auto const revoked = m->revoked();
|
||||
|
||||
auto const result = publisherManifests_.applyManifest (
|
||||
std::move(*m));
|
||||
auto const result = publisherManifests_.applyManifest(std::move(*m));
|
||||
|
||||
if (revoked && result == ManifestDisposition::accepted)
|
||||
{
|
||||
removePublisherList (pubKey);
|
||||
publisherLists_.erase (pubKey);
|
||||
removePublisherList(pubKey);
|
||||
publisherLists_.erase(pubKey);
|
||||
}
|
||||
|
||||
if (revoked || result == ManifestDisposition::invalid)
|
||||
return ListDisposition::untrusted;
|
||||
|
||||
auto const sig = strUnHex(signature);
|
||||
auto const data = base64_decode (blob);
|
||||
if (! sig ||
|
||||
! ripple::verify (
|
||||
auto const data = base64_decode(blob);
|
||||
if (!sig ||
|
||||
!ripple::verify(
|
||||
publisherManifests_.getSigningKey(pubKey),
|
||||
makeSlice(data),
|
||||
makeSlice(*sig)))
|
||||
return ListDisposition::invalid;
|
||||
|
||||
Json::Reader r;
|
||||
if (! r.parse (data, list))
|
||||
if (!r.parse(data, list))
|
||||
return ListDisposition::invalid;
|
||||
|
||||
if (list.isMember("sequence") && list["sequence"].isInt() &&
|
||||
@@ -570,79 +548,77 @@ ValidatorList::verify (
|
||||
}
|
||||
|
||||
bool
|
||||
ValidatorList::listed (
|
||||
PublicKey const& identity) const
|
||||
ValidatorList::listed(PublicKey const& identity) const
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};
|
||||
|
||||
auto const pubKey = validatorManifests_.getMasterKey (identity);
|
||||
return keyListings_.find (pubKey) != keyListings_.end ();
|
||||
auto const pubKey = validatorManifests_.getMasterKey(identity);
|
||||
return keyListings_.find(pubKey) != keyListings_.end();
|
||||
}
|
||||
|
||||
bool
|
||||
ValidatorList::trusted (PublicKey const& identity) const
|
||||
ValidatorList::trusted(PublicKey const& identity) const
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};
|
||||
|
||||
auto const pubKey = validatorManifests_.getMasterKey (identity);
|
||||
return trustedMasterKeys_.find (pubKey) != trustedMasterKeys_.end();
|
||||
auto const pubKey = validatorManifests_.getMasterKey(identity);
|
||||
return trustedMasterKeys_.find(pubKey) != trustedMasterKeys_.end();
|
||||
}
|
||||
|
||||
boost::optional<PublicKey>
|
||||
ValidatorList::getListedKey (
|
||||
PublicKey const& identity) const
|
||||
ValidatorList::getListedKey(PublicKey const& identity) const
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};
|
||||
|
||||
auto const pubKey = validatorManifests_.getMasterKey (identity);
|
||||
if (keyListings_.find (pubKey) != keyListings_.end ())
|
||||
auto const pubKey = validatorManifests_.getMasterKey(identity);
|
||||
if (keyListings_.find(pubKey) != keyListings_.end())
|
||||
return pubKey;
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
boost::optional<PublicKey>
|
||||
ValidatorList::getTrustedKey (PublicKey const& identity) const
|
||||
ValidatorList::getTrustedKey(PublicKey const& identity) const
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};
|
||||
|
||||
auto const pubKey = validatorManifests_.getMasterKey (identity);
|
||||
if (trustedMasterKeys_.find (pubKey) != trustedMasterKeys_.end())
|
||||
auto const pubKey = validatorManifests_.getMasterKey(identity);
|
||||
if (trustedMasterKeys_.find(pubKey) != trustedMasterKeys_.end())
|
||||
return pubKey;
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
bool
|
||||
ValidatorList::trustedPublisher (PublicKey const& identity) const
|
||||
ValidatorList::trustedPublisher(PublicKey const& identity) const
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};
|
||||
return identity.size() && publisherLists_.count (identity);
|
||||
return identity.size() && publisherLists_.count(identity);
|
||||
}
|
||||
|
||||
PublicKey
|
||||
ValidatorList::localPublicKey () const
|
||||
ValidatorList::localPublicKey() const
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};
|
||||
return localPubKey_;
|
||||
}
|
||||
|
||||
bool
|
||||
ValidatorList::removePublisherList (PublicKey const& publisherKey)
|
||||
ValidatorList::removePublisherList(PublicKey const& publisherKey)
|
||||
{
|
||||
auto const iList = publisherLists_.find (publisherKey);
|
||||
if (iList == publisherLists_.end ())
|
||||
auto const iList = publisherLists_.find(publisherKey);
|
||||
if (iList == publisherLists_.end())
|
||||
return false;
|
||||
|
||||
JLOG (j_.debug()) <<
|
||||
"Removing validator list for publisher " << strHex(publisherKey);
|
||||
JLOG(j_.debug()) << "Removing validator list for publisher "
|
||||
<< strHex(publisherKey);
|
||||
|
||||
for (auto const& val : iList->second.list)
|
||||
{
|
||||
auto const& iVal = keyListings_.find (val);
|
||||
auto const& iVal = keyListings_.find(val);
|
||||
if (iVal == keyListings_.end())
|
||||
continue;
|
||||
|
||||
if (iVal->second <= 1)
|
||||
keyListings_.erase (iVal);
|
||||
keyListings_.erase(iVal);
|
||||
else
|
||||
--iVal->second;
|
||||
}
|
||||
@@ -720,12 +696,10 @@ ValidatorList::getJson() const
|
||||
PublicKey local;
|
||||
Json::Value& jLocalStaticKeys =
|
||||
(res[jss::local_static_keys] = Json::arrayValue);
|
||||
if (auto it = publisherLists_.find(local);
|
||||
it != publisherLists_.end())
|
||||
if (auto it = publisherLists_.find(local); it != publisherLists_.end())
|
||||
{
|
||||
for (auto const& key : it->second.list)
|
||||
jLocalStaticKeys.append(
|
||||
toBase58(TokenType::NodePublic, key));
|
||||
jLocalStaticKeys.append(toBase58(TokenType::NodePublic, key));
|
||||
}
|
||||
|
||||
// Publisher lists
|
||||
@@ -733,13 +707,13 @@ ValidatorList::getJson() const
|
||||
(res[jss::publisher_lists] = Json::arrayValue);
|
||||
for (auto const& p : publisherLists_)
|
||||
{
|
||||
if(local == p.first)
|
||||
if (local == p.first)
|
||||
continue;
|
||||
Json::Value& curr = jPublisherLists.append(Json::objectValue);
|
||||
curr[jss::pubkey_publisher] = strHex(p.first);
|
||||
curr[jss::available] = p.second.available;
|
||||
curr[jss::uri] = p.second.siteUri;
|
||||
if(p.second.expiration != TimeKeeper::time_point{})
|
||||
if (p.second.expiration != TimeKeeper::time_point{})
|
||||
{
|
||||
curr[jss::seq] = static_cast<Json::UInt>(p.second.sequence);
|
||||
curr[jss::expiration] = to_string(p.second.expiration);
|
||||
@@ -762,38 +736,38 @@ ValidatorList::getJson() const
|
||||
|
||||
// signing keys
|
||||
Json::Value& jSigningKeys = (res[jss::signing_keys] = Json::objectValue);
|
||||
validatorManifests_.for_each_manifest(
|
||||
[&jSigningKeys, this](Manifest const& manifest) {
|
||||
|
||||
auto it = keyListings_.find(manifest.masterKey);
|
||||
if (it != keyListings_.end())
|
||||
{
|
||||
jSigningKeys[toBase58(
|
||||
TokenType::NodePublic, manifest.masterKey)] =
|
||||
toBase58(TokenType::NodePublic, manifest.signingKey);
|
||||
}
|
||||
});
|
||||
validatorManifests_.for_each_manifest([&jSigningKeys,
|
||||
this](Manifest const& manifest) {
|
||||
auto it = keyListings_.find(manifest.masterKey);
|
||||
if (it != keyListings_.end())
|
||||
{
|
||||
jSigningKeys[toBase58(TokenType::NodePublic, manifest.masterKey)] =
|
||||
toBase58(TokenType::NodePublic, manifest.signingKey);
|
||||
}
|
||||
});
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
ValidatorList::for_each_listed (
|
||||
ValidatorList::for_each_listed(
|
||||
std::function<void(PublicKey const&, bool)> func) const
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};
|
||||
|
||||
for (auto const& v : keyListings_)
|
||||
func (v.first, trusted(v.first));
|
||||
func(v.first, trusted(v.first));
|
||||
}
|
||||
|
||||
void
|
||||
ValidatorList::for_each_available (
|
||||
std::function<void(std::string const& manifest,
|
||||
std::string const& blob, std::string const& signature,
|
||||
std::uint32_t version,
|
||||
PublicKey const& pubKey, std::size_t sequence,
|
||||
uint256 const& hash)> func) const
|
||||
ValidatorList::for_each_available(std::function<void(
|
||||
std::string const& manifest,
|
||||
std::string const& blob,
|
||||
std::string const& signature,
|
||||
std::uint32_t version,
|
||||
PublicKey const& pubKey,
|
||||
std::size_t sequence,
|
||||
uint256 const& hash)> func) const
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};
|
||||
|
||||
@@ -801,8 +775,14 @@ ValidatorList::for_each_available (
|
||||
{
|
||||
if (!pl.available)
|
||||
continue;
|
||||
func(pl.rawManifest, pl.rawBlob, pl.rawSignature, pl.rawVersion,
|
||||
key, pl.sequence, pl.hash);
|
||||
func(
|
||||
pl.rawManifest,
|
||||
pl.rawBlob,
|
||||
pl.rawSignature,
|
||||
pl.rawVersion,
|
||||
key,
|
||||
pl.sequence,
|
||||
pl.hash);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -811,12 +791,12 @@ ValidatorList::getAvailable(boost::beast::string_view const& pubKey)
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};
|
||||
|
||||
auto const keyBlob = strViewUnHex (pubKey);
|
||||
auto const keyBlob = strViewUnHex(pubKey);
|
||||
|
||||
if (! keyBlob || ! publicKeyType(makeSlice(*keyBlob)))
|
||||
if (!keyBlob || !publicKeyType(makeSlice(*keyBlob)))
|
||||
{
|
||||
JLOG (j_.info()) <<
|
||||
"Invalid requested validator list publisher key: " << pubKey;
|
||||
JLOG(j_.info()) << "Invalid requested validator list publisher key: "
|
||||
<< pubKey;
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -824,8 +804,7 @@ ValidatorList::getAvailable(boost::beast::string_view const& pubKey)
|
||||
|
||||
auto iter = publisherLists_.find(id);
|
||||
|
||||
if (iter == publisherLists_.end()
|
||||
|| !iter->second.available)
|
||||
if (iter == publisherLists_.end() || !iter->second.available)
|
||||
return {};
|
||||
|
||||
Json::Value value(Json::objectValue);
|
||||
@@ -839,14 +818,13 @@ ValidatorList::getAvailable(boost::beast::string_view const& pubKey)
|
||||
}
|
||||
|
||||
std::size_t
|
||||
ValidatorList::calculateQuorum (
|
||||
std::size_t trusted, std::size_t seen)
|
||||
ValidatorList::calculateQuorum(std::size_t trusted, std::size_t seen)
|
||||
{
|
||||
// Do not use achievable quorum until lists from all configured
|
||||
// publishers are available
|
||||
for (auto const& list : publisherLists_)
|
||||
{
|
||||
if (! list.second.available)
|
||||
if (!list.second.available)
|
||||
return std::numeric_limits<std::size_t>::max();
|
||||
}
|
||||
|
||||
@@ -888,10 +866,8 @@ ValidatorList::calculateQuorum (
|
||||
{
|
||||
quorum = *minimumQuorum_;
|
||||
|
||||
JLOG (j_.warn())
|
||||
<< "Using unsafe quorum of "
|
||||
<< quorum
|
||||
<< " as specified in the command line";
|
||||
JLOG(j_.warn()) << "Using unsafe quorum of " << quorum
|
||||
<< " as specified in the command line";
|
||||
}
|
||||
|
||||
return quorum;
|
||||
@@ -915,8 +891,7 @@ ValidatorList::updateTrusted(hash_set<NodeID> const& seenValidators)
|
||||
auto it = trustedMasterKeys_.cbegin();
|
||||
while (it != trustedMasterKeys_.cend())
|
||||
{
|
||||
if (!keyListings_.count(*it) ||
|
||||
validatorManifests_.revoked(*it))
|
||||
if (!keyListings_.count(*it) || validatorManifests_.revoked(*it))
|
||||
{
|
||||
trustChanges.removed.insert(calcNodeID(*it));
|
||||
it = trustedMasterKeys_.erase(it);
|
||||
@@ -943,27 +918,25 @@ ValidatorList::updateTrusted(hash_set<NodeID> const& seenValidators)
|
||||
trustedSigningKeys_.insert(validatorManifests_.getSigningKey(k));
|
||||
}
|
||||
|
||||
JLOG (j_.debug())
|
||||
JLOG(j_.debug())
|
||||
<< trustedMasterKeys_.size() << " of " << keyListings_.size()
|
||||
<< " listed validators eligible for inclusion in the trusted set";
|
||||
|
||||
quorum_ = calculateQuorum (trustedMasterKeys_.size(), seenValidators.size());
|
||||
quorum_ = calculateQuorum(trustedMasterKeys_.size(), seenValidators.size());
|
||||
|
||||
JLOG(j_.debug())
|
||||
<< "Using quorum of " << quorum_ << " for new set of "
|
||||
<< trustedMasterKeys_.size() << " trusted validators ("
|
||||
<< trustChanges.added.size() << " added, "
|
||||
<< trustChanges.removed.size() << " removed)";
|
||||
JLOG(j_.debug()) << "Using quorum of " << quorum_ << " for new set of "
|
||||
<< trustedMasterKeys_.size() << " trusted validators ("
|
||||
<< trustChanges.added.size() << " added, "
|
||||
<< trustChanges.removed.size() << " removed)";
|
||||
|
||||
if (trustedMasterKeys_.size() < quorum_)
|
||||
{
|
||||
JLOG (j_.warn())
|
||||
<< "New quorum of " << quorum_
|
||||
<< " exceeds the number of trusted validators ("
|
||||
<< trustedMasterKeys_.size() << ")";
|
||||
JLOG(j_.warn()) << "New quorum of " << quorum_
|
||||
<< " exceeds the number of trusted validators ("
|
||||
<< trustedMasterKeys_.size() << ")";
|
||||
}
|
||||
|
||||
return trustChanges;
|
||||
}
|
||||
|
||||
} // ripple
|
||||
} // namespace ripple
|
||||
|
||||
Reference in New Issue
Block a user