rust-lightning
20 months agoDrop uneccessary `if {...; bool}` pattern in PeerManager 2022-08-cleanup-ratelimits
Matt Corallo [Mon, 15 Aug 2022 19:38:45 +0000 (19:38 +0000)]
Drop uneccessary `if {...; bool}` pattern in PeerManager

20 months agoReplace manual iteration with for loops in outbound gossip sync
Matt Corallo [Mon, 15 Aug 2022 18:08:13 +0000 (18:08 +0000)]
Replace manual iteration with for loops in outbound gossip sync

20 months agoBackfill gossip without buffering directly in LDK
Matt Corallo [Tue, 9 Aug 2022 21:26:16 +0000 (21:26 +0000)]
Backfill gossip without buffering directly in LDK

Instead of backfilling gossip by buffering (up to) ten messages at
a time, only buffer one message at a time, as the peers' outbound
socket buffer drains. This moves the outbound backfill messages out
of `PeerHandler` and into the operating system buffer, where it
arguably belongs.

Not buffering causes us to walk the gossip B-Trees somewhat more
often, but avoids allocating vecs for the responses. While its
probably (without having benchmarked it) a net performance loss, it
simplifies buffer tracking and leaves us with more room to play
with the buffer sizing constants as we add onion message forwarding
which is an important win.

Note that because we change how often we check if we're out of
messages to send before pinging, we slightly change how many
messages are exchanged at once, impacting the
`test_do_attempt_write_data` constants.

20 months agoClarify comment on BUFFER_DRAIN_MSGS_PER_TICK.
Matt Corallo [Tue, 9 Aug 2022 21:45:19 +0000 (21:45 +0000)]
Clarify comment on BUFFER_DRAIN_MSGS_PER_TICK.

20 months agoUse util methods in `Peer` to decide when to forward
Valentine Wallace [Tue, 9 Aug 2022 21:20:56 +0000 (21:20 +0000)]
Use util methods in `Peer` to decide when to forward

This consolidates our various checks on peer buffer space into the
`Peer` impl itself, making the thresholds at which we stop taking
various actions on a peer more readable as a whole.

This commit was primarily authored by `Valentine Wallace
<vwallace@protonmail.com>` with some amendments by `Matt Corallo
<git@bluematt.me>`.

20 months agoMerge pull request #1651 from TheBlueMatt/2022-08-export-chan-list
Matt Corallo [Mon, 8 Aug 2022 16:59:53 +0000 (16:59 +0000)]
Merge pull request #1651 from TheBlueMatt/2022-08-export-chan-list

[C Bindings] Expose channel and nodes list in `ReadOnlyNetworkGraph`

20 months agoMerge pull request #1654 from TheBlueMatt/2022-08-update-libfuzzer
valentinewallace [Mon, 8 Aug 2022 15:37:42 +0000 (11:37 -0400)]
Merge pull request #1654 from TheBlueMatt/2022-08-update-libfuzzer

Update libfuzzer-sys to new upstream inclusion method

20 months agoUpdate libfuzzer-sys to new upstream inclusion method 2022-08-update-libfuzzer
Matt Corallo [Sun, 7 Aug 2022 19:02:33 +0000 (19:02 +0000)]
Update libfuzzer-sys to new upstream inclusion method

Dunno why they changed it, but the old "depend directly on git"
thing that cargo-fuzz used forever is now deprecated that that
repo is archived, they've now moved to another repo and publish
properly on crates.io.

21 months ago[C Bindings] Expose channel and nodes list in `ReadOnlyNetworkGraph` 2022-08-export-chan-list
Matt Corallo [Fri, 5 Aug 2022 03:20:53 +0000 (03:20 +0000)]
[C Bindings] Expose channel and nodes list in `ReadOnlyNetworkGraph`

21 months agoMerge pull request #1638 from ViktorTigerstrom/2022-07-update-decode-update-add-htlc...
Matt Corallo [Wed, 3 Aug 2022 17:44:46 +0000 (17:44 +0000)]
Merge pull request #1638 from ViktorTigerstrom/2022-07-update-decode-update-add-htlc-onion-return-parameters

Don't return `channel_state` from `decode_update_add_htlc_onion`

21 months agoMerge pull request #1619 from G8XSU/main
Matt Corallo [Wed, 3 Aug 2022 17:37:51 +0000 (17:37 +0000)]
Merge pull request #1619 from G8XSU/main

