Skip to content

Commit 1a9b3f1

Browse files
committed
Add a next-outbound-HTLC minimum field to chan details and use it
In the coming commits, in order to ensure all routes we generate are usable, we'll start calculating the next-HTLC minimum for our channels and using it in the router. Here we set this up by adding an always-0 field for it in `ChannelDetails` and use it when routing.
1 parent a9f8a14 commit 1a9b3f1

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

fuzz/src/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
265265
balance_msat: 0,
266266
outbound_capacity_msat: capacity.saturating_mul(1000),
267267
next_outbound_htlc_limit_msat: capacity.saturating_mul(1000),
268+
next_outbound_htlc_minimum_msat: 0,
268269
inbound_htlc_minimum_msat: None,
269270
inbound_htlc_maximum_msat: None,
270271
config: None,

lightning/src/ln/channel.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ pub struct AvailableBalances {
7373
pub outbound_capacity_msat: u64,
7474
/// The maximum value we can assign to the next outbound HTLC
7575
pub next_outbound_htlc_limit_msat: u64,
76+
/// The minimum value we can assign to the next outbound HTLC
77+
pub next_outbound_htlc_min_msat: u64,
7678
}
7779

7880
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -2762,6 +2764,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
27622764
0) as u64,
27632765
outbound_capacity_msat,
27642766
next_outbound_htlc_limit_msat: available_capacity_msat,
2767+
next_outbound_htlc_min_msat: 0,
27652768
balance_msat,
27662769
}
27672770
}

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,8 +1274,14 @@ pub struct ChannelDetails {
12741274
/// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
12751275
/// to use a limit as close as possible to the HTLC limit we can currently send.
12761276
///
1277-
/// See also [`ChannelDetails::balance_msat`] and [`ChannelDetails::outbound_capacity_msat`].
1277+
/// See also [`ChannelDetails::next_outbound_htlc_minimum_msat`],
1278+
/// [`ChannelDetails::balance_msat`], and [`ChannelDetails::outbound_capacity_msat`].
12781279
pub next_outbound_htlc_limit_msat: u64,
1280+
/// The minimum value for sending a single HTLC to the remote peer. This is the equivalent of
1281+
/// [`ChannelDetails::next_outbound_htlc_limit_msat`] but represents a lower-bound, rather than
1282+
/// an upper-bound. This is intended for use when routing, allowing us to ensure we pick a
1283+
/// route which is valid.
1284+
pub next_outbound_htlc_minimum_msat: u64,
12791285
/// The available inbound capacity for the remote peer to send HTLCs to us. This does not
12801286
/// include any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
12811287
/// available for inclusion in new inbound HTLCs).
@@ -1395,6 +1401,7 @@ impl ChannelDetails {
13951401
inbound_capacity_msat: balance.inbound_capacity_msat,
13961402
outbound_capacity_msat: balance.outbound_capacity_msat,
13971403
next_outbound_htlc_limit_msat: balance.next_outbound_htlc_limit_msat,
1404+
next_outbound_htlc_minimum_msat: balance.next_outbound_htlc_min_msat,
13981405
user_channel_id: channel.get_user_id(),
13991406
confirmations_required: channel.minimum_depth(),
14001407
confirmations: Some(channel.get_funding_tx_confirmations(best_block_height)),
@@ -6951,10 +6958,9 @@ impl Writeable for ChannelDetails {
69516958
(14, user_channel_id_low, required),
69526959
(16, self.balance_msat, required),
69536960
(18, self.outbound_capacity_msat, required),
6954-
// Note that by the time we get past the required read above, outbound_capacity_msat will be
6955-
// filled in, so we can safely unwrap it here.
6956-
(19, self.next_outbound_htlc_limit_msat, (default_value, outbound_capacity_msat.0.unwrap() as u64)),
6961+
(19, self.next_outbound_htlc_limit_msat, required),
69576962
(20, self.inbound_capacity_msat, required),
6963+
(21, self.next_outbound_htlc_minimum_msat, required),
69586964
(22, self.confirmations_required, option),
69596965
(24, self.force_close_spend_delay, option),
69606966
(26, self.is_outbound, required),
@@ -6991,6 +6997,7 @@ impl Readable for ChannelDetails {
69916997
// filled in, so we can safely unwrap it here.
69926998
(19, next_outbound_htlc_limit_msat, (default_value, outbound_capacity_msat.0.unwrap() as u64)),
69936999
(20, inbound_capacity_msat, required),
7000+
(21, next_outbound_htlc_minimum_msat, (default_value, 0)),
69947001
(22, confirmations_required, option),
69957002
(24, force_close_spend_delay, option),
69967003
(26, is_outbound, required),
@@ -7024,6 +7031,7 @@ impl Readable for ChannelDetails {
70247031
balance_msat: balance_msat.0.unwrap(),
70257032
outbound_capacity_msat: outbound_capacity_msat.0.unwrap(),
70267033
next_outbound_htlc_limit_msat: next_outbound_htlc_limit_msat.0.unwrap(),
7034+
next_outbound_htlc_minimum_msat: next_outbound_htlc_minimum_msat.0.unwrap(),
70277035
inbound_capacity_msat: inbound_capacity_msat.0.unwrap(),
70287036
confirmations_required,
70297037
confirmations,

lightning/src/routing/router.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ impl<'a> CandidateRouteHop<'a> {
929929

930930
fn htlc_minimum_msat(&self) -> u64 {
931931
match self {
932-
CandidateRouteHop::FirstHop { .. } => 0,
932+
CandidateRouteHop::FirstHop { details } => details.next_outbound_htlc_minimum_msat,
933933
CandidateRouteHop::PublicHop { info, .. } => info.direction().htlc_minimum_msat,
934934
CandidateRouteHop::PrivateHop { hint } => hint.htlc_minimum_msat.unwrap_or(0),
935935
}
@@ -2460,6 +2460,7 @@ mod tests {
24602460
balance_msat: 0,
24612461
outbound_capacity_msat,
24622462
next_outbound_htlc_limit_msat: outbound_capacity_msat,
2463+
next_outbound_htlc_minimum_msat: 0,
24632464
inbound_capacity_msat: 42,
24642465
unspendable_punishment_reserve: None,
24652466
confirmations_required: None,
@@ -6121,6 +6122,7 @@ pub(crate) mod bench_utils {
61216122
user_channel_id: 0,
61226123
balance_msat: 10_000_000_000,
61236124
outbound_capacity_msat: 10_000_000_000,
6125+
next_outbound_htlc_minimum_msat: 0,
61246126
next_outbound_htlc_limit_msat: 10_000_000_000,
61256127
inbound_capacity_msat: 0,
61266128
unspendable_punishment_reserve: None,

0 commit comments

Comments
 (0)