1#include <xrpld/app/misc/HashRouter.h>
2#include <xrpld/app/misc/NetworkOPs.h>
3#include <xrpld/app/misc/ValidatorList.h>
4#include <xrpld/overlay/Overlay.h>
6#include <xrpl/basics/FileUtilities.h>
7#include <xrpl/basics/Slice.h>
8#include <xrpl/basics/StringUtilities.h>
9#include <xrpl/basics/base64.h>
10#include <xrpl/json/json_reader.h>
11#include <xrpl/protocol/PublicKey.h>
12#include <xrpl/protocol/STValidation.h>
13#include <xrpl/protocol/digest.h>
14#include <xrpl/protocol/jss.h>
15#include <xrpl/protocol/messages.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 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");
205 JLOG(
j_.
debug()) <<
"Loading configured validator keys";
208 for (
auto const& n : configKeys)
210 JLOG(
j_.
trace()) <<
"Processing '" << n <<
"'";
214 if (!boost::regex_match(n,
match, re))
216 JLOG(
j_.
error()) <<
"Malformed entry: '" << n <<
"'";
224 JLOG(
j_.
error()) <<
"Invalid node identity: " <<
match[1];
235 JLOG(
j_.
warn()) <<
"Duplicate node identity: " <<
match[1];
253boost::filesystem::path
281 "xrpl::ValidatorList::buildFileData : valid publisher list input");
282 auto const effectiveVersion = forceVersion ? *forceVersion : pubCollection.
rawVersion;
285 value[jss::version] = effectiveVersion;
286 value[jss::public_key] = pubKey;
288 switch (effectiveVersion)
292 value[jss::blob] =
current.rawBlob;
293 value[jss::signature] =
current.rawSignature;
297 value[jss::manifest] = *
current.rawManifest;
305 blob[jss::blob] = pubList.rawBlob;
306 blob[jss::signature] = pubList.rawSignature;
307 if (pubList.rawManifest && *pubList.rawManifest != outerManifest)
308 blob[jss::manifest] = *pubList.rawManifest;
318 value[jss::blobs_v2] = std::move(blobs);
322 JLOG(j.
trace()) <<
"Invalid VL version provided: " << effectiveVersion;
337 boost::system::error_code ec;
344 value[jss::refresh_interval] = 24 * 60;
351 JLOG(
j_.
error()) <<
"Problem writing " << filename <<
" " << ec.value() <<
": " << ec.message();
371 XRPL_ASSERT(result.
size() == 1,
"xrpl::ValidatorList::parseBlobs : single element result");
385 auto const& blobs = body[jss::blobs_v2];
387 for (
auto const& blobInfo : blobs)
389 if (!blobInfo.isObject() || !blobInfo.isMember(jss::signature) ||
390 !blobInfo[jss::signature].isString() || !blobInfo.isMember(jss::blob) ||
391 !blobInfo[jss::blob].isString())
394 info.
blob = blobInfo[jss::blob].asString();
395 info.
signature = blobInfo[jss::signature].asString();
396 if (blobInfo.isMember(jss::manifest))
398 if (!blobInfo[jss::manifest].isString())
400 info.
manifest = blobInfo[jss::manifest].asString();
404 result.
size() == blobs.size(),
405 "xrpl::ValidatorList::parseBlobs(version, Jason::Value) : "
406 "result size matches");
416 return {{body.blob(), body.signature(), {}}};
426 result.
reserve(body.blobs_size());
427 for (
auto const& blob : body.blobs())
430 info.
blob = blob.blob();
432 if (blob.has_manifest())
438 result.
size() == body.blobs_size(),
439 "xrpl::ValidatorList::parseBlobs(TMValidatorList) : result size "
447 protocol::TMValidatorListCollection
const& largeMsg,
455 protocol::TMValidatorListCollection
const& largeMsg,
460 if (begin == 0 && end == 0)
461 end = largeMsg.blobs_size();
462 XRPL_ASSERT(begin < end,
"xrpl::splitMessage : valid inputs");
466 auto mid = (begin + end) / 2;
476 protocol::TMValidatorListCollection
const& largeMsg,
483 if (end - begin == 1)
485 protocol::TMValidatorList smallMsg;
486 smallMsg.set_version(1);
487 smallMsg.set_manifest(largeMsg.manifest());
489 auto const& blob = largeMsg.blobs(begin);
490 smallMsg.set_blob(blob.blob());
491 smallMsg.set_signature(blob.signature());
493 if (blob.has_manifest())
494 smallMsg.set_manifest(blob.manifest());
500 return messages.
back().numVLs;
506 smallMsg->set_version(largeMsg.version());
507 smallMsg->set_manifest(largeMsg.manifest());
511 *smallMsg->add_blobs() = largeMsg.blobs(i);
518 return splitMessage(messages, largeMsg, maxSize, begin, end);
525 smallMsg->blobs_size());
526 return messages.
back().numVLs;
543 "xrpl::buildValidatorListMessage(ValidatorBlobInfo) : empty messages "
545 protocol::TMValidatorList msg;
547 auto const version = 1;
549 msg.set_blob(currentBlob.
blob);
550 msg.set_signature(currentBlob.
signature);
552 msg.set_version(version);
556 "xrpl::buildValidatorListMessage(ValidatorBlobInfo) : maximum "
575 "xrpl::buildValidatorListMessage(std::map<std::size_t, "
576 "ValidatorBlobInfo>) : empty messages input");
577 protocol::TMValidatorListCollection msg;
578 auto const version = rawVersion < 2 ? 2 : rawVersion;
579 msg.set_version(version);
580 msg.set_manifest(rawManifest);
582 for (
auto const& [sequence, blobInfo] : blobInfos)
584 if (sequence <= peerSequence)
586 protocol::ValidatorBlobInfo& blob = *msg.add_blobs();
587 blob.set_blob(blobInfo.blob);
588 blob.set_signature(blobInfo.signature);
589 if (blobInfo.manifest)
590 blob.set_manifest(*blobInfo.manifest);
593 msg.blobs_size() > 0,
594 "xrpl::buildValidatorListMessage(std::map<std::size_t, "
595 "ValidatorBlobInfo>) : minimum message blobs");
605 return messages.
back().numVLs;
624 "xrpl::ValidatorList::buildValidatorListMessages : empty messages "
626 auto const& [currentSeq, currentBlob] = *blobInfos.
begin();
628 return total + m.numVLs;
630 if (messageVersion == 2 && peerSequence < maxSequence)
633 if (messages.
empty())
636 if (messages.
empty())
643 return {maxSequence, numVLs};
645 else if (messageVersion == 1 && peerSequence < currentSeq)
648 if (messages.
empty())
651 messages, rawVersion, currentBlob.manifest ? *currentBlob.manifest : rawManifest, currentBlob, maxSize);
652 if (messages.
empty())
659 return {currentSeq, numVLs};
684 messageVersion, peerSequence, maxSequence, rawVersion, rawManifest, blobInfos, messages);
689 "xrpl::ValidatorList::sendValidatorList : non-empty messages "
695 for (
auto const& message : messages)
699 peer.
send(message.message);
706 XRPL_ASSERT(sent || messages.
size() == 1,
"xrpl::ValidatorList::sendValidatorList : sent or one message");
709 if (messageVersion > 1)
710 JLOG(j.
debug()) <<
"Sent " << messages.
size() <<
" validator list collection(s) containing " << numVLs
711 <<
" validator list(s) for " <<
strHex(publisherKey) <<
" with sequence range "
712 << peerSequence <<
", " << newPeerSequence <<
" to " << peer.
fingerprint();
717 "xrpl::ValidatorList::sendValidatorList : one validator "
719 JLOG(j.
debug()) <<
"Sent validator list for " <<
strHex(publisherKey) <<
" with sequence "
720 << newPeerSequence <<
" to " << peer.
fingerprint();
741 peer, peerSequence, publisherKey, maxSequence, rawVersion, rawManifest, blobInfos, messages, hashRouter, j);
753 for (
auto const& [sequence, vl] : remaining)
755 blobInfos[sequence] = {vl.rawBlob, vl.rawSignature, vl.rawManifest};
800 "xrpl::ValidatorList::broadcastBlobs : valid sequence");
805 if (toSkip->count(peer->id()) == 0)
807 auto const peerSequence = peer->publisherListSequence(publisherKey).value_or(0);
808 if (peerSequence < maxSequence)
810 if (blobInfos.
empty())
821 v2 ? messages2[peerSequence] : messages1,
826 hashRouter.addSuppressionPeer(hash, peer->id());
845 auto const disposition = result.bestDisposition();
876 broadcastBlobs(*result.publisherKey, pubCollection, *pubCollection.maxSequence, hash, overlay, hashRouter,
j_);
896 for (
auto const& blobInfo : blobs)
899 applyList(
manifest, blobInfo.manifest, blobInfo.blob, blobInfo.signature, version, siteUri, hash, lock);
904 stats.mergeDispositions(result);
905 result = std::move(stats);
917 auto& remaining = pubCollection.remaining;
918 auto const&
current = pubCollection.current;
919 for (
auto iter = remaining.begin(); iter != remaining.end();)
923 next == remaining.end() || next->first > iter->first,
924 "xrpl::ValidatorList::applyLists : next is valid");
925 if (iter->first <=
current.sequence ||
926 (next != remaining.end() && next->second.validFrom <= iter->second.validFrom))
928 iter = remaining.erase(iter);
938 pubCollection.fullHash =
sha512Half(pubCollection);
940 result.
sequence = *pubCollection.maxSequence;
956 auto iNew = publisherList.
begin();
957 auto iOld = oldList.
begin();
958 while (iNew != publisherList.
end() || iOld != oldList.
end())
960 if (iOld == oldList.
end() || (iNew != publisherList.
end() && *iNew < *iOld))
966 else if (iNew == publisherList.
end() || (iOld != oldList.
end() && *iOld < *iNew))
982 if (publisherList.
empty())
984 JLOG(
j_.
warn()) <<
"No validator keys included in valid list";
987 for (
auto const& valManifest : manifests)
993 JLOG(
j_.
warn()) <<
"List for " <<
strHex(pubKey) <<
" contained untrusted validator manifest";
999 JLOG(
j_.
warn()) <<
"List for " <<
strHex(pubKey) <<
" contained invalid validator manifest";
1015 using namespace std::string_literals;
1018 auto const&
manifest = localManifest ? *localManifest : globalManifest;
1022 JLOG(
j_.
warn()) <<
"UNL manifest cannot be deserialized";
1026 auto [result, pubKeyOpt] =
verify(lock, list, std::move(*m), blob, signature);
1030 JLOG(
j_.
warn()) <<
"UNL manifest is signed with an unrecognized master public key";
1041 UNREACHABLE(
"xrpl::ValidatorList::applyList : invalid public key type");
1052 if (pubCollection.maxSequence &&
1057 return PublisherListStats{result, pubKey, pubCollection.status, *pubCollection.maxSequence};
1065 auto const sequence = list[jss::sequence].
asUInt();
1069 pubCollection.status =
1071 pubCollection.rawManifest = globalManifest;
1072 if (!pubCollection.maxSequence || sequence > *pubCollection.maxSequence)
1073 pubCollection.maxSequence = sequence;
1075 Json::Value const& newList = list[jss::validators];
1077 if (
accepted && pubCollection.remaining.count(sequence) != 0)
1084 auto& publisher = pubCollection.current;
1086 oldList = std::move(pubCollection.current.list);
1088 publisher = std::move(pubCollection.remaining[sequence]);
1090 pubCollection.remaining.erase(sequence);
1092 XRPL_ASSERT(publisher.sequence == sequence,
"xrpl::ValidatorList::applyList : publisher sequence match");
1096 auto& publisher =
accepted ? pubCollection.current : pubCollection.remaining[sequence];
1097 publisher.sequence = sequence;
1101 publisher.siteUri = std::move(siteUri);
1102 publisher.rawBlob = blob;
1103 publisher.rawSignature = signature;
1104 publisher.rawManifest = localManifest;
1106 publisher.hash = *hash;
1112 oldList = std::move(publisherList);
1114 publisherList.
clear();
1116 for (
auto const& val : newList)
1118 if (val.isObject() && val.isMember(jss::validation_public_key) &&
1119 val[jss::validation_public_key].isString())
1125 JLOG(
j_.
error()) <<
"Invalid node identity: " << val[jss::validation_public_key].asString();
1132 if (val.isMember(jss::manifest) && val[jss::manifest].isString())
1133 manifests.
push_back(val[jss::manifest].asString());
1142 pubCollection.rawVersion =
std::max(pubCollection.rawVersion, version);
1143 if (!pubCollection.remaining.empty())
1147 pubCollection.rawVersion =
std::max(pubCollection.rawVersion, 2u);
1150 PublisherListStats const applyResult{result, pubKey, pubCollection.status, *pubCollection.maxSequence};
1163 using namespace std::string_literals;
1164 using namespace boost::filesystem;
1165 using namespace boost::system::errc;
1173 boost::system::error_code ec;
1180 auto const fullPath{
canonical(filename, ec)};
1184 auto size = file_size(fullPath, ec);
1197 return fullPath.root_path() ==
"/"s ?
"file://" :
"file:///";
1243 auto const sig =
strUnHex(signature);
1249 if (!r.
parse(data, list))
1252 if (list.
isMember(jss::sequence) && list[jss::sequence].
isInt() && list.
isMember(jss::expiration) &&
1253 list[jss::expiration].
isInt() && (!list.
isMember(jss::effective) || list[jss::effective].
isInt()) &&
1256 auto const sequence = list[jss::sequence].
asUInt();
1262 if (validUntil <= validFrom)
1264 else if (sequence < listCollection.current.sequence)
1266 else if (sequence == listCollection.current.sequence)
1268 else if (validUntil <= now)
1270 else if (validFrom > now)
1281 return !listCollection.maxSequence || sequence > *listCollection.maxSequence ||
1282 (listCollection.remaining.count(sequence) == 0 &&
1283 validFrom < listCollection.remaining.at(*listCollection.maxSequence).validFrom)
1315 return trusted(read_lock, identity);
1369 "xrpl::ValidatorList::removePublisherList : valid reason input");
1374 JLOG(
j_.
debug()) <<
"Removing validator list for publisher " <<
strHex(publisherKey);
1376 for (
auto const& val : iList->second.current.list)
1382 if (iVal->second <= 1)
1388 iList->second.current.list.clear();
1389 iList->second.status = reason;
1404 return count(read_lock);
1414 auto const&
current = collection.current;
1423 auto chainedExpiration =
current.validUntil;
1424 for (
auto const& [sequence, check] : collection.remaining)
1427 if (check.validFrom <= chainedExpiration)
1428 chainedExpiration = check.validUntil;
1434 if (!res || chainedExpiration < *res)
1436 res = chainedExpiration;
1440 if (localPublisherList.list.size() > 0)
1442 PublisherList collection = localPublisherList;
1444 auto const&
current = collection;
1445 auto chainedExpiration =
current.validUntil;
1448 if (!res || chainedExpiration < *res)
1450 res = chainedExpiration;
1457ValidatorList::expires()
const
1460 return expires(read_lock);
1464ValidatorList::getJson()
const
1470 res[jss::validation_quorum] =
static_cast<Json::UInt>(quorum_);
1475 x[jss::count] =
static_cast<Json::UInt>(count(read_lock));
1477 if (
auto when = expires(read_lock))
1479 if (*when == TimeKeeper::time_point::max())
1481 x[jss::expiration] =
"never";
1482 x[jss::status] =
"active";
1486 x[jss::expiration] = to_string(*when);
1488 if (*when > timeKeeper_.now())
1489 x[jss::status] =
"active";
1491 x[jss::status] =
"expired";
1496 x[jss::status] =
"unknown";
1497 x[jss::expiration] =
"unknown";
1500 x[jss::validator_list_threshold] =
Json::UInt(listThreshold_);
1506 for (
auto const& key : localPublisherList.list)
1511 for (
auto const& [publicKey, pubCollection] : publisherLists_)
1514 curr[jss::pubkey_publisher] =
strHex(publicKey);
1515 curr[jss::available] = pubCollection.status == PublisherStatus::available;
1518 target[jss::uri] = publisherList.
siteUri;
1522 target[jss::expiration] = to_string(publisherList.
validUntil);
1525 target[jss::effective] = to_string(publisherList.
validFrom);
1527 for (
auto const& key : publisherList.
list)
1533 auto const&
current = pubCollection.current;
1537 curr[jss::version] = pubCollection.rawVersion;
1542 for (
auto const& [sequence, future] : pubCollection.remaining)
1544 using namespace std::chrono_literals;
1548 appendList(future, r);
1551 future.validFrom > timeKeeper_.now() + 600s,
"xrpl::ValidatorList::getJson : minimum valid from");
1553 if (remaining.
size())
1554 curr[jss::remaining] = std::move(remaining);
1559 for (
auto const& k : trustedMasterKeys_)
1566 validatorManifests_.for_each_manifest([&jSigningKeys,
this](Manifest
const& manifest) {
1567 auto it = keyListings_.find(manifest.masterKey);
1568 if (it != keyListings_.end() && manifest.signingKey)
1570 jSigningKeys[toBase58(TokenType::NodePublic, manifest.masterKey)] =
1571 toBase58(TokenType::NodePublic, *manifest.signingKey);
1576 if (!negativeUNL_.empty())
1579 for (
auto const& k : negativeUNL_)
1593 for (
auto const& v : keyListings_)
1594 func(v.first, trusted(read_lock, v.first));
1604 uint256 const& hash)> func)
const
1608 for (
auto const& [key, plCollection] : publisherLists_)
1610 if (plCollection.status != PublisherStatus::available)
1612 XRPL_ASSERT(plCollection.maxSequence != 0,
"xrpl::ValidatorList::for_each_available : nonzero maxSequence");
1614 plCollection.rawManifest,
1615 plCollection.rawVersion,
1616 buildBlobInfos(plCollection),
1618 plCollection.maxSequence.value_or(0),
1619 plCollection.fullHash);
1632 JLOG(j_.warn()) <<
"Invalid requested validator list publisher key: " << pubKey;
1638 auto const iter = publisherLists_.find(
id);
1640 if (iter == publisherLists_.end() || iter->second.status != PublisherStatus::available)
1652 if (minimumQuorum_ > 0)
1654 JLOG(j_.warn()) <<
"Using potentially unsafe quorum of " << *minimumQuorum_
1655 <<
" as specified on the command line";
1656 return *minimumQuorum_;
1659 if (!publisherLists_.empty())
1664 for (
auto const& list : publisherLists_)
1666 if (list.second.status != PublisherStatus::available)
1688 auto const errorThreshold =
std::min(
1690 publisherLists_.size() - listThreshold_ + 1);
1691 XRPL_ASSERT(errorThreshold > 0,
"xrpl::ValidatorList::calculateQuorum : nonzero error threshold");
1734ValidatorList::updateTrusted(
1741 using namespace std::chrono_literals;
1742 if (timeKeeper_.now() > closeTime + 30s)
1743 closeTime = timeKeeper_.now();
1752 for (
auto& [pubKey, collection] : publisherLists_)
1755 auto& remaining = collection.remaining;
1756 auto const firstIter = remaining.begin();
1757 auto iter = firstIter;
1758 if (iter != remaining.end() && iter->second.validFrom <= closeTime)
1761 for (
auto next =
std::next(iter); next != remaining.end() && next->second.validFrom <= closeTime;
1766 "xrpl::ValidatorList::updateTrusted : sequential "
1770 iter != remaining.end(),
1771 "xrpl::ValidatorList::updateTrusted : non-end of "
1775 auto sequence = iter->first;
1776 auto& candidate = iter->second;
1777 auto&
current = collection.current;
1778 XRPL_ASSERT(candidate.validFrom <= closeTime,
"xrpl::ValidatorList::updateTrusted : maximum time");
1780 auto const oldList =
current.list;
1781 current = std::move(candidate);
1782 if (collection.status != PublisherStatus::available)
1783 collection.status = PublisherStatus::available;
1784 XRPL_ASSERT(
current.sequence == sequence,
"xrpl::ValidatorList::updateTrusted : sequence match");
1788 if (
current.validUntil <= closeTime)
1791 updatePublisherList(pubKey,
current, oldList, lock);
1798 broadcastBlobs(pubKey, collection, sequence,
current.hash, overlay, hashRouter, j_);
1801 remaining.erase(firstIter,
std::next(iter));
1807 if (collection.status == PublisherStatus::available && collection.current.validUntil <= closeTime)
1809 removePublisherList(lock, pubKey, PublisherStatus::expired);
1812 if (collection.status != PublisherStatus::available)
1820 auto it = trustedMasterKeys_.cbegin();
1821 while (it != trustedMasterKeys_.cend())
1823 auto const kit = keyListings_.find(*it);
1824 if (kit == keyListings_.end() ||
1825 kit->second < listThreshold_ ||
1826 validatorManifests_.revoked(*it))
1829 it = trustedMasterKeys_.erase(it);
1833 XRPL_ASSERT(kit->second >= listThreshold_,
"xrpl::ValidatorList::updateTrusted : count meets threshold");
1838 for (
auto const& val : keyListings_)
1840 if (val.second >= listThreshold_ && !validatorManifests_.revoked(val.first) &&
1841 trustedMasterKeys_.emplace(val.first).second)
1847 if (!trustChanges.
added.empty() || !trustChanges.
removed.empty())
1849 trustedSigningKeys_.clear();
1853 for (
auto const& k : trustedMasterKeys_)
1856 XRPL_ASSERT(signingKey,
"xrpl::ValidatorList::updateTrusted : found signing key");
1857 trustedSigningKeys_.insert(*signingKey);
1861 JLOG(j_.debug()) << trustedMasterKeys_.size() <<
" of " << keyListings_.size()
1862 <<
" listed validators eligible for inclusion in the trusted set";
1864 auto const unlSize = trustedMasterKeys_.size();
1865 auto effectiveUnlSize = unlSize;
1866 auto seenSize = seenValidators.
size();
1867 if (!negativeUNL_.empty())
1869 for (
auto const& k : trustedMasterKeys_)
1871 if (negativeUNL_.count(k))
1875 for (
auto const& k : negativeUNL_)
1879 for (
auto const& nid : seenValidators)
1881 if (negUnlNodeIDs.
count(nid))
1885 quorum_ = calculateQuorum(unlSize, effectiveUnlSize, seenSize);
1887 JLOG(j_.debug()) <<
"Using quorum of " << quorum_ <<
" for new set of " << unlSize <<
" trusted validators ("
1888 << trustChanges.
added.size() <<
" added, " << trustChanges.
removed.size() <<
" removed)";
1890 if (unlSize < quorum_)
1892 JLOG(j_.warn()) <<
"New quorum of " << quorum_ <<
" exceeds the number of trusted validators (" << unlSize
1896 if ((publisherLists_.size() || localPublisherList.list.size()) && unlSize == 0)
1902 return trustChanges;
1906ValidatorList::getTrustedMasterKeys()
const
1909 return trustedMasterKeys_;
1913ValidatorList::getListThreshold()
const
1916 return listThreshold_;
1920ValidatorList::getNegativeUNL()
const
1923 return negativeUNL_;
1930 negativeUNL_ = negUnl;
1937 auto ret = std::move(validations);
1940 if (!negativeUNL_.empty())
1946 [&](
auto const& v) ->
bool {
1947 if (auto const masterKey = getTrustedKey(read_lock, v->getSignerPublic()); masterKey)
1949 return negativeUNL_.count(*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
const_iterator end() 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