mirror of
https://github.com/ZmnSCPxj/clboss.git
synced 2026-08-13 12:33:20 +02:00
setconfig was acknowledged with unconditional success after broadcasting Msg::Option, while owning modules reject bad values by log-and-keep. lightningd persists a setconfig value (configvar_save) only on a success response, so the blanket ack recorded values clboss never applied: listconfigs and config.setconfig diverged from the running configuration, and a non-numeric value persisted for an int-typed option fails lightningd's own option parse on the next start -- lightningd refuses to boot. Add a rejection back-channel to Msg::Option: SetConfigHandler allocates a shared reject_reason (null on init-time raises, so aggregate initialization at existing sites is unaffected), the owning subscriber reports rejection via the new Msg::Option::reject() helper (a no-op at init time, where quietly keeping the default is right), and SetConfigHandler -- whose bus.raise() returns only after all subscribers ran -- fails the command with invalid-params when a reason was set. All dynamic-option owners in this tree report their rejections: RebalanceModeManager (unrecognized mode), FundsMover's three numeric handlers, and AskreneUpdates' shared age/retain handler.
127 lines
3.3 KiB
C++
127 lines
3.3 KiB
C++
#include"Boss/Mod/RebalanceModeManager.hpp"
|
|
#include"Boss/Msg/Manifestation.hpp"
|
|
#include"Boss/Msg/ManifestOption.hpp"
|
|
#include"Boss/Msg/Option.hpp"
|
|
#include"Boss/Msg/OptionType.hpp"
|
|
#include"Boss/Msg/ProvideStatus.hpp"
|
|
#include"Boss/Msg/RequestRebalanceMode.hpp"
|
|
#include"Boss/Msg/ResponseRebalanceMode.hpp"
|
|
#include"Boss/Msg/SolicitStatus.hpp"
|
|
#include"Boss/RebalanceMode.hpp"
|
|
#include"Boss/log.hpp"
|
|
#include"Ev/Io.hpp"
|
|
#include"Json/Out.hpp"
|
|
#include"S/Bus.hpp"
|
|
#include"Util/make_unique.hpp"
|
|
|
|
namespace {
|
|
|
|
/* Single dynamic option: the config file sets the startup default and
|
|
* `setconfig clboss-rebalance-mode <mode>` switches it at runtime. */
|
|
auto const option_name = std::string("clboss-rebalance-mode");
|
|
|
|
}
|
|
|
|
namespace Boss { namespace Mod {
|
|
|
|
class RebalanceModeManager::Impl {
|
|
private:
|
|
S::Bus& bus;
|
|
|
|
RebalanceMode mode;
|
|
|
|
void start() {
|
|
mode = default_rebalance_mode;
|
|
|
|
bus.subscribe<Msg::Manifestation
|
|
>([this](Msg::Manifestation const& _) {
|
|
return bus.raise(Msg::ManifestOption{
|
|
option_name,
|
|
Msg::OptionType_String,
|
|
Json::Out::direct(std::string(
|
|
rebalance_mode_to_string(
|
|
default_rebalance_mode
|
|
)
|
|
)),
|
|
"Rebalancer mode: \"classic\" (the original "
|
|
"rebalancer) or \"off\" (disable rebalancing). "
|
|
" Set in the config for the startup default or "
|
|
"at runtime with "
|
|
"`setconfig clboss-rebalance-mode <mode>`.",
|
|
true /* dynamic: runtime-settable via setconfig */
|
|
});
|
|
});
|
|
|
|
bus.subscribe<Msg::Option
|
|
>([this](Msg::Option const& o) {
|
|
if (o.name != option_name)
|
|
return Ev::lift();
|
|
auto s = std::string(o.value);
|
|
auto m = RebalanceMode();
|
|
if (!rebalance_mode_from_string(s, m)) {
|
|
/* No double quotes in the message:
|
|
* lightningd forwards plugin setconfig
|
|
* errors as the raw JSON-escaped token
|
|
* (plugin_setconfig_done uses the wire
|
|
* bytes verbatim), so embedded quotes
|
|
* reach the user doubled-escaped. */
|
|
o.reject( option_name + ": unrecognized "
|
|
"value '" + s + "'");
|
|
return Boss::log( bus, Error
|
|
, "RebalanceModeManager: "
|
|
"ignoring unrecognized "
|
|
"%s value \"%s\"; "
|
|
"keeping \"%s\"."
|
|
, option_name.c_str()
|
|
, s.c_str()
|
|
, rebalance_mode_to_string(mode)
|
|
);
|
|
}
|
|
if (m == mode)
|
|
return Ev::lift();
|
|
mode = m;
|
|
return Boss::log( bus, Info
|
|
, "RebalanceModeManager: "
|
|
"mode set to \"%s\"."
|
|
, rebalance_mode_to_string(mode)
|
|
);
|
|
});
|
|
|
|
bus.subscribe<Msg::RequestRebalanceMode
|
|
>([this](Msg::RequestRebalanceMode const& m) {
|
|
return bus.raise(Msg::ResponseRebalanceMode{
|
|
m.requester, mode
|
|
});
|
|
});
|
|
|
|
bus.subscribe<Msg::SolicitStatus
|
|
>([this](Msg::SolicitStatus const& _) {
|
|
auto out = Json::Out();
|
|
out.start_object()
|
|
.field("mode", std::string(rebalance_mode_to_string(mode)))
|
|
.end_object()
|
|
;
|
|
return bus.raise(Msg::ProvideStatus{
|
|
"rebalance_mode", std::move(out)
|
|
});
|
|
});
|
|
}
|
|
|
|
public:
|
|
Impl() =delete;
|
|
Impl(Impl&&) =delete;
|
|
Impl(Impl const&) =delete;
|
|
|
|
explicit
|
|
Impl(S::Bus& bus_) : bus(bus_) {
|
|
start();
|
|
}
|
|
};
|
|
|
|
RebalanceModeManager::RebalanceModeManager(RebalanceModeManager&&) =default;
|
|
RebalanceModeManager::~RebalanceModeManager() =default;
|
|
|
|
RebalanceModeManager::RebalanceModeManager(S::Bus& bus)
|
|
: pimpl(Util::make_unique<Impl>(bus)) { }
|
|
|
|
}}
|