diff --git a/src/xrpld/overlay/detail/PeerImp.cpp b/src/xrpld/overlay/detail/PeerImp.cpp index 0f8fd62fae..bcce5d5cda 100644 --- a/src/xrpld/overlay/detail/PeerImp.cpp +++ b/src/xrpld/overlay/detail/PeerImp.cpp @@ -1494,7 +1494,8 @@ PeerImp::onMessage(std::shared_ptr const& m) } } - // Verify ledger node IDs. Full parsing is deferred to the job. + // Verify ledger node counts. Full parsing of the node IDs is deferred to the job, so the I/O + // thread is not burdened with SHAMapNodeID deserialization for every TMGetLedger message. if (itype != protocol::liBASE && m->nodeids_size() <= 0) { badData("Invalid ledger node IDs"); @@ -1518,9 +1519,7 @@ PeerImp::onMessage(std::shared_ptr const& m) } } - // Queue a job to process the request. Full parsing of the node IDs is - // performed inside the job so the I/O thread is not burdened with - // SHAMapNodeID deserialization for every TMGetLedger message. + // Queue a job to process the request. std::weak_ptr const weak = shared_from_this(); app_.getJobQueue().addJob(JtLedgerReq, "RcvGetLedger", [weak, m, itype]() { auto peer = weak.lock(); @@ -1530,16 +1529,22 @@ PeerImp::onMessage(std::shared_ptr const& m) std::vector nodeIDs; if (itype != protocol::liBASE) { - nodeIDs.reserve(m->nodeids_size()); + nodeIDs.reserve(std::min(m->nodeids_size(), Tuning::kSoftMaxReplyNodes)); for (auto const& nodeId : m->nodeids()) { + if (nodeIDs.size() >= Tuning::kSoftMaxReplyNodes) + { + // Charge the peer for sending too many node IDs, but continue processing the + // received node IDs. If the request is legitimate then at least they will get + // a response and won't have to resend the request. + peer->charge( + Resource::kFeeModerateBurdenPeer, "TMGetLedger: too many node IDs"); + break; + } auto parsed = deserializeSHAMapNodeID(nodeId); if (!parsed) { - JLOG(peer->pJournal_.warn()) << "TMGetLedger: Invalid node ID"; - post(peer->strand_, [peer]() { - peer->charge(Resource::kFeeInvalidData, "TMGetLedger: Invalid node ID"); - }); + peer->charge(Resource::kFeeInvalidData, "TMGetLedger: Invalid node ID"); return; } nodeIDs.push_back(std::move(*parsed));