clboss/Boss/Mod/NewaddrHandler.cpp
Ken Sedgwick 1c3ac637ec
Boss/Mod/NewaddrHandler.cpp: Request p2tr addresses (CLN bech32 default removed).
CLN deprecated and then removed the implicit-bech32 default for the
newaddr command. Modern CLN (tested on v26.04.1) responds to
newaddr with only {"p2tr": "..."} and prints the warning

  jsonrpc: Note: disallowing deprecated newaddr.addresstype.defaultbech32

This hit our existing code at line 38, which extracted res["bech32"]
unconditionally. Jsmn::Object::operator[] returns an Object with
null pimpl when the key is missing, and the std::string conversion
operator then throws TypeError. The exception propagates up the
Ev::Io chain and is swallowed silently, so Msg::ResponseNewaddr is
never raised.

Downstream symptom: SwapManager hangs forever in state 0
(NeedsOnchainAddress) after restart. Its getting_address flag was
set true when it raised the request, and only clears when the
queue empties via the response chain that never completes. Every
subsequent Timer10Minutes tick short-circuits on the still-true
flag and does nothing.

Fix matches the draft on origin/boltzapi-v2-taproot-reverse-swaps
commit c3dd1de: explicitly request newaddr p2tr and read res["p2tr"].
This is a breaking change for CLN v23.05 and older, but those are
two-plus years out of support already.
2026-08-06 16:42:23 -07:00

53 lines
1.3 KiB
C++

#include"Boss/Mod/NewaddrHandler.hpp"
#include"Boss/Mod/Rpc.hpp"
#include"Boss/Msg/Init.hpp"
#include"Boss/Msg/RequestNewaddr.hpp"
#include"Boss/Msg/ResponseNewaddr.hpp"
#include"Boss/concurrent.hpp"
#include"Ev/Io.hpp"
#include"Ev/foreach.hpp"
#include"Jsmn/Object.hpp"
#include"Json/Out.hpp"
#include"S/Bus.hpp"
namespace Boss { namespace Mod {
void NewaddrHandler::start() {
bus.subscribe<Msg::Init
>([this](Msg::Init const& init) {
rpc = &init.rpc;
auto f = [this](void* r) { return newaddr(r); };
return Boss::concurrent(
Ev::foreach(f, std::move(pending))
);
});
bus.subscribe<Msg::RequestNewaddr
>([this](Msg::RequestNewaddr const& r) {
auto requester = r.requester;
if (!rpc) {
pending.push_back(requester);
return Ev::lift();
}
return Boss::concurrent(newaddr(requester));
});
}
Ev::Io<void> NewaddrHandler::newaddr(void* requester) {
/** BREAKING CHANGE:
* Requesting addresstype=p2tr is NOT compatible with CLN v23.05
* and older, which did not accept the p2tr addresstype. */
auto params = Json::Out()
.start_object()
.field("addresstype", "p2tr")
.end_object()
;
return rpc->command( "newaddr"
, std::move(params)
).then([this, requester](Jsmn::Object res) {
auto addr = std::string(res["p2tr"]);
return bus.raise(Msg::ResponseNewaddr{
std::move(addr), requester
});
});
}
}}