Skip to content

Commit

Permalink
feeMediumBurdenPeer and feeInvalidSignature context details
Browse files Browse the repository at this point in the history
  • Loading branch information
vlntb committed Jan 16, 2025
1 parent 0176e60 commit 73e8ae3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
9 changes: 9 additions & 0 deletions include/xrpl/resource/Charge.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class Charge
value_type
cost() const;

/** Return the human readable description associated with the charge. */
std::string const&
description() const;

/** Set additional details for the context in which the fee is applied. */
void
set_description(std::string const& description);

/** Converts this charge into a human readable string. */
std::string
to_string() const;
Expand All @@ -59,6 +67,7 @@ class Charge
private:
value_type m_cost;
std::string m_label;
std::string m_description;
};

std::ostream&
Expand Down
14 changes: 13 additions & 1 deletion src/libxrpl/resource/Charge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,23 @@ Charge::cost() const
return m_cost;
}

std::string const&
Charge::description() const
{
return m_description;
}

void
Charge::set_description(std::string const& description)
{
m_description = description;
}

std::string
Charge::to_string() const
{
std::stringstream ss;
ss << m_label << " ($" << m_cost << ")";
ss << m_label << " ($" << m_cost << "), details: " << m_description;
return ss.str();
}

Expand Down
37 changes: 30 additions & 7 deletions src/xrpld/overlay/detail/PeerImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,10 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMManifests> const& m)
}

if (s > 100)
{
fee_ = Resource::feeMediumBurdenPeer;
fee_.set_description("large list size");
}

app_.getJobQueue().addJob(
jtMANIFEST, "receiveManifests", [this, that = shared_from_this(), m]() {
Expand All @@ -1059,6 +1062,7 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMPing> const& m)
{
// We have received a ping request, reply with a pong
fee_ = Resource::feeMediumBurdenPeer;
fee_.set_description("received a ping request");
m->set_type(protocol::TMPing::ptPONG);
send(std::make_shared<Message>(*m, protocol::mtPING));
return;
Expand Down Expand Up @@ -1414,6 +1418,7 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMProofPathRequest> const& m)
}

fee_ = Resource::feeMediumBurdenPeer;
fee_.set_description("received a proof path request");
std::weak_ptr<PeerImp> weak = shared_from_this();
app_.getJobQueue().addJob(
jtREPLAY_REQ, "recvProofPathRequest", [weak, m]() {
Expand Down Expand Up @@ -1463,6 +1468,7 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMReplayDeltaRequest> const& m)
}

fee_ = Resource::feeMediumBurdenPeer;
fee_.set_description("received a replay delta request");
std::weak_ptr<PeerImp> weak = shared_from_this();
app_.getJobQueue().addJob(
jtREPLAY_REQ, "recvReplayDeltaRequest", [weak, m]() {
Expand Down Expand Up @@ -1604,8 +1610,10 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMProposeSet> const& m)
if ((std::clamp<std::size_t>(sig.size(), 64, 72) != sig.size()) ||
(publicKeyType(makeSlice(set.nodepubkey())) != KeyType::secp256k1))
{
JLOG(p_journal_.warn()) << "Proposal: malformed";
std::string desc{"Proposal: malformed, large list size"};
JLOG(p_journal_.warn()) << desc;
fee_ = Resource::feeInvalidSignature;
fee_.set_description(desc);
return;
}

Expand Down Expand Up @@ -2065,6 +2073,7 @@ PeerImp::onValidatorListMessage(
case ListDisposition::invalid:
// This shouldn't ever happen with a well-behaved peer
fee_ = Resource::feeInvalidSignature;
fee_.set_description("Invalid list disposition");
break;
case ListDisposition::unsupported_version:
// During a version transition, this may be legitimate.
Expand Down Expand Up @@ -2356,6 +2365,7 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMGetObjectByHash> const& m)
}

fee_ = Resource::feeMediumBurdenPeer;
fee_.set_description("received a get object by hash request");

protocol::TMGetObjectByHash reply;

Expand Down Expand Up @@ -2757,7 +2767,9 @@ PeerImp::checkTransaction(

// Probably not necessary to set SF_BAD, but doesn't hurt.
app_.getHashRouter().setFlags(stx->getTransactionID(), SF_BAD);
charge(Resource::feeInvalidSignature);
auto fee = Resource::feeInvalidSignature;
fee.set_description("Check transaction signature failure");
charge(fee);
return;
}
}
Expand All @@ -2778,7 +2790,9 @@ PeerImp::checkTransaction(
<< "Exception checking transaction: " << reason;
}
app_.getHashRouter().setFlags(stx->getTransactionID(), SF_BAD);
charge(Resource::feeInvalidSignature);
auto fee = Resource::feeInvalidSignature;
fee.set_description("Transaction status is invalid");
charge(fee);
return;
}

Expand Down Expand Up @@ -2809,8 +2823,11 @@ PeerImp::checkPropose(

if (!cluster() && !peerPos.checkSign())
{
JLOG(p_journal_.warn()) << "Proposal fails sig check";
charge(Resource::feeInvalidSignature);
std::string desc{"Proposal fails sig check"};
JLOG(p_journal_.warn()) << desc;
auto fee = Resource::feeInvalidSignature;
fee.set_description(desc);
charge(fee);
return;
}

Expand Down Expand Up @@ -2846,8 +2863,11 @@ PeerImp::checkValidation(
{
if (!val->isValid())
{
JLOG(p_journal_.debug()) << "Validation forwarded by peer is invalid";
charge(Resource::feeInvalidSignature);
std::string desc{"Validation forwarded by peer is invalid"};
JLOG(p_journal_.debug()) << desc;
auto fee = Resource::feeInvalidSignature;
fee.set_description(desc);
charge(fee);
return;
}

Expand Down Expand Up @@ -3108,7 +3128,10 @@ PeerImp::processLedgerRequest(std::shared_ptr<protocol::TMGetLedger> const& m)
{
// Do not resource charge a peer responding to a relay
if (!m->has_requestcookie())
{
charge(Resource::feeMediumBurdenPeer);
fee_.set_description("received a get ledger request");
}

std::shared_ptr<Ledger const> ledger;
std::shared_ptr<SHAMap const> sharedMap;
Expand Down

0 comments on commit 73e8ae3

Please sign in to comment.