Merge remote-tracking branch 'upstream/master' into merge231

Hotfix: version 2.3.1
  Reduce the peer charges for well-behaved peers
  Update conan in the "nix" CI jobs
This commit is contained in:
Ed Hennis
2025-01-29 18:11:02 -05:00
32 changed files with 400 additions and 162 deletions

View File

@@ -53,8 +53,9 @@ public:
bool
operator==(Charge const&) const;
bool
operator!=(Charge const&) const;
std::strong_ordering
operator<=>(Charge const&) const;
private:
value_type m_cost;

View File

@@ -67,7 +67,7 @@ public:
/** Apply a load charge to the consumer. */
Disposition
charge(Charge const& fee);
charge(Charge const& fee, std::string const& context = {});
/** Returns `true` if the consumer should be warned.
This consumes the warning.

View File

@@ -28,28 +28,28 @@ namespace Resource {
// clang-format off
/** Schedule of fees charged for imposing load on the server. */
/** @{ */
extern Charge const feeInvalidRequest; // A request that we can immediately
extern Charge const feeMalformedRequest; // A request that we can immediately
// tell is invalid
extern Charge const feeRequestNoReply; // A request that we cannot satisfy
extern Charge const feeInvalidSignature; // An object whose signature we had
// to check and it failed
extern Charge const feeUnwantedData; // Data we have no use for
extern Charge const feeBadData; // Data we have to verify before
extern Charge const feeUselessData; // Data we have no use for
extern Charge const feeInvalidData; // Data we have to verify before
// rejecting
// RPC loads
extern Charge const feeInvalidRPC; // An RPC request that we can
extern Charge const feeMalformedRPC; // An RPC request that we can
// immediately tell is invalid.
extern Charge const feeReferenceRPC; // A default "reference" unspecified
// load
extern Charge const feeExceptionRPC; // RPC load that causes an exception
extern Charge const feeMediumBurdenRPC; // A somewhat burdensome RPC load
extern Charge const feeHighBurdenRPC; // A very burdensome RPC load
extern Charge const feeHeavyBurdenRPC; // A very burdensome RPC load
// Peer loads
extern Charge const feeLightPeer; // Requires no reply
extern Charge const feeMediumBurdenPeer; // Requires some work
extern Charge const feeHighBurdenPeer; // Extensive work
extern Charge const feeTrivialPeer; // Requires no reply
extern Charge const feeModerateBurdenPeer; // Requires some work
extern Charge const feeHeavyBurdenPeer; // Extensive work
// Administrative
extern Charge const feeWarning; // The cost of receiving a warning

View File

@@ -446,12 +446,34 @@ public:
}
Disposition
charge(Entry& entry, Charge const& fee)
charge(Entry& entry, Charge const& fee, std::string context = {})
{
static constexpr Charge::value_type feeLogAsWarn = 3000;
static constexpr Charge::value_type feeLogAsInfo = 1000;
static constexpr Charge::value_type feeLogAsDebug = 100;
static_assert(
feeLogAsWarn > feeLogAsInfo && feeLogAsInfo > feeLogAsDebug &&
feeLogAsDebug > 10);
static auto getStream = [](Resource::Charge::value_type cost,
beast::Journal& journal) {
if (cost >= feeLogAsWarn)
return journal.warn();
if (cost >= feeLogAsInfo)
return journal.info();
if (cost >= feeLogAsDebug)
return journal.debug();
return journal.trace();
};
if (!context.empty())
context = " (" + context + ")";
std::lock_guard _(lock_);
clock_type::time_point const now(m_clock.now());
int const balance(entry.add(fee.cost(), now));
JLOG(m_journal.trace()) << "Charging " << entry << " for " << fee;
JLOG(getStream(fee.cost(), m_journal))
<< "Charging " << entry << " for " << fee << context;
return disposition(balance);
}

View File

@@ -32,7 +32,7 @@ enum {
// Balance at which the consumer is disconnected
,
dropThreshold = 15000
dropThreshold = 25000
// The number of seconds in the exponential decay window
// (This should be a power of two)