Skip to content

Commit 3191f1a

Browse files
committed
lightningd: add option dev-strict-forwarding
Changelog-Add: add option dev-strict-forwarding Signed-off-by: Lagrang3 <[email protected]>
1 parent 4170c09 commit 3191f1a

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

lightningd/lightningd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
151151
ld->dev_hsmd_no_preapprove_check = false;
152152
ld->dev_hsmd_fail_preapprove = false;
153153
ld->dev_handshake_no_reply = false;
154+
ld->dev_strict_forwarding = false;
154155

155156
/*~ We try to ensure enough fds for twice the number of channels
156157
* we start with. We have a developer option to change that factor

lightningd/lightningd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ struct lightningd {
362362
/* Tell connectd not to talk after handshake */
363363
bool dev_handshake_no_reply;
364364

365+
/* Remove the freedom to choose select between parallel channels to
366+
* forward a payment. */
367+
bool dev_strict_forwarding;
368+
365369
/* tor support */
366370
struct wireaddr *proxyaddr;
367371
bool always_use_proxy;

lightningd/options.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,10 @@ static void dev_register_opts(struct lightningd *ld)
956956
opt_set_bool,
957957
&ld->dev_handshake_no_reply,
958958
"Don't send or read init message after connection");
959+
clnopt_noarg("--dev-strict-forwarding", OPT_DEV,
960+
opt_set_bool,
961+
&ld->dev_strict_forwarding,
962+
"Forward HTLCs along the channel specified");
959963
clnopt_noarg("--dev-throttle-gossip", OPT_DEV,
960964
opt_set_bool,
961965
&ld->dev_throttle_gossip,

lightningd/peer_htlcs.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -668,16 +668,6 @@ static struct channel *best_channel(struct lightningd *ld,
668668
struct amount_msat amt_to_forward,
669669
struct channel *hint)
670670
{
671-
/* Prefer using hint if it can forward the request. */
672-
if (hint && channel_state_can_add_htlc(hint->state)) {
673-
struct amount_msat spendable;
674-
spendable = channel_amount_spendable(hint);
675-
if (amount_msat_greater_eq(
676-
amt_to_forward,
677-
hint->channel_info.their_config.htlc_minimum) &&
678-
amount_msat_less_eq(amt_to_forward, spendable))
679-
return hint;
680-
}
681671
struct amount_msat best_spendable = AMOUNT_MSAT(0);
682672
struct channel *channel, *best = hint;
683673

@@ -1222,7 +1212,11 @@ static struct channel_id *calc_forwarding_channel(struct lightningd *ld,
12221212
c = NULL;
12231213
}
12241214

1225-
best = best_channel(ld, peer, p->amt_to_forward, c);
1215+
if (!ld->dev_strict_forwarding)
1216+
best = best_channel(ld, peer, p->amt_to_forward, c);
1217+
else
1218+
best = c;
1219+
12261220
if (!c) {
12271221
if (!best)
12281222
return NULL;

tests/test_pay.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6065,10 +6065,16 @@ def start_channels(connections):
60656065

60666066
def test_parallel_channels_reserve(node_factory):
60676067
"""Tests wether we are able to pay through parallel channels concurrently."""
6068+
60686069
def direction(node1, node2):
60696070
return 0 if node1.info["id"] < node2.info["id"] else 1
60706071

6071-
opts = {"disable-mpp": None, "fee-base": 0, "fee-per-satoshi": 0, "cltv-delta": 6}
6072+
opts = {
6073+
"fee-base": 0,
6074+
"fee-per-satoshi": 0,
6075+
"cltv-delta": 6,
6076+
"dev-strict-forwarding": None,
6077+
}
60726078
l1, l2, l3 = node_factory.get_nodes(3, opts=opts)
60736079

60746080
chan_ids = start_channels(

0 commit comments

Comments
 (0)