From f74b469e6832db56fc286bf49bf1e5bdb01b93b1 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Tue, 12 Jan 2021 21:33:34 -0800 Subject: [PATCH] Improve manifest relaying: The manifest relay code would only ever relay manifests from validators on a server's UNL which means that the manifests of validators that are not broadly trusted can fail to propagate across the network, which can make it difficult to detect and track such validators. This commit, if merged, propagates all manifests on a best-effort basis resulting in broader availability of manifests on the network and avoid the need to introduce on-ledger manifest storage or to establish one or more manifest repositories. --- src/ripple/app/misc/NetworkOPs.cpp | 2 + src/ripple/overlay/impl/OverlayImpl.cpp | 69 ++++++++++--------------- src/ripple/overlay/impl/PeerImp.cpp | 11 ++++ 3 files changed, 39 insertions(+), 43 deletions(-) diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index acc8c31d59..84ba65dc85 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -1913,6 +1913,8 @@ NetworkOPsImp::pubManifest(Manifest const& mo) if (auto sig = mo.getSignature()) jvObj[jss::signature] = strHex(*sig); jvObj[jss::master_signature] = strHex(mo.getMasterSignature()); + if (!mo.domain.empty()) + jvObj[jss::domain] = mo.domain; for (auto i = mStreamMaps[sManifests].begin(); i != mStreamMaps[sManifests].end();) diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp index 7c36ea47c2..409d687cd5 100644 --- a/src/ripple/overlay/impl/OverlayImpl.cpp +++ b/src/ripple/overlay/impl/OverlayImpl.cpp @@ -658,12 +658,10 @@ OverlayImpl::onManifests( std::shared_ptr const& m, std::shared_ptr const& from) { - auto& hashRouter = app_.getHashRouter(); auto const n = m->list_size(); auto const& journal = from->pjournal(); - JLOG(journal.debug()) << "TMManifest, " << n - << (n == 1 ? " item" : " items"); + protocol::TMManifests relay; for (std::size_t i = 0; i < n; ++i) { @@ -671,20 +669,6 @@ OverlayImpl::onManifests( if (auto mo = deserializeManifest(s)) { - uint256 const hash = mo->hash(); - if (!hashRouter.addSuppressionPeer(hash, from->id())) - { - JLOG(journal.info()) << "Duplicate manifest #" << i + 1; - continue; - } - - if (!app_.validators().listed(mo->masterKey)) - { - JLOG(journal.info()) << "Untrusted manifest #" << i + 1; - app_.getOPs().pubManifest(*mo); - continue; - } - auto const serialized = mo->serialized; auto const result = @@ -692,43 +676,42 @@ OverlayImpl::onManifests( if (result == ManifestDisposition::accepted) { - app_.getOPs().pubManifest(*deserializeManifest(serialized)); - } + relay.add_list()->set_stobject(s); - if (result == ManifestDisposition::accepted) - { - auto db = app_.getWalletDB().checkoutDb(); + // N.B.: this is important; the applyManifest call above moves + // the loaded Manifest out of the optional so we need to + // reload it here. + mo = deserializeManifest(serialized); + assert(mo); - soci::transaction tr(*db); - static const char* const sql = - "INSERT INTO ValidatorManifests (RawData) VALUES " - "(:rawData);"; - soci::blob rawData(*db); - convert(serialized, rawData); - *db << sql, soci::use(rawData); - tr.commit(); + app_.getOPs().pubManifest(*mo); - protocol::TMManifests o; - o.add_list()->set_stobject(s); + if (app_.validators().listed(mo->masterKey)) + { + auto db = app_.getWalletDB().checkoutDb(); - auto const toSkip = hashRouter.shouldRelay(hash); - if (toSkip) - foreach(send_if_not( - std::make_shared(o, protocol::mtMANIFESTS), - peer_in_set(*toSkip))); - } - else - { - JLOG(journal.info()) - << "Bad manifest #" << i + 1 << ": " << to_string(result); + soci::transaction tr(*db); + static const char* const sql = + "INSERT INTO ValidatorManifests (RawData) VALUES " + "(:rawData);"; + soci::blob rawData(*db); + convert(serialized, rawData); + *db << sql, soci::use(rawData); + tr.commit(); + } } } else { - JLOG(journal.warn()) << "Malformed manifest #" << i + 1; + JLOG(journal.debug()) + << "Malformed manifest #" << i + 1 << ": " << strHex(s); continue; } } + + if (!relay.list().empty()) + for_each([m2 = std::make_shared(relay, protocol::mtMANIFESTS)]( + std::shared_ptr&& p) { p->send(m2); }); } void diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index 2d7f636f8d..80cabaedad 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -991,6 +991,17 @@ PeerImp::onMessageEnd( void PeerImp::onMessage(std::shared_ptr const& m) { + auto const s = m->list_size(); + + if (s == 0) + { + fee_ = Resource::feeUnwantedData; + return; + } + + if (s > 100) + fee_ = Resource::feeMediumBurdenPeer; + // VFALCO What's the right job type? auto that = shared_from_this(); app_.getJobQueue().addJob(