Skip to content

Commit 9ac68ea

Browse files
authored
Merge branch 'lightningdevkit:main' into issue1462
2 parents 163ab58 + 46e58ae commit 9ac68ea

File tree

13 files changed

+545
-222
lines changed

13 files changed

+545
-222
lines changed

lightning-invoice/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
1212

1313
//! This crate provides data structures to represent
14-
//! [lightning BOLT11](https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md)
14+
//! [lightning BOLT11](https://github.com/lightning/bolts/blob/master/11-payment-encoding.md)
1515
//! invoices and functions to create, encode and decode these. If you just want to use the standard
1616
//! en-/decoding functionality this should get you started:
1717
//!

lightning-invoice/src/payment.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
//! # use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
3939
//! # use lightning::ln::channelmanager::{ChannelDetails, PaymentId, PaymentSendFailure};
4040
//! # use lightning::ln::msgs::LightningError;
41-
//! # use lightning::routing::scoring::Score;
4241
//! # use lightning::routing::network_graph::NodeId;
4342
//! # use lightning::routing::router::{Route, RouteHop, RouteParameters};
43+
//! # use lightning::routing::scoring::{ChannelUsage, Score};
4444
//! # use lightning::util::events::{Event, EventHandler, EventsProvider};
4545
//! # use lightning::util::logger::{Logger, Record};
4646
//! # use lightning::util::ser::{Writeable, Writer};
@@ -90,7 +90,7 @@
9090
//! # }
9191
//! # impl Score for FakeScorer {
9292
//! # fn channel_penalty_msat(
93-
//! # &self, _short_channel_id: u64, _send_amt: u64, _chan_amt: u64, _source: &NodeId, _target: &NodeId
93+
//! # &self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId, _usage: ChannelUsage
9494
//! # ) -> u64 { 0 }
9595
//! # fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
9696
//! # fn payment_path_successful(&mut self, _path: &[&RouteHop]) {}
@@ -604,6 +604,7 @@ mod tests {
604604
use lightning::ln::msgs::{ChannelMessageHandler, ErrorAction, LightningError};
605605
use lightning::routing::network_graph::NodeId;
606606
use lightning::routing::router::{PaymentParameters, Route, RouteHop};
607+
use lightning::routing::scoring::ChannelUsage;
607608
use lightning::util::test_utils::TestLogger;
608609
use lightning::util::errors::APIError;
609610
use lightning::util::events::{Event, EventsProvider, MessageSendEvent, MessageSendEventsProvider};
@@ -1444,7 +1445,7 @@ mod tests {
14441445

14451446
impl Score for TestScorer {
14461447
fn channel_penalty_msat(
1447-
&self, _short_channel_id: u64, _send_amt: u64, _chan_amt: u64, _source: &NodeId, _target: &NodeId
1448+
&self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId, _usage: ChannelUsage
14481449
) -> u64 { 0 }
14491450

14501451
fn payment_path_failed(&mut self, actual_path: &[&RouteHop], actual_short_channel_id: u64) {

lightning/src/chain/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub trait Access {
7676
/// Returns an error if `genesis_hash` is for a different chain or if such a transaction output
7777
/// is unknown.
7878
///
79-
/// [`short_channel_id`]: https://github.com/lightningnetwork/lightning-rfc/blob/master/07-routing-gossip.md#definition-of-short_channel_id
79+
/// [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
8080
fn get_utxo(&self, genesis_hash: &BlockHash, short_channel_id: u64) -> Result<TxOut, AccessError>;
8181
}
8282

lightning/src/ln/chan_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub fn build_closing_transaction(to_holder_value_sat: u64, to_counterparty_value
139139
}
140140

141141
/// Implements the per-commitment secret storage scheme from
142-
/// [BOLT 3](https://github.com/lightningnetwork/lightning-rfc/blob/dcbf8583976df087c79c3ce0b535311212e6812d/03-transactions.md#efficient-per-commitment-secret-storage).
142+
/// [BOLT 3](https://github.com/lightning/bolts/blob/dcbf8583976df087c79c3ce0b535311212e6812d/03-transactions.md#efficient-per-commitment-secret-storage).
143143
///
144144
/// Allows us to keep track of all of the revocation secrets of our counterparty in just 50*32 bytes
145145
/// or so.

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ enum InboundHTLCState {
126126
/// signatures in a commitment_signed message.
127127
/// Implies AwaitingRemoteRevoke.
128128
///
129-
/// [BOLT #2]: https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md
129+
/// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
130130
AwaitingRemoteRevokeToAnnounce(PendingHTLCStatus),
131131
/// Included in a received commitment_signed message (implying we've revoke_and_ack'd it).
132132
/// We have also included this HTLC in our latest commitment_signed and are now just waiting
@@ -775,7 +775,7 @@ pub const MAX_CHAN_DUST_LIMIT_SATOSHIS: u64 = MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS
775775
/// In order to avoid having to concern ourselves with standardness during the closing process, we
776776
/// simply require our counterparty to use a dust limit which will leave any segwit output
777777
/// standard.
778-
/// See https://github.com/lightningnetwork/lightning-rfc/issues/905 for more details.
778+
/// See https://github.com/lightning/bolts/issues/905 for more details.
779779
pub const MIN_CHAN_DUST_LIMIT_SATOSHIS: u64 = 354;
780780

781781
/// Used to return a simple Error back to ChannelManager. Will get converted to a

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2258,7 +2258,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
22582258
msg.cltv_expiry.write(&mut res).expect("Writes cannot fail");
22592259
}
22602260
else if code == 0x1000 | 20 {
2261-
// TODO: underspecified, follow https://github.com/lightningnetwork/lightning-rfc/issues/791
2261+
// TODO: underspecified, follow https://github.com/lightning/bolts/issues/791
22622262
0u16.write(&mut res).expect("Writes cannot fail");
22632263
}
22642264
(chan_update.serialized_length() as u16 + 2).write(&mut res).expect("Writes cannot fail");

lightning/src/ln/features.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//! supports a feature if it advertises the feature (as either required or optional) to its peers.
2020
//! And the implementation can interpret a feature if the feature is known to it.
2121
//!
22-
//! [BOLT #9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md
22+
//! [BOLT #9]: https://github.com/lightning/bolts/blob/master/09-features.md
2323
//! [messages]: crate::ln::msgs
2424
2525
use {io, io_extras};
@@ -244,7 +244,7 @@ mod sealed {
244244
///
245245
/// See [BOLT #9] for details.
246246
///
247-
/// [BOLT #9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md
247+
/// [BOLT #9]: https://github.com/lightning/bolts/blob/master/09-features.md
248248
pub trait $feature: Context {
249249
/// The bit used to signify that the feature is required.
250250
const EVEN_BIT: usize = $odd_bit - 1;

lightning/src/ln/peer_channel_encryptor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use util::crypto::hkdf_extract_expand_twice;
2525
use bitcoin::hashes::hex::ToHex;
2626

2727
/// Maximum Lightning message data length according to
28-
/// [BOLT-8](https://github.com/lightningnetwork/lightning-rfc/blob/v1.0/08-transport.md#lightning-message-specification)
29-
/// and [BOLT-1](https://github.com/lightningnetwork/lightning-rfc/blob/master/01-messaging.md#lightning-message-format):
28+
/// [BOLT-8](https://github.com/lightning/bolts/blob/v1.0/08-transport.md#lightning-message-specification)
29+
/// and [BOLT-1](https://github.com/lightning/bolts/blob/master/01-messaging.md#lightning-message-format):
3030
pub const LN_MAX_MSG_LEN: usize = ::core::u16::MAX as usize; // Must be equal to 65535
3131

3232
// Sha256("Noise_XK_secp256k1_ChaChaPoly_SHA256")

lightning/src/ln/script.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use io;
1616

1717
/// A script pubkey for shutting down a channel as defined by [BOLT #2].
1818
///
19-
/// [BOLT #2]: https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md
19+
/// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
2020
#[derive(Clone, PartialEq)]
2121
pub struct ShutdownScript(ShutdownScriptImpl);
2222

@@ -25,7 +25,7 @@ pub struct ShutdownScript(ShutdownScriptImpl);
2525
pub struct InvalidShutdownScript {
2626
/// The script that did not meet the requirements from [BOLT #2].
2727
///
28-
/// [BOLT #2]: https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md
28+
/// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
2929
pub script: Script
3030
}
3131

lightning/src/ln/wire.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! Wire encoding/decoding for Lightning messages according to [BOLT #1], and for
1111
//! custom message through the [`CustomMessageReader`] trait.
1212
//!
13-
//! [BOLT #1]: https://github.com/lightningnetwork/lightning-rfc/blob/master/01-messaging.md
13+
//! [BOLT #1]: https://github.com/lightning/bolts/blob/master/01-messaging.md
1414
1515
use io;
1616
use ln::msgs;

lightning/src/routing/network_graph.rs

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub struct ReadOnlyNetworkGraph<'a> {
150150
/// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
151151
/// return packet by a node along the route. See [BOLT #4] for details.
152152
///
153-
/// [BOLT #4]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md
153+
/// [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md
154154
#[derive(Clone, Debug, PartialEq)]
155155
pub enum NetworkUpdate {
156156
/// An error indicating a `channel_update` messages should be applied via
@@ -695,7 +695,7 @@ impl ChannelInfo {
695695
return None;
696696
}
697697
};
698-
Some((DirectedChannelInfo { channel: self, direction }, source))
698+
Some((DirectedChannelInfo::new(self, direction), source))
699699
}
700700

701701
/// Returns a [`DirectedChannelInfo`] for the channel directed from the given `source` to a
@@ -710,7 +710,7 @@ impl ChannelInfo {
710710
return None;
711711
}
712712
};
713-
Some((DirectedChannelInfo { channel: self, direction }, target))
713+
Some((DirectedChannelInfo::new(self, direction), target))
714714
}
715715
}
716716

@@ -739,35 +739,53 @@ impl_writeable_tlv_based!(ChannelInfo, {
739739
pub struct DirectedChannelInfo<'a> {
740740
channel: &'a ChannelInfo,
741741
direction: Option<&'a ChannelUpdateInfo>,
742+
htlc_maximum_msat: u64,
743+
effective_capacity: EffectiveCapacity,
742744
}
743745

744746
impl<'a> DirectedChannelInfo<'a> {
747+
#[inline]
748+
fn new(channel: &'a ChannelInfo, direction: Option<&'a ChannelUpdateInfo>) -> Self {
749+
let htlc_maximum_msat = direction.and_then(|direction| direction.htlc_maximum_msat);
750+
let capacity_msat = channel.capacity_sats.map(|capacity_sats| capacity_sats * 1000);
751+
752+
let (htlc_maximum_msat, effective_capacity) = match (htlc_maximum_msat, capacity_msat) {
753+
(Some(amount_msat), Some(capacity_msat)) => {
754+
let htlc_maximum_msat = cmp::min(amount_msat, capacity_msat);
755+
(htlc_maximum_msat, EffectiveCapacity::Total { capacity_msat })
756+
},
757+
(Some(amount_msat), None) => {
758+
(amount_msat, EffectiveCapacity::MaximumHTLC { amount_msat })
759+
},
760+
(None, Some(capacity_msat)) => {
761+
(capacity_msat, EffectiveCapacity::Total { capacity_msat })
762+
},
763+
(None, None) => (EffectiveCapacity::Unknown.as_msat(), EffectiveCapacity::Unknown),
764+
};
765+
766+
Self {
767+
channel, direction, htlc_maximum_msat, effective_capacity
768+
}
769+
}
770+
745771
/// Returns information for the channel.
746772
pub fn channel(&self) -> &'a ChannelInfo { self.channel }
747773

748774
/// Returns information for the direction.
749775
pub fn direction(&self) -> Option<&'a ChannelUpdateInfo> { self.direction }
750776

777+
/// Returns the maximum HTLC amount allowed over the channel in the direction.
778+
pub fn htlc_maximum_msat(&self) -> u64 {
779+
self.htlc_maximum_msat
780+
}
781+
751782
/// Returns the [`EffectiveCapacity`] of the channel in the direction.
752783
///
753784
/// This is either the total capacity from the funding transaction, if known, or the
754785
/// `htlc_maximum_msat` for the direction as advertised by the gossip network, if known,
755-
/// whichever is smaller.
786+
/// otherwise.
756787
pub fn effective_capacity(&self) -> EffectiveCapacity {
757-
let capacity_msat = self.channel.capacity_sats.map(|capacity_sats| capacity_sats * 1000);
758-
self.direction
759-
.and_then(|direction| direction.htlc_maximum_msat)
760-
.map(|max_htlc_msat| {
761-
let capacity_msat = capacity_msat.unwrap_or(u64::max_value());
762-
if max_htlc_msat < capacity_msat {
763-
EffectiveCapacity::MaximumHTLC { amount_msat: max_htlc_msat }
764-
} else {
765-
EffectiveCapacity::Total { capacity_msat }
766-
}
767-
})
768-
.or_else(|| capacity_msat.map(|capacity_msat|
769-
EffectiveCapacity::Total { capacity_msat }))
770-
.unwrap_or(EffectiveCapacity::Unknown)
788+
self.effective_capacity
771789
}
772790

773791
/// Returns `Some` if [`ChannelUpdateInfo`] is available in the direction.
@@ -805,6 +823,10 @@ impl<'a> DirectedChannelInfoWithUpdate<'a> {
805823
/// Returns the [`EffectiveCapacity`] of the channel in the direction.
806824
#[inline]
807825
pub(super) fn effective_capacity(&self) -> EffectiveCapacity { self.inner.effective_capacity() }
826+
827+
/// Returns the maximum HTLC amount allowed over the channel in the direction.
828+
#[inline]
829+
pub(super) fn htlc_maximum_msat(&self) -> u64 { self.inner.htlc_maximum_msat() }
808830
}
809831

810832
impl<'a> fmt::Debug for DirectedChannelInfoWithUpdate<'a> {
@@ -817,6 +839,7 @@ impl<'a> fmt::Debug for DirectedChannelInfoWithUpdate<'a> {
817839
///
818840
/// While this may be smaller than the actual channel capacity, amounts greater than
819841
/// [`Self::as_msat`] should not be routed through the channel.
842+
#[derive(Clone, Copy)]
820843
pub enum EffectiveCapacity {
821844
/// The available liquidity in the channel known from being a channel counterparty, and thus a
822845
/// direct hop.

0 commit comments

Comments
 (0)