2020-10-22 08:48:09 +08:00
|
|
|
#include"Boss/Mod/FundsMover/Claimer.hpp"
|
|
|
|
|
#include"Boss/Mod/FundsMover/Main.hpp"
|
|
|
|
|
#include"Boss/Mod/FundsMover/Runner.hpp"
|
2021-04-28 19:12:34 +08:00
|
|
|
#include"Boss/Mod/FundsMover/create_label.hpp"
|
2020-11-11 15:14:08 +08:00
|
|
|
#include"Boss/Mod/Rpc.hpp"
|
2022-05-11 08:58:01 +08:00
|
|
|
#include"Boss/ModG/RebalanceUnmanagerProxy.hpp"
|
2020-10-22 08:48:09 +08:00
|
|
|
#include"Boss/Msg/Init.hpp"
|
2021-04-28 19:12:34 +08:00
|
|
|
#include"Boss/Msg/ProvideDeletablePaymentLabelFilter.hpp"
|
2020-10-22 08:48:09 +08:00
|
|
|
#include"Boss/Msg/RequestMoveFunds.hpp"
|
2021-04-28 19:12:34 +08:00
|
|
|
#include"Boss/Msg/SolicitDeletablePaymentLabelFilter.hpp"
|
2020-11-11 15:14:08 +08:00
|
|
|
#include"Boss/concurrent.hpp"
|
2022-05-11 08:58:01 +08:00
|
|
|
#include"Boss/log.hpp"
|
2020-10-22 08:48:09 +08:00
|
|
|
#include"Ev/Io.hpp"
|
|
|
|
|
#include"Ev/yield.hpp"
|
|
|
|
|
#include"Ln/NodeId.hpp"
|
|
|
|
|
#include"S/Bus.hpp"
|
|
|
|
|
#include"Util/make_unique.hpp"
|
2022-05-11 08:58:01 +08:00
|
|
|
#include"Util/stringify.hpp"
|
|
|
|
|
|
|
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
|
# include"config.h"
|
|
|
|
|
#endif
|
2020-10-22 08:48:09 +08:00
|
|
|
|
|
|
|
|
namespace Boss { namespace Mod { namespace FundsMover {
|
|
|
|
|
|
|
|
|
|
class Main::Impl {
|
|
|
|
|
private:
|
|
|
|
|
S::Bus& bus;
|
|
|
|
|
Claimer claimer;
|
|
|
|
|
Boss::Mod::Rpc* rpc;
|
|
|
|
|
Ln::NodeId self_id;
|
|
|
|
|
|
2022-05-11 08:58:01 +08:00
|
|
|
Boss::ModG::RebalanceUnmanagerProxy unmanager;
|
|
|
|
|
|
2020-10-22 08:48:09 +08:00
|
|
|
void start() {
|
|
|
|
|
bus.subscribe<Msg::Init>([this](Msg::Init const& init) {
|
|
|
|
|
rpc = &init.rpc;
|
|
|
|
|
self_id = init.self_id;
|
2021-04-28 19:12:34 +08:00
|
|
|
return Ev::lift();
|
2020-10-22 08:48:09 +08:00
|
|
|
});
|
|
|
|
|
bus.subscribe<Msg::RequestMoveFunds
|
|
|
|
|
>([this](Msg::RequestMoveFunds const& m) {
|
|
|
|
|
auto msg = std::make_shared<Msg::RequestMoveFunds>(m);
|
2022-05-11 08:58:01 +08:00
|
|
|
return wait_for_rpc().then([this]() {
|
|
|
|
|
return unmanager.get_unmanaged();
|
|
|
|
|
}).then([this, msg](std::set<Ln::NodeId> const* unmanaged) {
|
|
|
|
|
auto un_s = (unmanaged->count(msg->source) != 0);
|
|
|
|
|
auto un_d = (unmanaged->count(msg->destination) != 0);
|
|
|
|
|
if (un_s || un_d) {
|
|
|
|
|
char const* tpl = nullptr;
|
|
|
|
|
if (un_s && un_d) {
|
|
|
|
|
tpl = "%1$sfrom an unmanaged node %2$s "
|
|
|
|
|
"to an unmanaged node %3$s%4$s"
|
|
|
|
|
;
|
|
|
|
|
} else if (un_s) {
|
|
|
|
|
tpl = "%1$sfrom an unmanaged node %2$s"
|
|
|
|
|
"%4$s"
|
|
|
|
|
;
|
|
|
|
|
} else {
|
|
|
|
|
tpl = "%1$s"
|
|
|
|
|
"to an unmanaged node %3$s%4$s"
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
return Boss::log( bus, Error
|
|
|
|
|
, tpl
|
|
|
|
|
, "FundsMover: *SOMETHING* is "
|
|
|
|
|
"attempting to move funds "
|
|
|
|
|
, Util::stringify(msg->source)
|
|
|
|
|
.c_str()
|
|
|
|
|
, Util::stringify(msg->destination)
|
|
|
|
|
.c_str()
|
|
|
|
|
, ", this may be a bug, "
|
|
|
|
|
"refusing to move. "
|
|
|
|
|
"Contact " PACKAGE_BUGREPORT
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-10-22 08:48:09 +08:00
|
|
|
auto runner = Runner::create( bus
|
|
|
|
|
, *rpc
|
|
|
|
|
, self_id
|
|
|
|
|
, claimer
|
|
|
|
|
, *msg
|
|
|
|
|
);
|
|
|
|
|
return Runner::start(runner);
|
|
|
|
|
});
|
|
|
|
|
});
|
2021-04-28 19:12:34 +08:00
|
|
|
using Msg::ProvideDeletablePaymentLabelFilter;
|
|
|
|
|
using Msg::SolicitDeletablePaymentLabelFilter;
|
|
|
|
|
bus.subscribe<SolicitDeletablePaymentLabelFilter
|
|
|
|
|
>([this
|
|
|
|
|
](SolicitDeletablePaymentLabelFilter const& _) {
|
|
|
|
|
return bus.raise(ProvideDeletablePaymentLabelFilter{
|
|
|
|
|
&is_our_label
|
|
|
|
|
});
|
2020-11-11 15:14:08 +08:00
|
|
|
});
|
2020-10-22 08:48:09 +08:00
|
|
|
}
|
|
|
|
|
Ev::Io<void> wait_for_rpc() {
|
|
|
|
|
return Ev::lift().then([this]() {
|
|
|
|
|
if (!rpc)
|
|
|
|
|
return Ev::yield() + wait_for_rpc();
|
|
|
|
|
return Ev::lift();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Impl() =delete;
|
|
|
|
|
Impl(Impl&&) =delete;
|
|
|
|
|
Impl(Impl const&) =delete;
|
|
|
|
|
|
|
|
|
|
explicit
|
|
|
|
|
Impl(S::Bus& bus_) : bus(bus_)
|
|
|
|
|
, claimer(bus_)
|
|
|
|
|
, rpc(nullptr)
|
2022-05-11 08:58:01 +08:00
|
|
|
, unmanager(bus_)
|
2020-10-22 08:48:09 +08:00
|
|
|
{ start(); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Main::Main(Main&&) =default;
|
|
|
|
|
Main::~Main() =default;
|
|
|
|
|
|
|
|
|
|
Main::Main(S::Bus& bus) : pimpl(Util::make_unique<Impl>(bus)) { }
|
|
|
|
|
|
|
|
|
|
}}}
|