Add config support for 'their_channel_reserve_proportional_millionths' [#1498]

21 months agoMerge pull request #1503 from valentinewallace/2022-05-onion-msgs
Matt Corallo [Wed, 3 Aug 2022 04:39:56 +0000 (04:39 +0000)]
Merge pull request #1503 from valentinewallace/2022-05-onion-msgs

Onion messages v1

21 months agoFix possible incomplete read bug on onion packet decode
Valentine Wallace [Tue, 12 Jul 2022 20:04:42 +0000 (16:04 -0400)]
Fix possible incomplete read bug on onion packet decode

Pre-existing to this PR, we were reading next packet bytes with io::Read::read,
which is not guaranteed to read all the bytes we need, only guaranteed to read
*some* bytes.

We fix this to be read_exact, which is guaranteed to read all the next hop
packet bytes.

21 months agoError when attempting to send an OM to a blinded route with 0 hops
Valentine Wallace [Thu, 23 Jun 2022 19:51:43 +0000 (15:51 -0400)]
Error when attempting to send an OM to a blinded route with 0 hops

21 months agoAdd SendError enum for onion messages and error on too-big packets
Valentine Wallace [Thu, 23 Jun 2022 19:47:25 +0000 (15:47 -0400)]
Add SendError enum for onion messages and error on too-big packets

21 months agoAdd test utilities and integration tests for onion messages
Valentine Wallace [Sat, 4 Jun 2022 20:22:20 +0000 (13:22 -0700)]
Add test utilities and integration tests for onion messages

21 months agoSignificantly expand onion message documentation
Valentine Wallace [Thu, 23 Jun 2022 19:45:33 +0000 (15:45 -0400)]
Significantly expand onion message documentation

21 months agoImplement receiving and forwarding onion messages
Valentine Wallace [Sat, 28 May 2022 01:39:56 +0000 (18:39 -0700)]
Implement receiving and forwarding onion messages

This required adapting `onion_utils::decode_next_hop` to work for both payments
and onion messages.

Currently we just print out the path_id of any onion messages we receive. In
the future, these received onion messages will be redirected to their
respective handlers: i.e. an invoice_request will go to an InvoiceHandler,
custom onion messages will go to a custom handler, etc.

21 months agoSupport sending onion messages
Valentine Wallace [Sat, 28 May 2022 01:31:27 +0000 (18:31 -0700)]
Support sending onion messages

This adds several utilities in service of then adding
OnionMessenger::send_onion_message, which can send to either an unblinded
pubkey or a blinded route. Sending custom TLVs and sending an onion message
containing a reply path are not yet supported.

We also need to split the construct_keys_callback macro into two macros to
avoid an unused assignment warning.

21 months agoAdd baseline OnionMessenger and msgs::OnionMessage and its serialization
Valentine Wallace [Wed, 22 Jun 2022 21:03:06 +0000 (17:03 -0400)]
Add baseline OnionMessenger and msgs::OnionMessage and its serialization

OnionMessenger will be hooked up to the PeerManager to send and receive OMs in
a follow-up PR.

21 months agoKeysInterface: add new ecdh method
Valentine Wallace [Mon, 11 Jul 2022 20:27:10 +0000 (16:27 -0400)]
KeysInterface: add new ecdh method

This method will help us avoid retrieving our node secret, something we want to
get rid of entirely.  It will be used in upcoming commits when decoding the
onion message packet, and in future PRs to help us get rid of
KeysInterface::get_node_secret usages across the codebase

21 months agoAdd onion_message::Packet and adapt construct_onion_packet_with_init_noise for it
Valentine Wallace [Sat, 28 May 2022 00:47:15 +0000 (17:47 -0700)]
Add onion_message::Packet and adapt construct_onion_packet_with_init_noise for it

We need to add a new Packet struct because onion message packet hop_data fields
can be of variable length, whereas regular payment packets are always 1366
bytes.

Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
Co-authored-by: Jeffrey Czyz <jkczyz@gmail.com>
21 months agoAdd config support for 'their_channel_reserve_proportional_millionths' [#1498]
Gursharan Singh [Mon, 18 Jul 2022 23:58:10 +0000 (16:58 -0700)]
Add config support for 'their_channel_reserve_proportional_millionths' [#1498]

It is proportion of the channel value to configure as the
`their_channel_reserve_satoshis` for both outbound and inbound channels.
It decides the minimum balance that the other node has to maintain on their
side, at all times.

21 months agoDon't return `channel_state` from `decode_update_add_htlc_onion`
Viktor Tigerström [Sat, 23 Jul 2022 22:10:48 +0000 (00:10 +0200)]
Don't return `channel_state` from `decode_update_add_htlc_onion`

Currently `decode_update_add_htlc_onion` returns the `channel_state`
lock to ensure that `internal_update_add_htlc` holds a single
`channel_state` lock in when the entire function execution. This is
unnecessary, and since we are moving the channel storage to the
`per_peer_state`, this no longer achieves the goal it was intended for.

We therefore avoid returning the `channel_state` from
`decode_update_add_htlc_onion`, and just retake the lock in
`internal_update_add_htlc` instead.

21 months agoMerge pull request #1637 from tnull/2022-07-contrib-remove-slack
Matt Corallo [Tue, 2 Aug 2022 19:19:12 +0000 (19:19 +0000)]
Merge pull request #1637 from tnull/2022-07-contrib-remove-slack

Remove Slack and update `CONTRIBUTING`

21 months agoRemove Slack and update `CONTRIBUTING`
Elias Rohrer [Thu, 28 Jul 2022 07:26:02 +0000 (09:26 +0200)]
Remove Slack and update `CONTRIBUTING`

21 months agoAdd onion messages module + enable the construction of blinded routes
Valentine Wallace [Fri, 27 May 2022 23:25:15 +0000 (16:25 -0700)]
Add onion messages module + enable the construction of blinded routes

Blinded routes can be provided as destinations for onion messages, when the
recipient prefers to remain anonymous.

We also add supporting utilities for constructing blinded path keys, and
control TLVs structs representing blinded payloads prior to being
encoded/encrypted. These utilities and struct will be re-used in upcoming
commits for sending and receiving/forwarding onion messages.

Finally, add utilities for reading the padding from an onion message's
encrypted TLVs without an intermediate Vec.

21 months agoMerge pull request #1628 from tnull/2022-07-readme-remove-slack
Matt Corallo [Wed, 27 Jul 2022 19:10:04 +0000 (19:10 +0000)]
Merge pull request #1628 from tnull/2022-07-readme-remove-slack

Remove Slack link and other updates to `README`

21 months agoMerge pull request #1635 from TheBlueMatt/2022-07-accessor-pub
Matt Corallo [Wed, 27 Jul 2022 18:46:52 +0000 (18:46 +0000)]
Merge pull request #1635 from TheBlueMatt/2022-07-accessor-pub

Expose `ChannelMonitor::get_counterparty_node_id`

21 months agoMerge pull request #1633 from TheBlueMatt/2022-07-110
valentinewallace [Wed, 27 Jul 2022 18:03:44 +0000 (14:03 -0400)]
Merge pull request #1633 from TheBlueMatt/2022-07-110

Set release date on 0.0.110 release

21 months agoMerge pull request #1632 from TheBlueMatt/2022-07-warnings
Matt Corallo [Wed, 27 Jul 2022 16:29:09 +0000 (16:29 +0000)]
Merge pull request #1632 from TheBlueMatt/2022-07-warnings

Fix compilation warnings

21 months agoRemove 'slack' (and other things)
Elias Rohrer [Fri, 22 Jul 2022 16:28:31 +0000 (18:28 +0200)]
Remove 'slack' (and other things)

21 months agoExpose `ChannelMonitor::get_counterparty_node_id` 2022-07-accessor-pub
Matt Corallo [Wed, 27 Jul 2022 03:53:47 +0000 (03:53 +0000)]
Expose `ChannelMonitor::get_counterparty_node_id`

This fixes an oversight in ac842ed9dd7a36a4a26eb6b856d80ab04eecf750
namely that it left users unable to implement their own
`ChainMonitor` from outside of the `rust-lightning` crate.

21 months agoSet release date on 0.0.110 release 2022-07-110
Matt Corallo [Tue, 26 Jul 2022 23:43:58 +0000 (23:43 +0000)]
Set release date on 0.0.110 release

21 months agoMerge pull request #1629 from TheBlueMatt/2022-07-110 v0.0.110
Matt Corallo [Tue, 26 Jul 2022 23:40:45 +0000 (23:40 +0000)]
Merge pull request #1629 from TheBlueMatt/2022-07-110

Cut 0.0.110

21 months agoBump crate versions to 0.0.110/invoice 0.18
Matt Corallo [Mon, 25 Jul 2022 23:50:50 +0000 (23:50 +0000)]
Bump crate versions to 0.0.110/invoice 0.18

21 months agoAdd CHANGELOG entry for 0.0.110
Matt Corallo [Mon, 25 Jul 2022 23:49:24 +0000 (23:49 +0000)]
Add CHANGELOG entry for 0.0.110

21 months agoDrop unused test code in `lightning-invoice::payment` 2022-07-warnings
Matt Corallo [Tue, 26 Jul 2022 20:31:17 +0000 (20:31 +0000)]
Drop unused test code in `lightning-invoice::payment`

21 months agoFix new compilation warnings in `debug_sync` module
Matt Corallo [Tue, 26 Jul 2022 20:29:36 +0000 (20:29 +0000)]
Fix new compilation warnings in `debug_sync` module

21 months agoMerge pull request #1631 from dunxen/2022-07-disabledflags
Matt Corallo [Tue, 26 Jul 2022 15:53:34 +0000 (15:53 +0000)]
Merge pull request #1631 from dunxen/2022-07-disabledflags

Specify why flags for `channel_disabled` error are zero

21 months agoSpecify why flags for `channel_disabled` error are zero
Duncan Dean [Tue, 26 Jul 2022 07:54:09 +0000 (09:54 +0200)]
Specify why flags for `channel_disabled` error are zero

We can remove the TODO for this and specify why the flags are zero
as it's now fully specified in BOLT 4.

See https://github.com/lightning/bolts/blob/341ec84/04-onion-routing.md?plain=1#L1008

21 months agoMerge pull request #1403 from jurvis/jurvis/add-paymentforwardingfailed-event
Jeffrey Czyz [Tue, 26 Jul 2022 00:23:53 +0000 (19:23 -0500)]
Merge pull request #1403 from jurvis/jurvis/add-paymentforwardingfailed-event

Add HTLCHandlingFailed event

21 months agoMerge pull request #1617 from TheBlueMatt/2022-07-base-ppm
Matt Corallo [Mon, 25 Jul 2022 22:02:10 +0000 (22:02 +0000)]
Merge pull request #1617 from TheBlueMatt/2022-07-base-ppm

Add a per-amount base penalty in the ProbabilisticScorer

21 months agoMerge pull request #1626 from TheBlueMatt/2022-07-fix-pm-docs
Matt Corallo [Mon, 25 Jul 2022 21:56:40 +0000 (21:56 +0000)]
Merge pull request #1626 from TheBlueMatt/2022-07-fix-pm-docs

Remove scary disconenct warnings on PeerManager new connection fns

21 months agoMerge pull request #1611 from TheBlueMatt/2022-07-lower-bounded-estimator-nit
Matt Corallo [Mon, 25 Jul 2022 21:11:07 +0000 (21:11 +0000)]
Merge pull request #1611 from TheBlueMatt/2022-07-lower-bounded-estimator-nit

Use a separate (non-trait) fee-estimation fn in LowerBoundedEstimator

21 months agoMerge pull request #1519 from tnull/2022-06-require-htlc-max
Matt Corallo [Mon, 25 Jul 2022 21:04:54 +0000 (21:04 +0000)]
Merge pull request #1519 from tnull/2022-06-require-htlc-max

Make `htlc_maximum_msat` a required field.

21 months agoRename amount penalty to `liquidity_penalty_amount_multiplier_msat` 2022-07-base-ppm
Matt Corallo [Thu, 21 Jul 2022 17:47:19 +0000 (17:47 +0000)]
Rename amount penalty to `liquidity_penalty_amount_multiplier_msat`

This makes our `ProbabilisticScorer` field names more consistent,
as we add more types of penalties, referring to a penalty as only
the "amount penalty" no longer makes sense - we not have several
amount multiplier penalties.

21 months agoAdd a per-amount base penalty in the `ProbabilisticScorer`
Matt Corallo [Thu, 14 Jul 2022 01:06:10 +0000 (01:06 +0000)]
Add a per-amount base penalty in the `ProbabilisticScorer`

There's not much reason to not have a per-hop-per-amount penalty in
the `ProbabilisticScorer` to go along with the per-hop penalty to
let it scale up to larger amounts, so we add one here.

Notably, we use a divisor of 2^30 instead of 2^20 (like the
equivalent liquidity penalty) as it allows for more flexibility,
and there's not really any reason to worry about us not being able
to create high enough penalties.

Closes #1616

21 months agoTest serialization of `ChannelInfo` and `NodeInfo`
Elias Rohrer [Mon, 25 Jul 2022 18:39:06 +0000 (20:39 +0200)]
Test serialization of `ChannelInfo` and `NodeInfo`

21 months agoDon't fail read `NodeInfo` for inv. `NetAddress`
Elias Rohrer [Mon, 25 Jul 2022 18:38:18 +0000 (20:38 +0200)]
Don't fail read `NodeInfo` for inv. `NetAddress`

Fixes a deserialization incompatibility introduced with #1553.

21 months agoMake `htlc_maximum_msat` a required field.
Elias Rohrer [Mon, 25 Jul 2022 18:35:51 +0000 (20:35 +0200)]
Make `htlc_maximum_msat` a required field.

21 months agoChange `LowerBoundedFeeEstimator` fn name to make it hard to swap 2022-07-lower-bounded-estimator-nit
Matt Corallo [Mon, 25 Jul 2022 18:08:44 +0000 (18:08 +0000)]
Change `LowerBoundedFeeEstimator` fn name to make it hard to swap

This change the method name on `LowerBoundedFeeEstimator` to
further differentiate it from the generic `FeeEstimator` trait.

21 months agoAvoid blanket implementing FeeEstimator for Deref<FeeEstimator>
Matt Corallo [Thu, 21 Jul 2022 21:38:00 +0000 (21:38 +0000)]
Avoid blanket implementing FeeEstimator for Deref<FeeEstimator>

This simplifies things for bindings (and, to some extent,
downstream users) by exploiting the fact that we can always "clone"
a reference to a struct by dereferencing and then creating a new
reference.

21 months agoUse a separate (non-trait) fee-estimation fn in LowerBoundedEstimator
Matt Corallo [Wed, 13 Jul 2022 16:52:27 +0000 (16:52 +0000)]
Use a separate (non-trait) fee-estimation fn in LowerBoundedEstimator

This should make it somewhat more difficult to accidentally use a
straight fee estimator when we actually want a
LowerBoundedFeeEstimator by not having the types be exchangeable at
all.

21 months agoSend failure event if we fail to handle a HTLC
jurvis [Mon, 25 Jul 2022 18:28:51 +0000 (11:28 -0700)]
Send failure event if we fail to handle a HTLC

In `ChannelManager::fail_htlc_backwards_internal`, we push a `HTLCHandlingFailed`
containing some information about the HTLC

21 months agoRemove scary disconenct warnings on PeerManager new connection fns 2022-07-fix-pm-docs
Matt Corallo [Fri, 22 Jul 2022 00:32:17 +0000 (00:32 +0000)]
Remove scary disconenct warnings on PeerManager new connection fns

In 4703d4e72565ddfd150b9368ea036f4973fd7590 we changed
PeerManager::socket_disconnected to no longer require that sockets
which the PeerManager decided to disconnect not be disconnected.
However, we forgot to remove the scary warnings on the
`new_{inbound,outbound}_connection` functions which warned of the
old behavior.

We do so here.

21 months agoAdd utils to handle HTLC handling failure reason
jurvis [Tue, 19 Jul 2022 01:32:05 +0000 (20:32 -0500)]
Add utils to handle HTLC handling failure reason

We add `HTLCHandlingFailedConditions` to express the failure parameters,
that will be enforced by a new macro, `expect_pending_htlcs_forwardable_conditions`.

21 months agoAdd HTLCHandlingFailed event
jurvis [Tue, 19 Jul 2022 01:29:40 +0000 (20:29 -0500)]
Add HTLCHandlingFailed event

Adds a HTLCHandlingFailed that expresses failure by our node to process
a specific HTLC. A HTLCDestination enum is defined to express the
possible cases that causes the handling to fail.

21 months agoMerge pull request #1627 from dunxen/2022-07-reusevalidatepowblockhash
Matt Corallo [Fri, 22 Jul 2022 15:36:25 +0000 (15:36 +0000)]
Merge pull request #1627 from dunxen/2022-07-reusevalidatepowblockhash

Reuse `BlockHash` from `validate_pow()`

21 months agoReuse `BlockHash` from `validate_pow()`
Duncan Dean [Fri, 22 Jul 2022 09:34:25 +0000 (11:34 +0200)]
Reuse `BlockHash` from `validate_pow()`

The `validate_pow()` method now returns the BlockHash since rust-bitcoin
v0.26.2 thanks to jkczyz's PR (rust-bitcoin/rust-bitcoin/pull/572).

21 months agoMerge pull request #1420 from TheBlueMatt/2022-04-moar-lockorder
Matt Corallo [Thu, 21 Jul 2022 02:29:16 +0000 (02:29 +0000)]
Merge pull request #1420 from TheBlueMatt/2022-04-moar-lockorder

Expand lockorder testing to look at mutexes, not specific instances

21 months agoSwap `HashSet`s with custom `Hash` in debug_sync for `HashMap`s 2022-04-moar-lockorder
Matt Corallo [Tue, 19 Jul 2022 17:51:45 +0000 (17:51 +0000)]
Swap `HashSet`s with custom `Hash` in debug_sync for `HashMap`s

21 months agoExpand lockorder testing to look at mutexes, not specific instances
Matt Corallo [Tue, 12 Apr 2022 17:32:35 +0000 (17:32 +0000)]
Expand lockorder testing to look at mutexes, not specific instances

Our existing lockorder inversion checks look at specific instances
of mutexes rather than the general mutex itself. This changes that
behavior to look at the instruction pointer at which a mutex was
created and treat all mutexes which were created at the same
location as equivalent.

This allows us to detect lockorder inversions which occur across
tests, though it does substantially reduce parallelism during test
runs.

21 months agoConstruct all ChannelMonitor mutexes in the same function
Matt Corallo [Fri, 15 Jul 2022 16:18:42 +0000 (16:18 +0000)]
Construct all ChannelMonitor mutexes in the same function

When we add lockorder detection based on mutex construction site
rather than mutex instance in the next commit, ChannelMonitor's
PartialEq implementation causes spurious failures. This is caused
by the lockorder detection logic considering the ChannelMonitor
inner mutex to be two distinct mutexes - one when monitors are
deserialized and one when monitors are created fresh. Instead, we
attempt to tell the lockorder detection logic that they are the
same by ensuring they're constructed in the same place - in this
case a util method.

21 months agoMerge pull request #1624 from tnull/2022-07-fix-doc
Matt Corallo [Wed, 20 Jul 2022 17:38:42 +0000 (17:38 +0000)]
Merge pull request #1624 from tnull/2022-07-fix-doc

Fix 'not a hyperlink' doc warning

21 months agoMerge pull request #1623 from lexe-tech/custom-smart-pointers
valentinewallace [Wed, 20 Jul 2022 17:07:20 +0000 (13:07 -0400)]
Merge pull request #1623 from lexe-tech/custom-smart-pointers

lightning-net-tokio: Allow custom smart pointers

21 months agoFix 'not a hyperlink' doc warning
Elias Rohrer [Wed, 20 Jul 2022 12:57:31 +0000 (14:57 +0200)]
Fix 'not a hyperlink' doc warning

21 months agolightning-net-tokio: Allow custom smart pointers
Max Fang [Wed, 20 Jul 2022 04:57:12 +0000 (21:57 -0700)]
lightning-net-tokio: Allow custom smart pointers

21 months agoMerge pull request #1610 from TheBlueMatt/2022-07-no-rand-path-selection
Matt Corallo [Tue, 19 Jul 2022 16:56:36 +0000 (16:56 +0000)]
Merge pull request #1610 from TheBlueMatt/2022-07-no-rand-path-selection

21 months agoReduce default max_channel_saturation_power_of_half to 2 (max 1/4) 2022-07-no-rand-path-selection
Matt Corallo [Tue, 12 Jul 2022 21:13:30 +0000 (21:13 +0000)]
Reduce default max_channel_saturation_power_of_half to 2 (max 1/4)

Saturating a channel beyond 1/4 of its capacity seems like a more
reasonable threshold for avoiding a path than 1/2, especially given
we should still be willing to send a payment with a lower
saturation limit if it comes to that.

This requires an (obvious) change to some router tests, but also
requires a change to the `fake_network_test`, opting to simply
remove some over-limit test code there - `fake_network_test` was
our first ever functional test, and while it worked great to ensure
LDK worked at all on day one, we now have a rather large breadth
of functional tests, and a broad "does it work at all" test is no
longer all that useful.

21 months agoMake route path selection optimize strictly for `cost / amount`
Matt Corallo [Tue, 12 Jul 2022 20:35:36 +0000 (20:35 +0000)]
Make route path selection optimize strictly for `cost / amount`

Currently, after we've selected a number of candidate paths, we
construct a route from a random set of paths repeatedly, and then
select the route with the lowest total cost. In the vast majority
of cases this ends up doing a bunch of additional work in order to
select the path(s) with the total lowest cost, with some vague
attempt at randomization that doesn't actually work.

Instead, here, we simply sort available paths by `cost / amount`
and select the top paths. This ends up in practice having the same
end result with substantially less complexity. In some rare cases
it gets a better result, which also would have been achieved
through more random trials. This implies there may in such cases be
a potential privacy loss, but not a substantial one, given our path
selection is ultimately mostly deterministic in many cases (or, if
it is not, then privacy is achieved through randomization at the
scorer level).

21 months agoFix tracking of collected value across pathfinding iterations
Matt Corallo [Tue, 12 Jul 2022 20:30:00 +0000 (20:30 +0000)]
Fix tracking of collected value across pathfinding iterations

If we end up "paying" for an `htlc_minimum_msat` with fees, we
increment `already_collected_value_msat` by more than the amount
of the path that we collected (who's `value_contribution_msat` is
higher than the total payment amount, despite having been reduced
down to the payment amount).

This throws off our total value collection target, though in the
coming commit(s) it would also throw off our path selection
calculations.

21 months agoMerge pull request #1618 from wpaulino/gossip-sync-constructors
Matt Corallo [Fri, 15 Jul 2022 19:12:41 +0000 (19:12 +0000)]
Merge pull request #1618 from wpaulino/gossip-sync-constructors

Add convenient GossipSync variant constructors

21 months agoAdd convenient GossipSync variant constructors
Wilmer Paulino [Thu, 14 Jul 2022 19:32:30 +0000 (12:32 -0700)]
Add convenient GossipSync variant constructors

These constructors fill in the missing types for each variant so that
users don't have to turbofish them manually.

21 months agoMerge pull request #1600 from TheBlueMatt/2022-07-explicit-avoid-retries
Matt Corallo [Fri, 15 Jul 2022 13:51:05 +0000 (13:51 +0000)]
Merge pull request #1600 from TheBlueMatt/2022-07-explicit-avoid-retries

21 months agoChange default "impossibility penalty" to one Bitcoin 2022-07-explicit-avoid-retries
Matt Corallo [Thu, 7 Jul 2022 17:37:22 +0000 (17:37 +0000)]
Change default "impossibility penalty" to one Bitcoin

In general we should avoid taking paths that we are confident will
not work as much possible, but we should be willing to try each
payment at least once, even if its over a channel that failed
recently. A full Bitcoin penalty for such a channel seems
reasonable - lightning fees are unlikely to ever reach that point
so such channels will be scored much worse than any other potential
path, while still being below `u64::max_value()`.

21 months agoMake the `ProbabilisticScorer` impossibility penalty configurable
Matt Corallo [Wed, 6 Jul 2022 21:05:54 +0000 (21:05 +0000)]
Make the `ProbabilisticScorer` impossibility penalty configurable

When we consider sending an HTLC over a given channel impossible
due to our current knowledge of the channel's liquidity, we
currently always assign a penalty of `u64::max_value()`. However,
because we now refuse to retry a payment along the same path in
the router itself, we can now make this value configurable. This
allows users to have a relatively high knowledge decay interval
without the side-effect of refusing to try the only available path
in cases where a channel is intermittently available.

21 months agoTrack channels which a given payment part failed to traverse
Matt Corallo [Wed, 6 Jul 2022 19:17:40 +0000 (19:17 +0000)]
Track channels which a given payment part failed to traverse

When an HTLC fails, we currently rely on the scorer learning the
failed channel and assigning an infinite (`u64::max_value()`)
penalty to the channel so as to avoid retrying over the exact same
path (if there's only one available path). This is common when
trying to pay a mobile client behind an LSP if the mobile client is
currently offline.

This leads to the scorer being overly conservative in some cases -
returning `u64::max_value()` when a given path hasn't been tried
for a given payment may not be the best decision, even if that
channel failed 50 minutes ago.

By tracking channels which failed on a payment part level and
explicitly refusing to route over them we can relax the
requirements on the scorer, allowing it to make different decisions
on how to treat channels that failed relatively recently without
causing payments to retry the same path forever.

This does have the drawback that it could allow two separate part
of a payment to traverse the same path even though that path just
failed, however this should only occur if the payment is going to
fail anyway, at least as long as the scorer is properly learning.

Closes #1241, superseding #1252.

21 months agoMerge pull request #1605 from TheBlueMatt/2022-07-smaller-mpp-parts
Matt Corallo [Thu, 14 Jul 2022 18:33:53 +0000 (18:33 +0000)]
Merge pull request #1605 from TheBlueMatt/2022-07-smaller-mpp-parts

Avoid saturating channels before we split payments

21 months agoMerge pull request #1543 from jkczyz/2022-06-network-graph-bindings
Jeffrey Czyz [Thu, 14 Jul 2022 16:57:08 +0000 (11:57 -0500)]
Merge pull request #1543 from jkczyz/2022-06-network-graph-bindings

Look-up functions for `ReadOnlyNetworkGraph`

21 months agoLook-up functions for ReadOnlyNetworkGraph
Jeffrey Czyz [Tue, 14 Jun 2022 23:05:25 +0000 (18:05 -0500)]
Look-up functions for ReadOnlyNetworkGraph

ReadOnlyNetworkGraph uses BTreeMap to store its nodes and channels, but
these data structures are not supported by C bindings. Expose look-up
functions on these maps in lieu of such support.

21 months agoMerge pull request #1615 from TheBlueMatt/2022-07-screw-dependabot
Matt Corallo [Thu, 14 Jul 2022 00:53:17 +0000 (00:53 +0000)]
Merge pull request #1615 from TheBlueMatt/2022-07-screw-dependabot

Rip out dependabot - its worse than useless - its annoying

21 months agoRip out dependabot - its worse than useless - its annoying 2022-07-screw-dependabot
Matt Corallo [Wed, 13 Jul 2022 19:33:25 +0000 (19:33 +0000)]
Rip out dependabot - its worse than useless - its annoying

Dependabot has a ton of issues with its rust integration that makes
it wholly useless, and very annoying:
 * It has no concept of MSRV, opening PRs that are not going to pass
   CI.
 * It has no concept of patch-level - if we depend on tokio 1.X,
   that means any version of tokio > 1.X, but dependabot insists on
   opening a PR to "update us" to tokio 1.X + 1, even though it
   doesn't impact what version of our users use (and often violates
   MSRV).
 * It has no concept of dependencies that rely on each other,
   causing it to open a PR to update us to bitcoin_hashes X + 1,
   even though we're still depending on rust-bitcoin Y which
   depends on bitcoin_hashes X, causing build failure.
 * It hogs CI resources, getting CI run twice, once for the branch
   once for the PR.
 * It creates branches directly on the rust-lightning repo, making
   it look like the work is somehow connected to the
   lightningdevkit project, even though it isn't, and spamming the
   local clones of project contributors.

At the end of the day, dependabot has never meaningfully
contributed to notifying us of an important dependency, and,
really, we don't have enough dependencies for it to matter.

21 months agoFix some test theoretical lock inversions
Matt Corallo [Tue, 12 Apr 2022 17:28:15 +0000 (17:28 +0000)]
Fix some test theoretical lock inversions

In the next commit we add lockorder testing based on the line each
mutex was created on rather than the particular mutex instance.
This causes some additional test failure because of lockorder
inversions for the same mutex across different tests, which is
fixed here.

21 months agoAdd a test of the new channel saturation limit 2022-07-smaller-mpp-parts
Matt Corallo [Sat, 9 Jul 2022 04:24:22 +0000 (04:24 +0000)]
Add a test of the new channel saturation limit

21 months agoRelax the channel saturation limit if we can't find enough paths
Matt Corallo [Fri, 8 Jul 2022 19:48:00 +0000 (19:48 +0000)]
Relax the channel saturation limit if we can't find enough paths

In order to avoid failing to find paths due to the new channel
saturation limit, if we fail to find enough paths, we simply
disable the saturation limit for further path finding iterations.

Because we can now increase the maximum sent over a given channel
during routefinding, we may now generate redundant paths for the
same payment. Because this is wasteful in the network, we add an
additional pass during routefinding to merge redundant paths.

Note that two tests which previously attempted to send exactly the
available liquidity over a channel which charged an absolute fee
need updating - in those cases the router will first collect a path
that is saturation-limited, then attempt to collect a second path
without a saturation limit while stil honoring the existing
utilized capacity on the channel, causing failure as the absolute
fee must be included.

21 months agoAvoid saturating channels before we split payments
Matt Corallo [Fri, 8 Jul 2022 18:26:06 +0000 (18:26 +0000)]
Avoid saturating channels before we split payments

Currently we only opt to split a payment into an MPP if we have
completely and totally used a channel's available capacity (up to
the announced htlc_max or on-chain capacity, whichever is lower).
This is obviously destined to fail as channels are unlikely to have
their full capacity available.

Here we do the minimum viable fix by simply limiting channels to
only using up to a configurable power-of-1/2. We default this new
configuration knob to 1 (1/2 of the channel) so as to avoid a
substantial change but in the future we may consider changing this
to 2 (1/4) or even 3 (1/8).

21 months agoMerge pull request #1552 from dunxen/2022-06-checkminrelayfee
Matt Corallo [Wed, 13 Jul 2022 16:49:16 +0000 (16:49 +0000)]
Merge pull request #1552 from dunxen/2022-06-checkminrelayfee

Add min feerate checks

21 months agoMake all internal signatures accept LowerBoundedFeeEstimator
Duncan Dean [Wed, 29 Jun 2022 13:13:40 +0000 (15:13 +0200)]
Make all internal signatures accept LowerBoundedFeeEstimator

21 months agoAdd LowerBoundedFeeEstimator to set FeeEstimator min rates
Duncan Dean [Wed, 29 Jun 2022 12:59:07 +0000 (14:59 +0200)]
Add LowerBoundedFeeEstimator to set FeeEstimator min rates

`LowerBoundedFeeEstimator` is a wrapper for `Deref`s to `FeeEstimator`s
that limits the get_est_sat_per_1000_weight() method to no less than 253
sats/kW.

21 months agoMerge pull request #1542 from ViktorTigerstrom/2022-06-prepare-maps-for-channels...
Matt Corallo [Wed, 13 Jul 2022 01:03:11 +0000 (18:03 -0700)]
Merge pull request #1542 from ViktorTigerstrom/2022-06-prepare-maps-for-channels-per-peer

Preparations for storing channels per peer

21 months agoAdd `ChannelManager:id_to_peer` map coverage test
Viktor Tigerström [Mon, 6 Jun 2022 18:20:48 +0000 (20:20 +0200)]
Add `ChannelManager:id_to_peer` map coverage test

21 months agoAdd id_to_peer map
Viktor Tigerström [Fri, 3 Jun 2022 15:17:39 +0000 (17:17 +0200)]
Add id_to_peer map

21 months agoMerge pull request #1603 from TheBlueMatt/2022-07-no-backwards-time
Matt Corallo [Mon, 11 Jul 2022 21:07:18 +0000 (14:07 -0700)]
Merge pull request #1603 from TheBlueMatt/2022-07-no-backwards-time

Avoid panicking on wallclock time going backwards across restart

21 months agoMerge pull request #1596 from jurvis/jurvis/give-chanmon-counterparty-id
Jeffrey Czyz [Mon, 11 Jul 2022 18:51:55 +0000 (13:51 -0500)]
Merge pull request #1596 from jurvis/jurvis/give-chanmon-counterparty-id

Make ChannelMonitor aware of counterparty's node id

21 months agoAvoid panicking on wallclock time going backwards across restart 2022-07-no-backwards-time
Matt Corallo [Fri, 8 Jul 2022 01:16:05 +0000 (01:16 +0000)]
Avoid panicking on wallclock time going backwards across restart

Because we serialize `Instant`s using wallclock time in
`ProbabilisticScorer`, if time goes backwards across restarts we
may end up with `Instant`s in the future, which causes rustc prior
to 1.60 to panic when calculating durations. Here we simply avoid
this by setting the time to `now` if we get a time in the future.

21 months agoAdd counterparty_node_id to ChannelMonitor
jurvis [Tue, 5 Jul 2022 22:36:27 +0000 (15:36 -0700)]
Add counterparty_node_id to ChannelMonitor

21 months agoMerge pull request #1602 from TheBlueMatt/2022-07-109-rel-missing-force-close
Jeffrey Czyz [Fri, 8 Jul 2022 19:34:13 +0000 (14:34 -0500)]
Merge pull request #1602 from TheBlueMatt/2022-07-109-rel-missing-force-close

Add missing note about renaming force-close methods in 109 changelog

21 months agoMerge pull request #1592 from tnull/2022-07-manual-penalty
Matt Corallo [Fri, 8 Jul 2022 19:29:25 +0000 (12:29 -0700)]
Merge pull request #1592 from tnull/2022-07-manual-penalty

Allow to set manual node penalties

21 months agoAdd missing note about renaming force-close methods in 109 changelog 2022-07-109-rel-missing-force-close
Matt Corallo [Thu, 7 Jul 2022 17:43:30 +0000 (17:43 +0000)]
Add missing note about renaming force-close methods in 109 changelog