lightningd: take into account outstanding HTLCs for 'spendable_msat'
The current calculation ignores them, which is unrealistic. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
ab31f40aa2
commit
bb6c34fb13
|
@ -542,6 +542,23 @@ static struct amount_sat commit_txfee(const struct channel *channel,
|
|||
return commit_tx_base_fee(local_feerate, num_untrimmed_htlcs);
|
||||
}
|
||||
|
||||
static void subtract_offered_htlcs(const struct channel *channel,
|
||||
struct amount_msat *amount)
|
||||
{
|
||||
const struct htlc_out *hout;
|
||||
struct htlc_out_map_iter outi;
|
||||
struct lightningd *ld = channel->peer->ld;
|
||||
|
||||
for (hout = htlc_out_map_first(&ld->htlcs_out, &outi);
|
||||
hout;
|
||||
hout = htlc_out_map_next(&ld->htlcs_out, &outi)) {
|
||||
if (hout->key.channel != channel)
|
||||
continue;
|
||||
if (!amount_msat_sub(amount, *amount, hout->msat))
|
||||
*amount = AMOUNT_MSAT(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void json_add_channel(struct lightningd *ld,
|
||||
struct json_stream *response, const char *key,
|
||||
const struct channel *channel)
|
||||
|
@ -656,6 +673,9 @@ static void json_add_channel(struct lightningd *ld,
|
|||
channel->channel_info.their_config.channel_reserve))
|
||||
spendable = AMOUNT_MSAT(0);
|
||||
|
||||
/* Take away any currently-offered HTLCs. */
|
||||
subtract_offered_htlcs(channel, &spendable);
|
||||
|
||||
/* If we're funder, subtract txfees we'll need to spend this */
|
||||
if (channel->funder == LOCAL) {
|
||||
if (!amount_msat_sub_sat(&spendable, spendable,
|
||||
|
|
|
@ -2047,7 +2047,6 @@ def test_setchannelfee_all(node_factory, bitcoind):
|
|||
assert result['channels'][1]['short_channel_id'] == scid3
|
||||
|
||||
|
||||
@pytest.mark.xfail(strict=True)
|
||||
def test_channel_spendable(node_factory, bitcoind):
|
||||
"""Test that spendable_msat is accurate"""
|
||||
sats = 10**6
|
||||
|
|
Loading…
Reference in New Issue