Commit graph

21 commits

Author SHA1 Message Date
Ken Sedgwick
986f30d1b4
PeerComplaintsDesk: defer auto-close while the peer is offline
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
close was issued with unilateraltimeout=180 on a fixed timer,
without regard to the peer's connection state, while one complaint
source (ComplainerByLowConnectRate) selects peers specifically for
a low connect rate.  Closing while the peer is offline escalates
to a unilateral force-close after 3 minutes, against exactly the
peers least likely to negotiate a mutual close in time.

Check the peer's channels for a live connection (listpeerchannels
peer_connected) before issuing close, and defer while the peer is
offline.  Poll close candidates every 10 minutes rather than once
per solicitation cycle, so a flaky peer's brief online windows are
actually caught.  If the peer stays offline for close_patience
(3 days), close anyway and let the short unilateral timeout
escalate; the first-deferred time is persisted in a new
PeerComplaintsDesk_closepending table so restarts do not reset
the patience window.  The fees_low gate applies only to that
unilateral path: a mutual close even at high feerates is cheaper
than a unilateral at low feerates, so connected peers are closed
immediately regardless of feerate.

Add tests/boss/test_peercomplaintsdesk_main.cpp covering the close
paths: a connected peer closes immediately; an offline peer defers
and the deferral survives a restart; within patience it holds;
expired patience holds at high fees and closes at low fees;
dropping below the complaint threshold sweeps the deferral;
channel destruction clears it; disabled auto-close closes nothing.
The test drives the module over the bus with a mock CLN on a
socketpair.

Reported by an external security researcher via private disclosure.

Fixes #324
2026-08-13 13:18:04 -07:00
Ken Sedgwick
16ac283abb
JitRebalancer: skip rebalance if one is already in flight for the destination
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
The fee budget check reads out_expenditures, which is only
persisted once a rebalance completes (up to 120 s per run).  Each
incoming HTLC spawned an independent rebalance run with no guard,
so concurrent HTLCs to the same underfunded channel each passed
the check against the same stale value, multiplying the intended
25%-of-earnings aggregate cap by the number of concurrent triggers.

Skip HTLC-triggered rebalances for a node that already has one in
flight, mirroring the working guard in EarningsRebalancer.  Skipped
HTLCs are released immediately and proceed without JIT rebalancing;
a retry after the in-flight run completes sees both the refilled
channel and the updated budget.

Update the parallel-calls unit test to the new semantics: exactly
one of three concurrent calls is let in, only it requests a
rebalance, and the guard clears once the run completes.

Reported by an external security researcher via private disclosure.

Fixes #323
2026-08-13 12:05:06 -07:00
Ken Sedgwick
ec4d695796 Reduce the default max-rebalance-fee-ppm 2025-08-25 09:30:52 -07:00
Ken Sedgwick
30c7be4019 Add configurable max rebalance fee (ppm)
Introduce `--clboss-max-rebalance-fee-ppm` to cap the fee allowed for a
single rebalance. Both JitRebalancer and EarningsRebalancer register and
use this option, defaulting to 5000 ppm (0.5%). Documentation updated to
explain the new setting.
2025-08-25 09:30:52 -07:00
Ken Sedgwick
52e739ebd9 tabify for consistency (unfortunately) 2025-08-25 09:30:52 -07:00
Ken Sedgwick
4a2ea4a039 Insert exception what() value in logging messages 2024-08-19 15:04:30 -07:00
Ken Sedgwick
dec8114cdf Convert some listpeers uses to listpeerchannels.
A couple `listpeers` uses can remain because they don't need channel
information.  Others use ListpeersAnnouncer and are covered by the
next commit.
2024-06-02 16:19:56 -07:00
Ken Sedgwick
60c07a7d66 Handle JSON-RPC msat amounts in either the old or new conventions 2023-08-18 20:29:21 -07:00
Ken Sedgwick
78c39f6242 Fix build issue w/ htlc_accepted_cont signature 2023-08-18 12:34:08 -07:00
ZmnSCPxj jxPCSnmZ
b2def4c51e Boss/Msg/ReqRespTraits.hpp: Use a traits class for requests and response. 2023-07-11 20:57:51 +08:00
ZmnSCPxj jxPCSnmZ
7f1db47af3 Boss/Mod/JitRebalancer.cpp: Use the new PeerFromScidMapper module. 2023-07-11 20:57:51 +08:00
ZmnSCPxj jxPCSnmZ
64ca360f65 *: Use Ln::CommandId for command IDs for received commands and hook events. 2022-11-23 00:36:43 +08:00
ZmnSCPxj jxPCSnmZ
c8ddb962df Boss/Mod/JitRebalancer.cpp: Respect unmanagement. 2022-05-11 12:09:13 +00:00
ZmnSCPxj jxPCSnmZ
773872435b Boss/Mod/JitRebalancer.cpp: Make testable via RPC emulation, also write a test. 2022-05-11 12:09:13 +00:00
ZmnSCPxj jxPCSnmZ
a9d0ad9b18 Boss/Mod/: Use iterators instead of indexing for Jsmn::Object types.
Closes: #28
2020-11-18 16:46:20 +08:00
ZmnSCPxj jxPCSnmZ
366229d7d7 Boss/Mod/JitRebalancer.cpp: Fix traversal of channels. 2020-11-06 10:03:49 +08:00
ZmnSCPxj jxPCSnmZ
41bd7bc6af *: Silence clang warnings. 2020-11-02 19:02:35 +08:00
ZmnSCPxj jxPCSnmZ
0bbf9426de Boss/Mod/JitRebalancer.cpp: Scale limit on rebalancing fee according to size of rebalance. 2020-10-28 12:29:13 +08:00
ZmnSCPxj jxPCSnmZ
91e1aa9eb9 Boss/Mod/InitialRebalancer.cpp, Boss/Mod/JitRebalancer.cpp: Make sure ReqResp objects are on persistent objects. 2020-10-28 08:35:08 +08:00
ZmnSCPxj jxPCSnmZ
c2311cc9d4 Boss/Mod/InitialRebalancer.cpp, Boss/Mod/JitRebalancer.cpp: Increase limits on rebalancing fees. 2020-10-27 21:40:28 +08:00
ZmnSCPxj jxPCSnmZ
830f258acf Boss/Mod/JitRebalancer.cpp: Implement JIT rebalancing. 2020-10-25 10:17:48 +08:00