clboss/Boss/Mod/all.cpp

232 lines
7.6 KiB
C++
Raw Normal View History

#include"Boss/Mod/ActiveProber.hpp"
#include"Boss/Mod/AmountSettingsHandler.hpp"
#include"Boss/Mod/AutoDisconnector.hpp"
#include"Boss/Mod/AvailableRpcCommandsAnnouncer.hpp"
#include"Boss/Mod/BlockTracker.hpp"
#include"Boss/Mod/BoltzSwapper/Main.hpp"
#include"Boss/Mod/ChannelCandidateInvestigator/Main.hpp"
#include"Boss/Mod/ChannelCandidateMatchmaker.hpp"
#include"Boss/Mod/ChannelCandidatePreinvestigator.hpp"
#include"Boss/Mod/ChannelCreateDestroyMonitor.hpp"
#include"Boss/Mod/ChannelCreationDecider.hpp"
#include"Boss/Mod/ChannelCreator/Main.hpp"
#include"Boss/Mod/ChannelFeeManager.hpp"
#include"Boss/Mod/ChannelFeeSetter.hpp"
#include"Boss/Mod/ChannelFinderByDistance.hpp"
#include"Boss/Mod/ChannelFinderByEarnedFee.hpp"
#include"Boss/Mod/ChannelFinderByListpays.hpp"
#include"Boss/Mod/ChannelFinderByPopularity.hpp"
#include"Boss/Mod/ChannelFundsComputer.hpp"
#include"Boss/Mod/ComplainerByLowConnectRate.hpp"
#include"Boss/Mod/ComplainerByLowSuccessPerDay.hpp"
#include"Boss/Mod/ConnectFinderByDns.hpp"
#include"Boss/Mod/ConnectFinderByHardcode.hpp"
#include"Boss/Mod/Connector.hpp"
#include"Boss/Mod/CommandReceiver.hpp"
#include"Boss/Mod/Dowser.hpp"
#include"Boss/Mod/EarningsRebalancer.hpp"
#include"Boss/Mod/EarningsTracker.hpp"
#include"Boss/Mod/FeeModderByBalance.hpp"
#include"Boss/Mod/FeeMonitor.hpp"
#include"Boss/Mod/FeeModderByPriceTheory.hpp"
#include"Boss/Mod/FeeModderBySize.hpp"
#include"Boss/Mod/ForwardFeeMonitor.hpp"
#include"Boss/Mod/FundsMover/Main.hpp"
#include"Boss/Mod/HtlcAcceptor.hpp"
#include"Boss/Mod/InitialConnect.hpp"
#include"Boss/Mod/InitialRebalancer.hpp"
#include"Boss/Mod/Initiator.hpp"
#include"Boss/Mod/InternetConnectionMonitor.hpp"
#include"Boss/Mod/InvoicePayer.hpp"
#include"Boss/Mod/JitRebalancer.hpp"
#include"Boss/Mod/JsonOutputter.hpp"
#include"Boss/Mod/ListfundsAnalyzer.hpp"
#include"Boss/Mod/ListfundsAnnouncer.hpp"
#include"Boss/Mod/ListpaysHandler.hpp"
#include"Boss/Mod/ListpeersAnalyzer.hpp"
#include"Boss/Mod/ListpeersAnnouncer.hpp"
#include"Boss/Mod/Manifester.hpp"
#include"Boss/Mod/MoveFundsCommand.hpp"
#include"Boss/Mod/NeedsConnectSolicitor.hpp"
#include"Boss/Mod/NeedsOnchainFundsSwapper.hpp"
#include"Boss/Mod/NewaddrHandler.hpp"
#include"Boss/Mod/NodeBalanceSwapper.hpp"
#include"Boss/Mod/OnchainFeeMonitor.hpp"
#include"Boss/Mod/OnchainFundsAnnouncer.hpp"
#include"Boss/Mod/OnchainFundsIgnorer.hpp"
#include"Boss/Mod/PaymentDeleter.hpp"
#include"Boss/Mod/PeerCompetitorFeeMonitor/Main.hpp"
#include"Boss/Mod/PeerComplaintsDesk/Main.hpp"
#include"Boss/Mod/PeerFromScidMapper.hpp"
#include"Boss/Mod/PeerMetrician.hpp"
#include"Boss/Mod/PeerStatistician.hpp"
#include"Boss/Mod/RebalanceUnmanager.hpp"
#include"Boss/Mod/Reconnector.hpp"
#include"Boss/Mod/RegularActiveProbe.hpp"
#include"Boss/Mod/RpcWrapper.hpp"
#include"Boss/Mod/SelfUptimeMonitor.hpp"
#include"Boss/Mod/SendpayResultMonitor.hpp"
XMoveFunds: age the clboss-xrebalance layer, runtime-tunable via setconfig Adds periodic askrene-age against the persistent clboss-xrebalance layer so capacity constraints written by inform_channel_constrained do not accumulate forever. Mirrors FundsMover's age_clboss_layer: fires on Msg::TimerRandomHourly, logs num_removed at Debug, and catches RpcError with -32601 stayed at Debug (graceful degradation on CLN without askrene-age) while other codes promote to Warn so sustained aging failure is visible. The aging cutoff is controlled by a new plugin option, clboss-xrebalance-age-secs, default 3600 (1h) to match FundsMover's production value. Operators on networks with slower flows (signet) are expected to widen this; the right value is empirical and will be tuned after observation. The option is registered dynamic=true so the window is mutable at runtime via: lightning-cli setconfig clboss-xrebalance-age-secs <secs> No clboss / lightningd restart required. To support that, three small infrastructure pieces: * Boss::Msg::ManifestOption gains a bool dynamic field (default false; preserves existing behavior). * Boss::Mod::Manifester emits the per-option dynamic flag in the getmanifest response, so lightningd knows to forward setconfig for that option. * New Boss::Mod::SetConfigHandler module records (name -> dynamic flag) from Msg::ManifestOption events, then handles incoming Msg::CommandRequest where command == "setconfig" by validating the named option is registered + dynamic and re-raising a fresh Msg::Option on the bus. Existing option handlers re-apply the new value transparently. Contract for any future opt-in to dynamic: at startup lightningd encodes Int / Bool / Flag option values as JSON primitives, but at setconfig time it encodes them as JSON strings. Handlers for dynamic options must accept both Jsmn shapes. The XMoveFunds option handler does this; the contract is documented in SetConfigHandler's header comment so future modules can opt in safely.
2026-06-01 09:31:50 -07:00
#include"Boss/Mod/SetConfigHandler.hpp"
#include"Boss/Mod/StatusCommand.hpp"
#include"Boss/Mod/SwapManager.hpp"
#include"Boss/Mod/SwapReporter.hpp"
#include"Boss/Mod/TimerTwiceDailyAnnouncer.hpp"
#include"Boss/Mod/Timers.hpp"
#include"Boss/Mod/UnmanagedManager.hpp"
#include"Boss/Mod/Waiter.hpp"
XMoveFunds: scaffold the manual-trigger rebalance primitive Adds Boss/Mod/XMoveFunds/Main.{hpp,cpp} and registers a new RPC command `clboss-xmovefunds`. This is the lowest-level primitive that the upcoming xrebalance algorithm will sit on top of: the caller hands it an explicit set of source channels (drain candidates), destination channels (fill candidates), an amount, and optional knobs, and the module will eventually drive an askrene-getroutes call (circular mode) and an optional sendpay. The module follows the pimpl + Impl pattern already used by FundsMover and is installed in Boss/Mod/all.cpp alongside the existing rebalance machinery. API surface Each of source_scid and dest_scid may be either a single scid string or a JSON array of scid strings. The single-channel form is convenient for hand-typed RPC calls; the array form is what the xrebalance algorithm will use to express multi-source / multi-dest tier selection. parse_scid_list() in the implementation handles both shapes uniformly. Named parameters: source_scid scid string or array -- channels whose us->peer direction stays unmasked. Required. dest_scid scid string or array -- channels whose peer->us direction stays unmasked. Required. amount_msat integer -- total amount to move. Required. maxfee_msat integer. Defaults to 5000 ppm of amount_msat, floored at 1000 msat. maxparts integer. Defaults to 10. execute boolean. Defaults to false; when false, the route is computed and reported but not sent. The manifest help text spells out the array shape with concrete examples so anyone running `lightning-cli help clboss-xmovefunds` sees the full surface without having to read the code.
2026-05-31 13:48:03 -07:00
#include"Boss/Mod/XMoveFunds/Main.hpp"
#include"Boss/Mod/all.hpp"
#include<vector>
namespace {
class All {
private:
std::vector<std::shared_ptr<void>> modules;
public:
template<typename M, typename... As>
std::shared_ptr<M> install(As&&... as) {
auto ptr = std::make_shared<M>(as...);
modules.push_back(std::shared_ptr<void>(ptr));
return ptr;
}
};
}
namespace Boss { namespace Mod {
std::shared_ptr<void> all( std::ostream& cout
, S::Bus& bus
, Ev::ThreadPool& threadpool
, std::function< Net::Fd( std::string const&
, std::string const&
)
> open_rpc_socket
) {
auto all = std::make_shared<All>();
2020-09-17 11:16:08 +08:00
/* Basic. */
auto waiter = all->install<Waiter>(bus);
auto imon = all->install<InternetConnectionMonitor>( bus
, threadpool
, *waiter
);
all->install<JsonOutputter>(cout, bus);
all->install<CommandReceiver>(bus);
all->install<RpcWrapper>(bus);
all->install<AvailableRpcCommandsAnnouncer>(bus);
2020-09-17 11:16:08 +08:00
/* Startup. */
all->install<Manifester>(bus);
all->install<Initiator>(bus, threadpool, std::move(open_rpc_socket));
XMoveFunds: age the clboss-xrebalance layer, runtime-tunable via setconfig Adds periodic askrene-age against the persistent clboss-xrebalance layer so capacity constraints written by inform_channel_constrained do not accumulate forever. Mirrors FundsMover's age_clboss_layer: fires on Msg::TimerRandomHourly, logs num_removed at Debug, and catches RpcError with -32601 stayed at Debug (graceful degradation on CLN without askrene-age) while other codes promote to Warn so sustained aging failure is visible. The aging cutoff is controlled by a new plugin option, clboss-xrebalance-age-secs, default 3600 (1h) to match FundsMover's production value. Operators on networks with slower flows (signet) are expected to widen this; the right value is empirical and will be tuned after observation. The option is registered dynamic=true so the window is mutable at runtime via: lightning-cli setconfig clboss-xrebalance-age-secs <secs> No clboss / lightningd restart required. To support that, three small infrastructure pieces: * Boss::Msg::ManifestOption gains a bool dynamic field (default false; preserves existing behavior). * Boss::Mod::Manifester emits the per-option dynamic flag in the getmanifest response, so lightningd knows to forward setconfig for that option. * New Boss::Mod::SetConfigHandler module records (name -> dynamic flag) from Msg::ManifestOption events, then handles incoming Msg::CommandRequest where command == "setconfig" by validating the named option is registered + dynamic and re-raising a fresh Msg::Option on the bus. Existing option handlers re-apply the new value transparently. Contract for any future opt-in to dynamic: at startup lightningd encodes Int / Bool / Flag option values as JSON primitives, but at setconfig time it encodes them as JSON strings. Handlers for dynamic options must accept both Jsmn shapes. The XMoveFunds option handler does this; the contract is documented in SetConfigHandler's header comment so future modules can opt in safely.
2026-06-01 09:31:50 -07:00
all->install<SetConfigHandler>(bus);
2020-09-17 11:16:08 +08:00
/* General settings. */
all->install<AmountSettingsHandler>(bus);
2020-09-17 11:16:08 +08:00
/* Regular timers. */
all->install<BlockTracker>(bus);
all->install<Timers>(bus, *waiter);
all->install<TimerTwiceDailyAnnouncer>(bus);
2020-09-17 11:16:08 +08:00
/* Connection wrangling. */
all->install<InitialConnect>(bus);
all->install<Connector>(bus);
all->install<NeedsConnectSolicitor>(bus);
all->install<ConnectFinderByDns>(bus);
all->install<ConnectFinderByHardcode>(bus);
2020-09-17 11:16:08 +08:00
all->install<Reconnector>(bus);
all->install<AutoDisconnector>(bus);
/* Status monitors. */
all->install<ChannelFundsComputer>(bus);
all->install<ListpeersAnnouncer>(bus);
all->install<ListpeersAnalyzer>(bus);
all->install<OnchainFeeMonitor>(bus, *waiter);
2020-09-17 11:16:08 +08:00
all->install<ListfundsAnnouncer>(bus);
all->install<ListfundsAnalyzer>(bus);
2020-09-17 11:16:08 +08:00
all->install<OnchainFundsAnnouncer>(bus);
all->install<OnchainFundsIgnorer>(bus);
all->install<ChannelCreateDestroyMonitor>(bus);
all->install<SelfUptimeMonitor>(bus);
2020-09-17 11:16:08 +08:00
/* Channel creation wrangling. */
all->install<ChannelFinderByDistance>(bus, *waiter);
all->install<ChannelFinderByEarnedFee>(bus);
all->install<ChannelFinderByListpays>(bus);
all->install<ChannelFinderByPopularity>(bus, *waiter);
all->install<ChannelCandidatePreinvestigator>(bus);
auto investigator = all->install< ChannelCandidateInvestigator::Main
>(bus, *imon);
all->install<ChannelCreationDecider>(bus);
all->install<ChannelCreator::Main>(bus, *waiter, *investigator);
all->install<ChannelCandidateMatchmaker>(bus);
all->install<Dowser>(bus);
/* Status. */
all->install<StatusCommand>(bus);
/* Offchain-to-onchain swap. */
all->install<NewaddrHandler>(bus);
all->install<BoltzSwapper::Main>(bus, threadpool);
all->install<SwapManager>(bus);
all->install<NeedsOnchainFundsSwapper>(bus);
all->install<NodeBalanceSwapper>(bus);
all->install<SwapReporter>(bus);
/* Invoice wrangling. */
all->install<InvoicePayer>(bus);
all->install<ListpaysHandler>(bus);
all->install<PaymentDeleter>(bus);
/* Channel fees. */
all->install<FeeMonitor>(bus);
all->install<PeerCompetitorFeeMonitor::Main>(bus);
all->install<ChannelFeeSetter>(bus);
all->install<ChannelFeeManager>(bus);
all->install<FeeModderBySize>(bus);
all->install<FeeModderByBalance>(bus);
all->install<FeeModderByPriceTheory>(bus);
/* HTLC manipulation. */
all->install<HtlcAcceptor>(bus, *waiter);
/* Bad peer monitoring. */
all->install<SendpayResultMonitor>(bus);
all->install<ForwardFeeMonitor>(bus);
all->install<PeerStatistician>(bus);
all->install<PeerMetrician>(bus);
all->install<ActiveProber>(bus, *investigator);
all->install<RegularActiveProbe>(bus);
/* Peer complaints. */
all->install<PeerComplaintsDesk::Main>(bus);
all->install<ComplainerByLowConnectRate>(bus);
#ifdef ENABLE_COMPLAINER_BY_LOW_SUCCESS_PER_DAY
all->install<ComplainerByLowSuccessPerDay>(bus);
#endif /* ENABLE_COMPLAINER_BY_LOW_SUCCESS_PER_DAY */
/* Channel balancing. */
all->install<FundsMover::Main>(bus);
XMoveFunds: scaffold the manual-trigger rebalance primitive Adds Boss/Mod/XMoveFunds/Main.{hpp,cpp} and registers a new RPC command `clboss-xmovefunds`. This is the lowest-level primitive that the upcoming xrebalance algorithm will sit on top of: the caller hands it an explicit set of source channels (drain candidates), destination channels (fill candidates), an amount, and optional knobs, and the module will eventually drive an askrene-getroutes call (circular mode) and an optional sendpay. The module follows the pimpl + Impl pattern already used by FundsMover and is installed in Boss/Mod/all.cpp alongside the existing rebalance machinery. API surface Each of source_scid and dest_scid may be either a single scid string or a JSON array of scid strings. The single-channel form is convenient for hand-typed RPC calls; the array form is what the xrebalance algorithm will use to express multi-source / multi-dest tier selection. parse_scid_list() in the implementation handles both shapes uniformly. Named parameters: source_scid scid string or array -- channels whose us->peer direction stays unmasked. Required. dest_scid scid string or array -- channels whose peer->us direction stays unmasked. Required. amount_msat integer -- total amount to move. Required. maxfee_msat integer. Defaults to 5000 ppm of amount_msat, floored at 1000 msat. maxparts integer. Defaults to 10. execute boolean. Defaults to false; when false, the route is computed and reported but not sent. The manifest help text spells out the array shape with concrete examples so anyone running `lightning-cli help clboss-xmovefunds` sees the full surface without having to read the code.
2026-05-31 13:48:03 -07:00
all->install<XMoveFunds::Main>(bus);
all->install<MoveFundsCommand>(bus);
all->install<EarningsTracker>(bus);
all->install<JitRebalancer>(bus);
#ifdef ENABLE_INITIAL_REBALANCER
all->install<InitialRebalancer>(bus);
#endif /* ENABLE_INITIAL_REBALANCER */
all->install<EarningsRebalancer>(bus);
all->install<RebalanceUnmanager>(bus);
/* Unmanaged nodes. */
all->install<UnmanagedManager>(bus);
/* Utility. */
all->install<PeerFromScidMapper>(bus);
return all;
}
}}