Skip to content

Commit

Permalink
lightningd: add option dev-strict-forwarding
Browse files Browse the repository at this point in the history
Changelog-Add: add option dev-strict-forwarding

Signed-off-by: Lagrang3 <[email protected]>
  • Loading branch information
Lagrang3 committed Aug 24, 2024
1 parent 4170c09 commit 3191f1a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
ld->dev_hsmd_no_preapprove_check = false;
ld->dev_hsmd_fail_preapprove = false;
ld->dev_handshake_no_reply = false;
ld->dev_strict_forwarding = false;

/*~ We try to ensure enough fds for twice the number of channels
* we start with. We have a developer option to change that factor
Expand Down
4 changes: 4 additions & 0 deletions lightningd/lightningd.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ struct lightningd {
/* Tell connectd not to talk after handshake */
bool dev_handshake_no_reply;

/* Remove the freedom to choose select between parallel channels to
* forward a payment. */
bool dev_strict_forwarding;

/* tor support */
struct wireaddr *proxyaddr;
bool always_use_proxy;
Expand Down
4 changes: 4 additions & 0 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,10 @@ static void dev_register_opts(struct lightningd *ld)
opt_set_bool,
&ld->dev_handshake_no_reply,
"Don't send or read init message after connection");
clnopt_noarg("--dev-strict-forwarding", OPT_DEV,
opt_set_bool,
&ld->dev_strict_forwarding,
"Forward HTLCs along the channel specified");
clnopt_noarg("--dev-throttle-gossip", OPT_DEV,
opt_set_bool,
&ld->dev_throttle_gossip,
Expand Down
16 changes: 5 additions & 11 deletions lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,16 +668,6 @@ static struct channel *best_channel(struct lightningd *ld,
struct amount_msat amt_to_forward,
struct channel *hint)
{
/* Prefer using hint if it can forward the request. */
if (hint && channel_state_can_add_htlc(hint->state)) {
struct amount_msat spendable;
spendable = channel_amount_spendable(hint);
if (amount_msat_greater_eq(
amt_to_forward,
hint->channel_info.their_config.htlc_minimum) &&
amount_msat_less_eq(amt_to_forward, spendable))
return hint;
}
struct amount_msat best_spendable = AMOUNT_MSAT(0);
struct channel *channel, *best = hint;

Expand Down Expand Up @@ -1222,7 +1212,11 @@ static struct channel_id *calc_forwarding_channel(struct lightningd *ld,
c = NULL;
}

best = best_channel(ld, peer, p->amt_to_forward, c);
if (!ld->dev_strict_forwarding)
best = best_channel(ld, peer, p->amt_to_forward, c);
else
best = c;

if (!c) {
if (!best)
return NULL;
Expand Down
8 changes: 7 additions & 1 deletion tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -6065,10 +6065,16 @@ def start_channels(connections):

def test_parallel_channels_reserve(node_factory):
"""Tests wether we are able to pay through parallel channels concurrently."""

def direction(node1, node2):
return 0 if node1.info["id"] < node2.info["id"] else 1

opts = {"disable-mpp": None, "fee-base": 0, "fee-per-satoshi": 0, "cltv-delta": 6}
opts = {
"fee-base": 0,
"fee-per-satoshi": 0,
"cltv-delta": 6,
"dev-strict-forwarding": None,
}
l1, l2, l3 = node_factory.get_nodes(3, opts=opts)

chan_ids = start_channels(
Expand Down

0 comments on commit 3191f1a

Please sign in to comment.