|
|
@ -436,39 +436,6 @@ static struct command_result *parse_fallback(struct command *cmd, |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
|
|
|
|
/** incoming_capacity
|
|
|
|
* |
|
|
|
* @brief Determine the ability of the peer to pay us. |
|
|
|
* |
|
|
|
* @param ld - the lightningd. |
|
|
|
* @param c - the channel to check. |
|
|
|
* @param capacity_to_pay_us - out; if this returns true, |
|
|
|
* the pointed-to `struct amount_msat` will contain how |
|
|
|
* much the peer can pay us at maximum. |
|
|
|
* |
|
|
|
* @return false if the peer cannot pay to us, true if |
|
|
|
* the peer can pay us and `capacity_to_pay_us` is set. |
|
|
|
*/ |
|
|
|
static bool incoming_capacity(struct lightningd *ld, |
|
|
|
struct channel *c, |
|
|
|
struct amount_msat *capacity_to_pay_us) |
|
|
|
{ |
|
|
|
struct amount_msat their_msat; |
|
|
|
if (!amount_sat_sub_msat(&their_msat, c->funding, c->our_msat)) { |
|
|
|
log_broken(ld->log, |
|
|
|
"underflow: funding %s - our_msat %s", |
|
|
|
type_to_string(tmpctx, struct amount_sat, |
|
|
|
&c->funding), |
|
|
|
type_to_string(tmpctx, struct amount_msat, |
|
|
|
&c->our_msat)); |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (!amount_msat_sub_sat(capacity_to_pay_us, their_msat, |
|
|
|
c->our_config.channel_reserve)) |
|
|
|
return false; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
* From array of incoming channels [inchan], find suitable ones for |
|
|
|
* a payment-to-us of [amount_needed], using criteria: |
|
|
@ -530,9 +497,7 @@ static struct route_info **select_inchan(const tal_t *ctx, |
|
|
|
0 ^ ^ ^ funding |
|
|
|
our_reserve our_msat */ |
|
|
|
|
|
|
|
/* Can the peer pay to us, and if so how much? */ |
|
|
|
if (!incoming_capacity(ld, c, &capacity_to_pay_us)) |
|
|
|
continue; |
|
|
|
capacity_to_pay_us = channel_amount_receivable(c); |
|
|
|
|
|
|
|
/* Does the peer have sufficient balance to pay us,
|
|
|
|
* even after having taken into account their reserve? */ |
|
|
@ -628,9 +593,7 @@ static struct route_info **select_inchan_mpp(const tal_t *ctx, |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
/* Can the peer pay to us? */ |
|
|
|
if (!incoming_capacity(ld, c, &capacity_to_pay_us)) |
|
|
|
continue; |
|
|
|
capacity_to_pay_us = channel_amount_receivable(c); |
|
|
|
|
|
|
|
/* Is the channel in the inchans input? */ |
|
|
|
found = NULL; |
|
|
|