From d66d960d599915b7ba1bb7f9311e6848278945ae Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Wed, 9 Feb 2022 00:50:56 -0800 Subject: [PATCH] Miscellaneous Improvements: - Adjust default tree cache sizing - Various micro-optimizations --- src/ripple/core/impl/Config.cpp | 26 +++++++------- src/ripple/overlay/impl/PeerImp.cpp | 53 ++++++++++++++++++----------- src/ripple/overlay/impl/PeerImp.h | 1 + 3 files changed, 48 insertions(+), 32 deletions(-) diff --git a/src/ripple/core/impl/Config.cpp b/src/ripple/core/impl/Config.cpp index 50b487f8be8..1595f8831c4 100644 --- a/src/ripple/core/impl/Config.cpp +++ b/src/ripple/core/impl/Config.cpp @@ -115,19 +115,19 @@ sizedItems // what they control and whether there exists an explicit // config option that can be used to override the default. - // tiny small medium large huge - {SizedItem::sweepInterval, {{ 10, 30, 60, 90, 120 }}}, - {SizedItem::treeCacheSize, {{ 128000, 256000, 512000, 768000, 2048000 }}}, - {SizedItem::treeCacheAge, {{ 30, 60, 90, 120, 900 }}}, - {SizedItem::ledgerSize, {{ 32, 128, 256, 384, 768 }}}, - {SizedItem::ledgerAge, {{ 30, 90, 180, 240, 900 }}}, - {SizedItem::ledgerFetch, {{ 2, 3, 4, 5, 8 }}}, - {SizedItem::hashNodeDBCache, {{ 4, 12, 24, 64, 128 }}}, - {SizedItem::txnDBCache, {{ 4, 12, 24, 64, 128 }}}, - {SizedItem::lgrDBCache, {{ 4, 8, 16, 32, 128 }}}, - {SizedItem::openFinalLimit, {{ 8, 16, 32, 64, 128 }}}, - {SizedItem::burstSize, {{ 4, 8, 16, 32, 48 }}}, - {SizedItem::ramSizeGB, {{ 8, 12, 16, 24, 32 }}}, + // tiny small medium large huge + {SizedItem::sweepInterval, {{ 10, 30, 60, 90, 120 }}}, + {SizedItem::treeCacheSize, {{ 262144, 524288, 2097152, 4194304, 8388608 }}}, + {SizedItem::treeCacheAge, {{ 30, 60, 90, 120, 900 }}}, + {SizedItem::ledgerSize, {{ 32, 128, 256, 384, 768 }}}, + {SizedItem::ledgerAge, {{ 30, 90, 180, 240, 900 }}}, + {SizedItem::ledgerFetch, {{ 2, 3, 4, 5, 8 }}}, + {SizedItem::hashNodeDBCache, {{ 4, 12, 24, 64, 128 }}}, + {SizedItem::txnDBCache, {{ 4, 12, 24, 64, 128 }}}, + {SizedItem::lgrDBCache, {{ 4, 8, 16, 32, 128 }}}, + {SizedItem::openFinalLimit, {{ 8, 16, 32, 64, 128 }}}, + {SizedItem::burstSize, {{ 4, 8, 16, 32, 48 }}}, + {SizedItem::ramSizeGB, {{ 8, 12, 16, 24, 32 }}}, }}; // Ensure that the order of entries in the table corresponds to the diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index 5bdaa01213d..bc379c14725 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -603,7 +603,7 @@ PeerImp::fail(std::string const& reason) return post( strand_, std::bind( - (void(Peer::*)(std::string const&)) & PeerImp::fail, + (void (Peer::*)(std::string const&)) & PeerImp::fail, shared_from_this(), reason)); if (journal_.active(beast::severities::kWarning) && socket_.is_open()) @@ -1587,17 +1587,18 @@ PeerImp::handleTransaction( } } - if (app_.getJobQueue().getJobCount(jtTRANSACTION) > + if (app_.getLedgerMaster().getValidatedLedgerAge() > 4min) + { + JLOG(p_journal_.trace()) + << "No new transactions until synchronized"; + } + else if ( + app_.getJobQueue().getJobCount(jtTRANSACTION) > app_.config().MAX_TRANSACTIONS) { overlay_.incJqTransOverflow(); JLOG(p_journal_.info()) << "Transaction queue is full"; } - else if (app_.getLedgerMaster().getValidatedLedgerAge() > 4min) - { - JLOG(p_journal_.trace()) - << "No new transactions until synchronized"; - } else { app_.getJobQueue().addJob( @@ -2573,6 +2574,7 @@ PeerImp::onMessage(std::shared_ptr const& m) return; auto key = sha512Half(makeSlice(m->validation())); + if (auto [added, relayed] = app_.getHashRouter().addSuppressionPeerWithStatus(key, id_); !added) @@ -2592,22 +2594,36 @@ PeerImp::onMessage(std::shared_ptr const& m) if (!isTrusted && (tracking_.load() == Tracking::diverged)) { JLOG(p_journal_.debug()) - << "Validation: dropping untrusted from diverged peer"; + << "Dropping untrusted validation from diverged peer"; } - if (isTrusted || cluster() || !app_.getFeeTrack().isLoadedLocal()) + else if (isTrusted || !app_.getFeeTrack().isLoadedLocal()) { + std::string const name = [isTrusted, val]() { + std::string ret = + isTrusted ? "Trusted validation" : "Untrusted validation"; + +#ifdef DEBUG + ret += " " + + std::to_string(val->getFieldU32(sfLedgerSequence)) + ": " + + to_string(val->getNodeID()); +#endif + + return ret; + }(); + std::weak_ptr weak = shared_from_this(); app_.getJobQueue().addJob( isTrusted ? jtVALIDATION_t : jtVALIDATION_ut, - "recvValidation->checkValidation", - [weak, val, m]() { + name, + [weak, val, m, key]() { if (auto peer = weak.lock()) - peer->checkValidation(val, m); + peer->checkValidation(val, key, m); }); } else { - JLOG(p_journal_.debug()) << "Validation: Dropping UNTRUSTED (load)"; + JLOG(p_journal_.debug()) + << "Dropping untrusted validation for load"; } } catch (std::exception const& e) @@ -3152,12 +3168,13 @@ PeerImp::checkPropose( void PeerImp::checkValidation( std::shared_ptr const& val, + uint256 const& key, std::shared_ptr const& packet) { - if (!cluster() && !val->isValid()) + if (!val->isValid()) { JLOG(p_journal_.debug()) << "Validation forwarded by peer is invalid"; - charge(Resource::feeInvalidRequest); + charge(Resource::feeInvalidSignature); return; } @@ -3167,18 +3184,16 @@ PeerImp::checkValidation( if (app_.getOPs().recvValidation(val, std::to_string(id())) || cluster()) { - auto const suppression = - sha512Half(makeSlice(val->getSerialized())); // haveMessage contains peers, which are suppressed; i.e. the peers // are the source of the message, consequently the message should // not be relayed to these peers. But the message must be counted // as part of the squelch logic. auto haveMessage = - overlay_.relay(*packet, suppression, val->getSignerPublic()); + overlay_.relay(*packet, key, val->getSignerPublic()); if (reduceRelayReady() && !haveMessage.empty()) { overlay_.updateSlotAndSquelch( - suppression, + key, val->getSignerPublic(), std::move(haveMessage), protocol::mtVALIDATION); diff --git a/src/ripple/overlay/impl/PeerImp.h b/src/ripple/overlay/impl/PeerImp.h index 8bed64e724c..710ab4d74d6 100644 --- a/src/ripple/overlay/impl/PeerImp.h +++ b/src/ripple/overlay/impl/PeerImp.h @@ -626,6 +626,7 @@ class PeerImp : public Peer, void checkValidation( std::shared_ptr const& val, + uint256 const& key, std::shared_ptr const& packet); void