clboss/Boss/Mod/DemandTracker.hpp
Ken Sedgwick a612d759dd
Some checks are pending
Code Base Sanity Check / tests (push) Waiting to run
Code Base Sanity Check / coverage (push) Waiting to run
Code Base Sanity Check / build-clang (push) Waiting to run
DemandTracker: trigger demand rebalance cycles from observed forwards
New module DemandTracker registers an htlc_accepted deferrer that
never holds an HTLC: for each forward it raises DemandObserved
naming the outgoing channel, then immediately declines.  The
message deliberately carries no amount: unforwardable probe HTLCs
cost an attacker nothing, so sizing from a demanded amount would
be a free lever over our spend.

XRebalancer consumes the message.  A trigger arriving while any
cycle runs is discarded (traffic recurrence re-arms real demand);
otherwise it runs a demand cycle: the same fetch/join pipeline as
a matched cycle, targeting the peer whose channel the forward
exited through.  Fill-pool membership is the entire criterion --
demand controls when we rebalance, never who qualifies or how
much.  The request restores the peer to the fill edge, priced at
target NetPpm plus the minimum offered NetPpm, executed through
the existing executor with cycle tag [demand].

The new in_flight flag serializes matched and demand cycles; both
paths clear it behind a catch-all so an exception cannot wedge
it.  The catch-all around the matched tick also keeps the Poisson
loop alive on RPC errors, which previously terminated it with
only a stderr notice.
2026-08-05 10:59:08 -07:00

39 lines
1,021 B
C++

#ifndef BOSS_MOD_DEMANDTRACKER_HPP
#define BOSS_MOD_DEMANDTRACKER_HPP
namespace Ev { template<typename a> class Io; }
namespace Ln { namespace HtlcAccepted { struct Request; }}
namespace S { class Bus; }
namespace Boss { namespace Mod {
/** class Boss::Mod::DemandTracker
*
* @brief Observes forwards through an `htlc_accepted` deferrer
* and raises `Boss::Msg::DemandObserved` naming the outgoing
* channel of each one.
*
* Never holds an HTLC: the deferrer always declines immediately,
* so forwarding latency is unaffected. Consumers decide whether
* an observation warrants action (`Boss::Mod::XRebalancer`'s
* demand cycles).
*/
class DemandTracker {
private:
S::Bus& bus;
void start();
Ev::Io<bool> htlc_accepted(Ln::HtlcAccepted::Request const& req);
public:
DemandTracker() =delete;
DemandTracker(DemandTracker&&) =delete;
DemandTracker(DemandTracker const&) =delete;
explicit
DemandTracker(S::Bus& bus_) : bus(bus_) { start(); }
};
}}
#endif /* !defined(BOSS_MOD_DEMANDTRACKER_HPP) */