Skip to content

Commit d0b4f52

Browse files
authored
Merge pull request #669 from joemphilips/fix_capacity-is-always-zero-bug_in_list_channels
Fix bug in Channel
2 parents 7dca3a9 + 54916db commit d0b4f52

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,8 +1696,8 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
16961696
/// corner case properly.
16971697
pub fn get_inbound_outbound_available_balance_msat(&self) -> (u64, u64) {
16981698
// Note that we have to handle overflow due to the above case.
1699-
(cmp::min(self.channel_value_satoshis as i64 * 1000 - self.value_to_self_msat as i64 - self.get_inbound_pending_htlc_stats().1 as i64, 0) as u64,
1700-
cmp::min(self.value_to_self_msat as i64 - self.get_outbound_pending_htlc_stats().1 as i64, 0) as u64)
1699+
(cmp::max(self.channel_value_satoshis as i64 * 1000 - self.value_to_self_msat as i64 - self.get_inbound_pending_htlc_stats().1 as i64, 0) as u64,
1700+
cmp::max(self.value_to_self_msat as i64 - self.get_outbound_pending_htlc_stats().1 as i64, 0) as u64)
17011701
}
17021702

17031703
// Get the fee cost of a commitment tx with a given number of HTLC outputs.

lightning/src/ln/functional_tests.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,25 @@ fn test_chan_reserve_violation_inbound_htlc_inbound_chan() {
18931893
check_added_monitors!(nodes[1], 1);
18941894
}
18951895

1896+
#[test]
1897+
fn test_inbound_outbound_capacity_is_not_zero() {
1898+
let chanmon_cfgs = create_chanmon_cfgs(2);
1899+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1900+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
1901+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1902+
let _ = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known());
1903+
let channels0 = node_chanmgrs[0].list_channels();
1904+
let channels1 = node_chanmgrs[1].list_channels();
1905+
assert_eq!(channels0.len(), 1);
1906+
assert_eq!(channels1.len(), 1);
1907+
1908+
assert_eq!(channels0[0].inbound_capacity_msat, 95000000);
1909+
assert_eq!(channels1[0].outbound_capacity_msat, 95000000);
1910+
1911+
assert_eq!(channels0[0].outbound_capacity_msat, 100000 * 1000 - 95000000);
1912+
assert_eq!(channels1[0].inbound_capacity_msat, 100000 * 1000 - 95000000);
1913+
}
1914+
18961915
fn commit_tx_fee_msat(feerate: u32, num_htlcs: u64) -> u64 {
18971916
(COMMITMENT_TX_BASE_WEIGHT + num_htlcs * COMMITMENT_TX_WEIGHT_PER_HTLC) * feerate as u64 / 1000 * 1000
18981917
}

0 commit comments

Comments
 (0)