1#include <xrpld/app/misc/ValidatorList.h>
2#include <xrpld/overlay/Overlay.h>
4#include <xrpl/basics/FileUtilities.h>
5#include <xrpl/basics/Slice.h>
6#include <xrpl/basics/StringUtilities.h>
7#include <xrpl/basics/base64.h>
8#include <xrpl/core/HashRouter.h>
9#include <xrpl/json/json_reader.h>
10#include <xrpl/protocol/PublicKey.h>
11#include <xrpl/protocol/STValidation.h>
12#include <xrpl/protocol/digest.h>
13#include <xrpl/protocol/jss.h>
14#include <xrpl/protocol/messages.h>
15#include <xrpl/server/NetworkOPs.h>
17#include <boost/regex.hpp>
35 return "same_sequence";
39 return "known_sequence";
41 return "unsupported_version";
62 : publisherKey(key), status(stat), sequence(seq)
84 dispositions[disp] +=
count;
92 : message(message_), hash(hash_), numVLs(num_)
110 ,
quorum_(minimumQuorum.value_or(1))
123 static boost::regex
const re(
137 JLOG(
j_.
debug()) <<
"Loading configured trusted validator list publisher keys";
140 for (
auto const& key : publisherKeys)
142 JLOG(
j_.
trace()) <<
"Processing '" << key <<
"'";
148 JLOG(
j_.
error()) <<
"Invalid validator list publisher key: " << key;
157 JLOG(
j_.
warn()) <<
"Configured validator list publisher key is revoked: " << key;
163 JLOG(
j_.
warn()) <<
"Duplicate validator list publisher key: " << key;
177 "xrpl::ValidatorList::load : list threshold inside range");
201 JLOG(
j_.
debug()) <<
"Added own master key "
206 JLOG(
j_.
debug()) <<
"Loading configured validator keys";
209 for (
auto const& n : configKeys)
211 JLOG(
j_.
trace()) <<
"Processing '" << n <<
"'";
215 if (!boost::regex_match(n,
match, re))
217 JLOG(
j_.
error()) <<
"Malformed entry: '" << n <<
"'";
225 JLOG(
j_.
error()) <<
"Invalid node identity: " <<
match[1];
236 JLOG(
j_.
warn()) <<
"Duplicate node identity: " <<
match[1];
254boost::filesystem::path
282 "xrpl::ValidatorList::buildFileData : valid publisher list input");
283 auto const effectiveVersion = forceVersion ? *forceVersion : pubCollection.
rawVersion;
286 value[jss::version] = effectiveVersion;
287 value[jss::public_key] = pubKey;
289 switch (effectiveVersion)
293 value[jss::blob] =
current.rawBlob;
294 value[jss::signature] =
current.rawSignature;
298 value[jss::manifest] = *
current.rawManifest;
307 blob[jss::blob] = pubList.rawBlob;
308 blob[jss::signature] = pubList.rawSignature;
309 if (pubList.rawManifest && *pubList.rawManifest != outerManifest)
310 blob[jss::manifest] = *pubList.rawManifest;
320 value[jss::blobs_v2] = std::move(blobs);
324 JLOG(j.
trace()) <<
"Invalid VL version provided: " << effectiveVersion;
340 boost::system::error_code ec;
347 value[jss::refresh_interval] = 24 * 60;
354 JLOG(
j_.
error()) <<
"Problem writing " << filename <<
" " << ec.value() <<
": "
376 result.
size() == 1,
"xrpl::ValidatorList::parseBlobs : single element result");
390 auto const& blobs = body[jss::blobs_v2];
392 for (
auto const& blobInfo : blobs)
394 if (!blobInfo.isObject() || !blobInfo.isMember(jss::signature) ||
395 !blobInfo[jss::signature].isString() || !blobInfo.isMember(jss::blob) ||
396 !blobInfo[jss::blob].isString())
399 info.
blob = blobInfo[jss::blob].asString();
400 info.
signature = blobInfo[jss::signature].asString();
401 if (blobInfo.isMember(jss::manifest))
403 if (!blobInfo[jss::manifest].isString())
405 info.
manifest = blobInfo[jss::manifest].asString();
409 result.
size() == blobs.size(),
410 "xrpl::ValidatorList::parseBlobs(version, Jason::Value) : "
411 "result size matches");
421 return {{body.blob(), body.signature(), {}}};
431 result.
reserve(body.blobs_size());
432 for (
auto const& blob : body.blobs())
435 info.
blob = blob.blob();
437 if (blob.has_manifest())
443 result.
size() == body.blobs_size(),
444 "xrpl::ValidatorList::parseBlobs(TMValidatorList) : result size "
452 protocol::TMValidatorListCollection
const& largeMsg,
460 protocol::TMValidatorListCollection
const& largeMsg,
465 if (begin == 0 && end == 0)
466 end = largeMsg.blobs_size();
467 XRPL_ASSERT(begin < end,
"xrpl::splitMessage : valid inputs");
471 auto mid = (begin + end) / 2;
481 protocol::TMValidatorListCollection
const& largeMsg,
488 if (end - begin == 1)
490 protocol::TMValidatorList smallMsg;
491 smallMsg.set_version(1);
492 smallMsg.set_manifest(largeMsg.manifest());
494 auto const& blob = largeMsg.blobs(begin);
495 smallMsg.set_blob(blob.blob());
496 smallMsg.set_signature(blob.signature());
498 if (blob.has_manifest())
499 smallMsg.set_manifest(blob.manifest());
503 "xrpl::splitMessageParts : maximum message size");
509 return messages.
back().numVLs;
514 smallMsg->set_version(largeMsg.version());
515 smallMsg->set_manifest(largeMsg.manifest());
519 *smallMsg->add_blobs() = largeMsg.blobs(i);
526 return splitMessage(messages, largeMsg, maxSize, begin, end);
532 smallMsg->blobs_size());
533 return messages.
back().numVLs;
547 "xrpl::buildValidatorListMessage(ValidatorBlobInfo) : empty messages "
549 protocol::TMValidatorList msg;
551 auto const version = 1;
553 msg.set_blob(currentBlob.
blob);
554 msg.set_signature(currentBlob.
signature);
556 msg.set_version(version);
560 "xrpl::buildValidatorListMessage(ValidatorBlobInfo) : maximum "
580 "xrpl::buildValidatorListMessage(std::map<std::size_t, "
581 "ValidatorBlobInfo>) : empty messages input");
582 protocol::TMValidatorListCollection msg;
583 auto const version = rawVersion < 2 ? 2 : rawVersion;
584 msg.set_version(version);
585 msg.set_manifest(rawManifest);
587 for (
auto const& [sequence, blobInfo] : blobInfos)
589 if (sequence <= peerSequence)
591 protocol::ValidatorBlobInfo& blob = *msg.add_blobs();
592 blob.set_blob(blobInfo.blob);
593 blob.set_signature(blobInfo.signature);
594 if (blobInfo.manifest)
595 blob.set_manifest(*blobInfo.manifest);
598 msg.blobs_size() > 0,
599 "xrpl::buildValidatorListMessage(std::map<std::size_t, "
600 "ValidatorBlobInfo>) : minimum message blobs");
611 return messages.
back().numVLs;
629 "xrpl::ValidatorList::buildValidatorListMessages : empty messages "
631 auto const& [currentSeq, currentBlob] = *blobInfos.
begin();
634 return total + m.numVLs;
636 if (messageVersion == 2 && peerSequence < maxSequence)
639 if (messages.
empty())
642 messages, peerSequence, rawVersion, rawManifest, blobInfos, maxSize);
643 if (messages.
empty())
652 return {maxSequence, numVLs};
654 if (messageVersion == 1 && peerSequence < currentSeq)
657 if (messages.
empty())
662 currentBlob.manifest ? *currentBlob.manifest : rawManifest,
665 if (messages.
empty())
674 return {currentSeq, numVLs};
702 if (messageVersion == 0u)
705 messageVersion, peerSequence, maxSequence, rawVersion, rawManifest, blobInfos, messages);
706 if (newPeerSequence != 0u)
710 "xrpl::ValidatorList::sendValidatorList : non-empty messages "
716 for (
auto const& message : messages)
720 peer.
send(message.message);
728 sent || messages.
size() == 1,
729 "xrpl::ValidatorList::sendValidatorList : sent or one message");
732 if (messageVersion > 1)
734 JLOG(j.
debug()) <<
"Sent " << messages.
size()
735 <<
" validator list collection(s) containing " << numVLs
736 <<
" validator list(s) for " <<
strHex(publisherKey)
737 <<
" with sequence range " << peerSequence <<
", "
738 << newPeerSequence <<
" to " << peer.
fingerprint();
744 "xrpl::ValidatorList::sendValidatorList : one validator "
746 JLOG(j.
debug()) <<
"Sent validator list for " <<
strHex(publisherKey)
747 <<
" with sequence " << newPeerSequence <<
" to "
790 for (
auto const& [sequence, vl] : remaining)
792 blobInfos[sequence] = {vl.rawBlob, vl.rawSignature, vl.rawManifest};
837 "xrpl::ValidatorList::broadcastBlobs : valid sequence");
842 if (!toSkip->contains(peer->id()))
844 auto const peerSequence = peer->publisherListSequence(publisherKey).value_or(0);
845 if (peerSequence < maxSequence)
847 if (blobInfos.
empty())
859 v2 ? messages2[peerSequence] : messages1,
864 hashRouter.addSuppressionPeer(hash, peer->id());
883 auto const disposition = result.bestDisposition();
915 *result.publisherKey,
917 *pubCollection.maxSequence,
942 for (
auto const& blobInfo : blobs)
958 stats.mergeDispositions(result);
959 result = std::move(stats);
973 auto& remaining = pubCollection.remaining;
974 auto const&
current = pubCollection.current;
975 for (
auto iter = remaining.begin(); iter != remaining.end();)
979 next == remaining.end() || next->first > iter->first,
980 "xrpl::ValidatorList::applyLists : next is valid");
981 if (iter->first <=
current.sequence ||
982 (next != remaining.end() && next->second.validFrom <= iter->second.validFrom))
984 iter = remaining.erase(iter);
994 pubCollection.fullHash =
sha512Half(pubCollection);
996 result.
sequence = *pubCollection.maxSequence;
1012 auto iNew = publisherList.
begin();
1013 auto iOld = oldList.
begin();
1014 while (iNew != publisherList.
end() || iOld != oldList.
end())
1016 if (iOld == oldList.
end() || (iNew != publisherList.
end() && *iNew < *iOld))
1022 else if (iNew == publisherList.
end() || (iOld != oldList.
end() && *iOld < *iNew))
1042 if (publisherList.
empty())
1044 JLOG(
j_.
warn()) <<
"No validator keys included in valid list";
1047 for (
auto const& valManifest : manifests)
1054 <<
" contained untrusted validator manifest";
1062 <<
" contained invalid validator manifest";
1078 using namespace std::string_literals;
1081 auto const&
manifest = localManifest ? *localManifest : globalManifest;
1085 JLOG(
j_.
warn()) <<
"UNL manifest cannot be deserialized";
1089 auto [result, pubKeyOpt] =
verify(lock, list, std::move(*m), blob, signature);
1093 JLOG(
j_.
warn()) <<
"UNL manifest is signed with an unrecognized master public key";
1104 UNREACHABLE(
"xrpl::ValidatorList::applyList : invalid public key type");
1115 if (pubCollection.maxSequence &&
1122 result, pubKey, pubCollection.status, *pubCollection.maxSequence};
1130 auto const sequence = list[jss::sequence].
asUInt();
1139 pubCollection.rawManifest = globalManifest;
1140 if (!pubCollection.maxSequence || sequence > *pubCollection.maxSequence)
1141 pubCollection.maxSequence = sequence;
1143 Json::Value const& newList = list[jss::validators];
1145 if (
accepted && pubCollection.remaining.contains(sequence))
1152 auto& publisher = pubCollection.current;
1154 oldList = std::move(pubCollection.current.list);
1156 publisher = std::move(pubCollection.remaining[sequence]);
1158 pubCollection.remaining.erase(sequence);
1161 publisher.sequence == sequence,
1162 "xrpl::ValidatorList::applyList : publisher sequence match");
1166 auto& publisher =
accepted ? pubCollection.current : pubCollection.remaining[sequence];
1167 publisher.sequence = sequence;
1169 list.
isMember(jss::effective) ? list[jss::effective].
asUInt() : 0}};
1170 publisher.validUntil =
1172 publisher.siteUri = std::move(siteUri);
1173 publisher.rawBlob = blob;
1174 publisher.rawSignature = signature;
1175 publisher.rawManifest = localManifest;
1177 publisher.hash = *hash;
1183 oldList = std::move(publisherList);
1185 publisherList.
clear();
1187 for (
auto const& val : newList)
1189 if (val.isObject() && val.isMember(jss::validation_public_key) &&
1190 val[jss::validation_public_key].isString())
1193 strUnHex(val[jss::validation_public_key].asString());
1198 <<
"Invalid node identity: " << val[jss::validation_public_key].asString();
1205 if (val.isMember(jss::manifest) && val[jss::manifest].isString())
1206 manifests.
push_back(val[jss::manifest].asString());
1215 pubCollection.rawVersion =
std::max(pubCollection.rawVersion, version);
1216 if (!pubCollection.remaining.empty())
1220 pubCollection.rawVersion =
std::max(pubCollection.rawVersion, 2u);
1224 result, pubKey, pubCollection.status, *pubCollection.maxSequence};
1237 using namespace std::string_literals;
1238 using namespace boost::filesystem;
1239 using namespace boost::system::errc;
1247 boost::system::error_code ec;
1254 auto const fullPath{
canonical(filename, ec)};
1258 auto size = file_size(fullPath, ec);
1259 if (!ec && (size == 0u))
1271 return fullPath.root_path() ==
"/"s ?
"file://" :
"file:///";
1317 auto const sig =
strUnHex(signature);
1323 if (!r.
parse(data, list))
1326 if (list.
isMember(jss::sequence) && list[jss::sequence].
isInt() &&
1327 list.
isMember(jss::expiration) && list[jss::expiration].
isInt() &&
1328 (!list.
isMember(jss::effective) || list[jss::effective].
isInt()) &&
1331 auto const sequence = list[jss::sequence].
asUInt();
1333 list.
isMember(jss::effective) ? list[jss::effective].
asUInt() : 0}};
1334 auto const validUntil =
1338 if (validUntil <= validFrom)
1342 if (sequence < listCollection.current.sequence)
1346 if (sequence == listCollection.current.sequence)
1350 if (validUntil <= now)
1354 if (validFrom > now)
1366 return !listCollection.maxSequence || sequence > *listCollection.maxSequence ||
1367 (!listCollection.remaining.contains(sequence) &&
1368 validFrom < listCollection.remaining.at(*listCollection.maxSequence).validFrom)
1401 return trusted(read_lock, identity);
1455 "xrpl::ValidatorList::removePublisherList : valid reason input");
1460 JLOG(
j_.
debug()) <<
"Removing validator list for publisher " <<
strHex(publisherKey);
1462 for (
auto const& val : iList->second.current.list)
1468 if (iVal->second <= 1)
1478 iList->second.current.list.clear();
1479 iList->second.status = reason;
1494 return count(read_lock);
1504 auto const&
current = collection.current;
1513 auto chainedExpiration =
current.validUntil;
1514 for (
auto const& [sequence, check] : collection.remaining)
1517 if (check.validFrom <= chainedExpiration)
1519 chainedExpiration = check.validUntil;
1528 if (!res || chainedExpiration < *res)
1530 res = chainedExpiration;
1534 if (!localPublisherList.list.empty())
1536 PublisherList
const collection = localPublisherList;
1538 auto const&
current = collection;
1539 auto chainedExpiration =
current.validUntil;
1542 if (!res || chainedExpiration < *res)
1544 res = chainedExpiration;
1551ValidatorList::expires()
const
1554 return expires(read_lock);
1558ValidatorList::getJson()
const
1564 res[jss::validation_quorum] =
static_cast<Json::UInt>(quorum_);
1569 x[jss::count] =
static_cast<Json::UInt>(count(read_lock));
1571 if (
auto when = expires(read_lock))
1573 if (*when == TimeKeeper::time_point::max())
1575 x[jss::expiration] =
"never";
1576 x[jss::status] =
"active";
1580 x[jss::expiration] = to_string(*when);
1582 if (*when > timeKeeper_.now())
1584 x[jss::status] =
"active";
1588 x[jss::status] =
"expired";
1594 x[jss::status] =
"unknown";
1595 x[jss::expiration] =
"unknown";
1598 x[jss::validator_list_threshold] =
Json::UInt(listThreshold_);
1604 for (
auto const& key : localPublisherList.list)
1609 for (
auto const& [publicKey, pubCollection] : publisherLists_)
1612 curr[jss::pubkey_publisher] =
strHex(publicKey);
1613 curr[jss::available] = pubCollection.status == PublisherStatus::available;
1616 target[jss::uri] = publisherList.
siteUri;
1620 target[jss::expiration] = to_string(publisherList.
validUntil);
1623 target[jss::effective] = to_string(publisherList.
validFrom);
1625 for (
auto const& key : publisherList.
list)
1631 auto const&
current = pubCollection.current;
1635 curr[jss::version] = pubCollection.rawVersion;
1640 for (
auto const& [sequence, future] : pubCollection.remaining)
1642 using namespace std::chrono_literals;
1646 appendList(future, r);
1649 future.validFrom > timeKeeper_.now() + 600s,
1650 "xrpl::ValidatorList::getJson : minimum valid from");
1652 if (remaining.
size() != 0u)
1653 curr[jss::remaining] = std::move(remaining);
1658 for (
auto const& k : trustedMasterKeys_)
1665 validatorManifests_.for_each_manifest([&jSigningKeys,
this](Manifest
const& manifest) {
1666 auto it = keyListings_.find(manifest.masterKey);
1667 if (it != keyListings_.end() && manifest.signingKey)
1669 jSigningKeys[toBase58(TokenType::NodePublic, manifest.masterKey)] =
1670 toBase58(TokenType::NodePublic, *manifest.signingKey);
1675 if (!negativeUNL_.empty())
1678 for (
auto const& k : negativeUNL_)
1692 for (
auto const& v : keyListings_)
1693 func(v.first, trusted(read_lock, v.first));
1697ValidatorList::for_each_available(
1704 uint256 const& hash)> func)
const
1708 for (
auto const& [key, plCollection] : publisherLists_)
1710 if (plCollection.status != PublisherStatus::available)
1713 plCollection.maxSequence.value_or(0) != 0,
1714 "xrpl::ValidatorList::for_each_available : nonzero maxSequence");
1716 plCollection.rawManifest,
1717 plCollection.rawVersion,
1718 buildBlobInfos(plCollection),
1720 plCollection.maxSequence.value_or(0),
1721 plCollection.fullHash);
1726ValidatorList::getAvailable(
1736 JLOG(j_.
warn()) <<
"Invalid requested validator list publisher key: " << pubKey;
1742 auto const iter = publisherLists_.find(
id);
1744 if (iter == publisherLists_.end() || iter->second.status != PublisherStatus::available)
1753ValidatorList::calculateQuorum(
1759 if (minimumQuorum_ > 0)
1761 JLOG(j_.
warn()) <<
"Using potentially unsafe quorum of " << *minimumQuorum_
1762 <<
" as specified on the command line";
1763 return *minimumQuorum_;
1766 if (!publisherLists_.empty())
1771 for (
auto const& list : publisherLists_)
1773 if (list.second.status != PublisherStatus::available)
1795 auto const errorThreshold =
std::min(
1797 publisherLists_.size() - listThreshold_ + 1);
1799 errorThreshold > 0,
"xrpl::ValidatorList::calculateQuorum : nonzero error threshold");
1843ValidatorList::updateTrusted(
1850 using namespace std::chrono_literals;
1851 if (timeKeeper_.now() > closeTime + 30s)
1852 closeTime = timeKeeper_.now();
1861 for (
auto& [pubKey, collection] : publisherLists_)
1864 auto& remaining = collection.remaining;
1865 auto const firstIter = remaining.begin();
1866 auto iter = firstIter;
1867 if (iter != remaining.end() && iter->second.validFrom <= closeTime)
1871 next != remaining.end() && next->second.validFrom <= closeTime;
1876 "xrpl::ValidatorList::updateTrusted : sequential "
1880 iter != remaining.end(),
1881 "xrpl::ValidatorList::updateTrusted : non-end of "
1885 auto sequence = iter->first;
1886 auto& candidate = iter->second;
1887 auto&
current = collection.current;
1889 candidate.validFrom <= closeTime,
1890 "xrpl::ValidatorList::updateTrusted : maximum time");
1892 auto const oldList =
current.list;
1893 current = std::move(candidate);
1894 if (collection.status != PublisherStatus::available)
1895 collection.status = PublisherStatus::available;
1898 "xrpl::ValidatorList::updateTrusted : sequence match");
1902 if (
current.validUntil <= closeTime)
1905 updatePublisherList(pubKey,
current, oldList, lock);
1912 broadcastBlobs(pubKey, collection, sequence,
current.hash, overlay, hashRouter, j_);
1915 remaining.erase(firstIter,
std::next(iter));
1921 if (collection.status == PublisherStatus::available &&
1922 collection.current.validUntil <= closeTime)
1924 removePublisherList(lock, pubKey, PublisherStatus::expired);
1927 if (collection.status != PublisherStatus::available)
1935 auto it = trustedMasterKeys_.cbegin();
1936 while (it != trustedMasterKeys_.cend())
1938 auto const kit = keyListings_.find(*it);
1939 if (kit == keyListings_.end() ||
1940 kit->second < listThreshold_ ||
1941 validatorManifests_.revoked(*it))
1944 it = trustedMasterKeys_.erase(it);
1949 kit->second >= listThreshold_,
1950 "xrpl::ValidatorList::updateTrusted : count meets threshold");
1955 for (
auto const& val : keyListings_)
1957 if (val.second >= listThreshold_ && !validatorManifests_.revoked(val.first) &&
1958 trustedMasterKeys_.emplace(val.first).second)
1964 if (!trustChanges.
added.empty() || !trustChanges.
removed.empty())
1966 trustedSigningKeys_.clear();
1970 for (
auto const& k : trustedMasterKeys_)
1973 XRPL_ASSERT(signingKey,
"xrpl::ValidatorList::updateTrusted : found signing key");
1974 trustedSigningKeys_.insert(*signingKey);
1978 JLOG(j_.
debug()) << trustedMasterKeys_.size() <<
" of " << keyListings_.size()
1979 <<
" listed validators eligible for inclusion in the trusted set";
1981 auto const unlSize = trustedMasterKeys_.size();
1982 auto effectiveUnlSize = unlSize;
1983 auto seenSize = seenValidators.
size();
1984 if (!negativeUNL_.empty())
1986 for (
auto const& k : trustedMasterKeys_)
1988 if (negativeUNL_.contains(k))
1992 for (
auto const& k : negativeUNL_)
1996 for (
auto const& nid : seenValidators)
2002 quorum_ = calculateQuorum(unlSize, effectiveUnlSize, seenSize);
2004 JLOG(j_.
debug()) <<
"Using quorum of " << quorum_ <<
" for new set of " << unlSize
2005 <<
" trusted validators (" << trustChanges.
added.size() <<
" added, "
2006 << trustChanges.
removed.size() <<
" removed)";
2008 if (unlSize < quorum_)
2010 JLOG(j_.
warn()) <<
"New quorum of " << quorum_
2011 <<
" exceeds the number of trusted validators (" << unlSize <<
")";
2014 if ((!publisherLists_.empty() || !localPublisherList.list.empty()) && unlSize == 0)
2020 return trustChanges;
2024ValidatorList::getTrustedMasterKeys()
const
2027 return trustedMasterKeys_;
2031ValidatorList::getListThreshold()
const
2034 return listThreshold_;
2038ValidatorList::getNegativeUNL()
const
2041 return negativeUNL_;
2048 negativeUNL_ = negUnl;
2055 auto ret = std::move(validations);
2058 if (!negativeUNL_.empty())
2064 [&](
auto const& v) ->
bool {
2065 if (auto const masterKey = getTrustedKey(read_lock, v->getSignerPublic());
2068 return negativeUNL_.contains(*masterKey);
Unserialize a JSON document into a Value.
bool parse(std::string const &document, Value &root)
Read a Value from a JSON document.
Value & append(Value const &value)
Append value to array at the end.
UInt size() const
Number of values in array or object.
std::string toStyledString() const
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
typename Clock::time_point time_point
typename Clock::duration duration
Routing table for objects identified by hash.
std::optional< std::set< PeerShortID > > shouldRelay(uint256 const &key)
Determines whether the hashed item should be relayed.
bool addSuppressionPeer(uint256 const &key, PeerShortID peer)
Remembers manifests with the highest sequence number.
std::optional< PublicKey > getSigningKey(PublicKey const &pk) const
Returns master key's current signing key.
ManifestDisposition applyManifest(Manifest m)
Add manifest to cache.
PublicKey getMasterKey(PublicKey const &pk) const
Returns ephemeral signing key's master public key.
bool revoked(PublicKey const &pk) const
Returns true if master key has been revoked in a manifest.
static std::size_t totalSize(::google::protobuf::Message const &message)
Provides server functionality for clients.
virtual void clearUNLBlocked()=0
virtual void setUNLBlocked()=0
Manages the set of connected peers.
virtual PeerSequence getActivePeers() const =0
Returns a sequence representing the current list of peers.
Represents a peer connection in the overlay.
virtual std::string const & fingerprint() const =0
virtual void setPublisherListSequence(PublicKey const &, std::size_t const)=0
virtual void send(std::shared_ptr< Message > const &m)=0
virtual id_t id() const =0
virtual bool supportsFeature(ProtocolFeature f) const =0
std::size_t size() const noexcept
An immutable linear range of bytes.
Manages various times used by the server.
time_point now() const override
Returns the current time, using the server's clock.
static std::pair< std::size_t, std::size_t > buildValidatorListMessages(std::size_t messageVersion, std::uint64_t peerSequence, std::size_t maxSequence, std::uint32_t rawVersion, std::string const &rawManifest, std::map< std::size_t, ValidatorBlobInfo > const &blobInfos, std::vector< MessageWithHash > &messages, std::size_t maxSize=maximumMessageSize)
static void sendValidatorList(Peer &peer, std::uint64_t peerSequence, PublicKey const &publisherKey, std::size_t maxSequence, std::uint32_t rawVersion, std::string const &rawManifest, std::map< std::size_t, ValidatorBlobInfo > const &blobInfos, HashRouter &hashRouter, beast::Journal j)
static constexpr std::uint32_t supportedListVersions[]
PublisherList localPublisherList
hash_set< PublicKey > trustedMasterKeys_
bool trustedPublisher(PublicKey const &identity) const
Returns true if public key is a trusted publisher.
static constexpr std::size_t maxSupportedBlobs
ValidatorList(ManifestCache &validatorManifests, ManifestCache &publisherManifests, TimeKeeper &timeKeeper, std::string const &databasePath, beast::Journal j, std::optional< std::size_t > minimumQuorum=std::nullopt)
static Json::Value buildFileData(std::string const &pubKey, PublisherListCollection const &pubCollection, beast::Journal j)
Build a Json representation of the collection, suitable for writing to a cache file,...
std::vector< std::string > loadLists()
std::optional< PublicKey > localPubKey_
std::atomic< std::size_t > quorum_
std::pair< ListDisposition, std::optional< PublicKey > > verify(lock_guard const &, Json::Value &list, Manifest manifest, std::string const &blob, std::string const &signature)
Check response for trusted valid published list.
boost::filesystem::path const dataPath_
bool load(std::optional< PublicKey > const &localSigningKey, std::vector< std::string > const &configKeys, std::vector< std::string > const &publisherKeys, std::optional< std::size_t > listThreshold={})
Load configured trusted keys.
bool removePublisherList(lock_guard const &, PublicKey const &publisherKey, PublisherStatus reason)
Stop trusting publisher's list of keys.
PublisherListStats applyLists(std::string const &manifest, std::uint32_t version, std::vector< ValidatorBlobInfo > const &blobs, std::string siteUri, std::optional< uint256 > const &hash={})
Apply multiple published lists of public keys.
std::optional< PublicKey > localPublicKey() const
This function returns the local validator public key or a std::nullopt.
PublisherListStats applyList(std::string const &globalManifest, std::optional< std::string > const &localManifest, std::string const &blob, std::string const &signature, std::uint32_t version, std::string siteUri, std::optional< uint256 > const &hash, lock_guard const &)
Apply published list of public keys.
std::optional< PublicKey > getListedKey(PublicKey const &identity) const
Returns listed master public if public key is included on any lists.
void cacheValidatorFile(lock_guard const &lock, PublicKey const &pubKey) const
Write a JSON UNL to a cache file.
std::optional< std::size_t > minimumQuorum_
static std::vector< ValidatorBlobInfo > parseBlobs(std::uint32_t version, Json::Value const &body)
Pull the blob/signature/manifest information out of the appropriate Json body fields depending on the...
ManifestCache & publisherManifests_
hash_map< PublicKey, std::size_t > keyListings_
std::optional< TimeKeeper::time_point > expires() const
Return the time when the validator list will expire.
static void buildBlobInfos(std::map< std::size_t, ValidatorBlobInfo > &blobInfos, PublisherListCollection const &lists)
ManifestCache & validatorManifests_
std::size_t listThreshold_
static void broadcastBlobs(PublicKey const &publisherKey, PublisherListCollection const &lists, std::size_t maxSequence, uint256 const &hash, Overlay &overlay, HashRouter &hashRouter, beast::Journal j)
std::size_t count() const
Return the number of configured validator list sites.
std::optional< PublicKey > getTrustedKey(PublicKey const &identity) const
Returns master public key if public key is trusted.
void updatePublisherList(PublicKey const &pubKey, PublisherList const ¤t, std::vector< PublicKey > const &oldList, lock_guard const &)
PublisherListStats applyListsAndBroadcast(std::string const &manifest, std::uint32_t version, std::vector< ValidatorBlobInfo > const &blobs, std::string siteUri, uint256 const &hash, Overlay &overlay, HashRouter &hashRouter, NetworkOPs &networkOPs)
Apply multiple published lists of public keys, then broadcast it to all peers that have not seen it o...
boost::filesystem::path getCacheFileName(lock_guard const &, PublicKey const &pubKey) const
Get the filename used for caching UNLs.
bool trusted(PublicKey const &identity) const
Returns true if public key is trusted.
static std::string const filePrefix_
bool listed(PublicKey const &identity) const
Returns true if public key is included on any lists.
hash_map< PublicKey, PublisherListCollection > publisherLists_
T emplace_back(T... args)
@ arrayValue
array value (ordered list)
@ objectValue
object value (collection of name/value pairs).
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::error_code make_error_code(xrpl::TokenCodecErrc e)
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
std::string to_string(base_uint< Bits, Tag > const &a)
std::string strHex(FwdIt begin, FwdIt end)
std::string base64_decode(std::string_view data)
@ unsupported_version
List version is not supported.
@ stale
Trusted publisher key, but seq is too old.
@ untrusted
List signed by untrusted publisher key.
@ same_sequence
Same sequence as current list.
@ pending
List will be valid in the future.
@ known_sequence
Future sequence already seen.
@ expired
List is expired, but has the largest non-pending sequence seen so far.
@ invalid
Invalid format or signature.
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig) noexcept
Verify a signature on a message.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
@ ValidatorListPropagation
@ ValidatorList2Propagation
std::size_t splitMessage(std::vector< ValidatorList::MessageWithHash > &messages, protocol::TMValidatorListCollection const &largeMsg, std::size_t maxSize, std::size_t begin=0, std::size_t end=0)
std::size_t splitMessageParts(std::vector< ValidatorList::MessageWithHash > &messages, protocol::TMValidatorListCollection const &largeMsg, std::size_t maxSize, std::size_t begin, std::size_t end)
@ current
This was a new validation and was added.
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
std::optional< Manifest > deserializeManifest(Slice s, beast::Journal journal)
Constructs Manifest from serialized string.
std::size_t buildValidatorListMessage(std::vector< ValidatorList::MessageWithHash > &messages, std::uint32_t rawVersion, std::string const &rawManifest, ValidatorBlobInfo const ¤tBlob, std::size_t maxSize)
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
NodeID calcNodeID(PublicKey const &)
Calculate the 160-bit node ID from a node public key.
void writeFileContents(boost::system::error_code &ec, boost::filesystem::path const &destPath, std::string const &contents)
std::optional< Blob > strViewUnHex(std::string_view strSrc)
constexpr std::size_t maximumMessageSize
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
@ accepted
Manifest is valid.
@ invalid
Timely, but invalid signature.
Changes in trusted nodes after updating validator list.
hash_set< NodeID > removed
Used to represent the information stored in the blobs_v2 Json array.
std::optional< std::string > manifest
MessageWithHash()=default
std::map< std::size_t, PublisherList > remaining
Describes the result of processing a Validator List (UNL), including some of the information from the...
void mergeDispositions(PublisherListStats const &src)
PublisherListStats()=default
std::optional< PublicKey > publisherKey
ListDisposition worstDisposition() const
std::map< ListDisposition, std::size_t > dispositions
ListDisposition bestDisposition() const
std::vector< PublicKey > list
TimeKeeper::time_point validFrom
TimeKeeper::time_point validUntil