Skip to content

Commit c741044

Browse files
Mateusz FaltynMateusz Faltyn
authored andcommitted
Document lightning crate features.
1 parent 197cbc4 commit c741044

File tree

12 files changed

+65
-14
lines changed

12 files changed

+65
-14
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/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/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@
1717
//! figure out how best to make networking happen/timers fire/things get written to disk/keys get
1818
//! generated/etc. This makes it a good candidate for tight integration into an existing wallet
1919
//! instead of having a rather-separate lightning appendage to a wallet.
20+
//!
21+
//! `default` features are:
22+
//!
23+
//! * `std` - enables functionalities which require `std`, including `std::io` trait implementations and things which utilize time
24+
//! * `grind_signatures` - enables generation of [low-r bitcoin signatures](https://bitcoin.stackexchange.com/questions/111660/what-is-signature-grinding),
25+
//! which saves 1 byte per signature in 50% of the cases (see [bitcoin PR #13666](https://github.com/bitcoin/bitcoin/pull/13666))
26+
//!
27+
//! Available features are:
28+
//!
29+
//! * `std`
30+
//! * `grind_signatures`
31+
//! * `no-std ` - exposes write trait implementations from the `core2` crate (at least one of `no-std` or `std` are required)
32+
//! * Skip logging of messages at levels below the given log level:
33+
//! * `max_level_off`
34+
//! * `max_level_error`
35+
//! * `max_level_warn`
36+
//! * `max_level_info`
37+
//! * `max_level_debug`
38+
//! * `max_level_trace`
2039
2140
#![cfg_attr(not(any(test, fuzzing, feature = "_test_utils")), deny(missing_docs))]
2241
#![cfg_attr(not(any(test, fuzzing, feature = "_test_utils")), forbid(unsafe_code))]

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: 1 addition & 1 deletion
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

lightning/src/routing/scoring.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,14 @@ impl<G: Deref<Target = NetworkGraph>, L: Deref, T: Time> Score for Probabilistic
903903
fn channel_penalty_msat(
904904
&self, short_channel_id: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage
905905
) -> u64 {
906+
if let EffectiveCapacity::ExactLiquidity { liquidity_msat } = usage.effective_capacity {
907+
if usage.amount_msat > liquidity_msat {
908+
return u64::max_value();
909+
} else {
910+
return self.params.base_penalty_msat;
911+
};
912+
}
913+
906914
let liquidity_offset_half_life = self.params.liquidity_offset_half_life;
907915
let amount_msat = usage.amount_msat;
908916
let capacity_msat = usage.effective_capacity.as_msat()
@@ -2574,4 +2582,28 @@ mod tests {
25742582
let usage = ChannelUsage { inflight_htlc_msat: 251, ..usage };
25752583
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), u64::max_value());
25762584
}
2585+
2586+
#[test]
2587+
fn removes_uncertainity_when_exact_liquidity_known() {
2588+
let network_graph = network_graph();
2589+
let logger = TestLogger::new();
2590+
let params = ProbabilisticScoringParameters::default();
2591+
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
2592+
let source = source_node_id();
2593+
let target = target_node_id();
2594+
2595+
let base_penalty_msat = params.base_penalty_msat;
2596+
let usage = ChannelUsage {
2597+
amount_msat: 750,
2598+
inflight_htlc_msat: 0,
2599+
effective_capacity: EffectiveCapacity::ExactLiquidity { liquidity_msat: 1_000 },
2600+
};
2601+
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), base_penalty_msat);
2602+
2603+
let usage = ChannelUsage { amount_msat: 1_000, ..usage };
2604+
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), base_penalty_msat);
2605+
2606+
let usage = ChannelUsage { amount_msat: 1_001, ..usage };
2607+
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), u64::max_value());
2608+
}
25772609
}

0 commit comments

Comments
 (0)