Commit graph

1715 commits

Author SHA1 Message Date
Matt Corallo
d629a7edb7 Expand chain::Listen trivially to accept filtered block data
The `chain::Listen` interface provides a block-connection-based
alternative to the `chain::Confirm` interface, which supports
providing transaction data at a time separate from the block
connection time.

For users who are downloading the full headers tree (e.g. from a
node over the Bitcoin P2P protocol) but who are not downloading
full blocks (e.g. because they're using BIP 157/158 filtering)
there is no API that matches exactly their event stream -
`chain::Listen` requries full blocks for each block,
`chain::Confirm` requires breaking each connection event into two
calls.

Given its incredibly trivial to take a `TransactionData` in
addition to a `Block` in `chain::Listen` we do so here, adding a
default-implementation `block_connected` which simply creates the
`TransactionData`, which ultimately all of the `chain::Listen`
implementations currently do anyway.

Closes #1128.
2022-04-26 19:14:19 +00:00
Matt Corallo
637fb88037
Merge pull request #1378 from ViktorTigerstrom/2022-03-include-htlc-min-max
Include htlc min/max for ChannelDetails and ChannelCounterparty
2022-04-21 18:09:20 +00:00
Viktor Tigerström
63f0a31b59 Add outbound min/max to ChannelCounterparty 2022-04-21 12:27:51 +02:00
Matt Corallo
d0f69f77bd
Merge pull request #1417 from johncantrell97/generic-persist
add `KVStorePersister` trait and blanket implementations of `Persist` and `Persister` for any type that implements `KVStorePersister`
2022-04-21 01:28:23 +00:00
John Cantrell
4964944279
implement Persist and Persister with generic KVStorePersister trait 2022-04-20 16:46:58 -04:00
valentinewallace
742f5e59b9
Merge pull request #1419 from atalw/2022-03-paymentforwarded-event
Expose more info in `PaymentForwarded` event
2022-04-20 11:37:48 -04:00
atalw
e53c5bdb44 Add source_channel_id in PaymentForwarded event 2022-04-20 10:58:21 +05:30
Viktor Tigerström
6644ef138d Add inbound htlc min/max to ChannelDetails 2022-04-19 23:54:55 +02:00
Jeffrey Czyz
e0b9b748d6
Merge pull request #1414 from ViktorTigerstrom/2022-04-default-to-tlv-onions
Default to BOLT 4 tlv payload format onions
2022-04-18 13:09:55 -07:00
Viktor Tigerström
c72ae67768 Add tests for defaulting to creating tlv onions 2022-04-16 01:35:32 +02:00
Viktor Tigerström
b28bcfe3d9 Pass PaymentParameters in get_route_and_payment_hash 2022-04-14 23:04:51 +02:00
Viktor Tigerström
a316ef4596 Default to creating BOLT4 tlv payload format onions
Default to creating tlv onions for nodes for which we haven't received
any features through node announcements or which aren't in the
`network_graph`, and where no other features are known such as invoice
features nor features in the init msg for nodes we have channels to.
2022-04-14 23:04:51 +02:00
Matt Corallo
03f655003d
Merge pull request #1384 from valentinewallace/2022-03-chanmanless-phantom-invoices 2022-04-13 14:51:35 +00:00
Valentine Wallace
204dd42a7d
Expose methods for ChannelManager-less phantom invoice generation 2022-04-11 18:43:48 -04:00
Matt Corallo
30e1922797 Lower-bound the log approximation and stop using it > ~98.5%
When we start getting a numerator and divisor particularly close to
each other, the log approximation starts to get very noisy. In
order to avoid applying scores that are basically noise (and can
range upwards of 2x the default per-hop penalty), simply consider
such cases as having a success probability of 100%.
2022-04-11 20:55:55 +00:00
Matt Corallo
4930af9b54 Expand the precision of our log10 lookup tables + add precision
When we send values over channels of rather substantial size, the
imprecision of our log lookup tables creates a rather substantial
non-linearity between values that round up or down one bit.

For example, with the default scoring values, sending 100k sats
over channels with 1m, 2m, 3m, and 4m sats of capacity score
rather drastically differently: 3645, 2512, 500, and 1442 msat.

Here we expand the precision of our log lookup tables rather
substantially by: (a) making the multiplier 2048 instead of 1024,
which still fits inside a u16, and (b) quadrupling the size of the
lookup table to look at the top 6 bits after the most-significant
bit of an input instead of the top 4.

This makes the scores of the same channels substantially more
linear, with values of 3613, 1977, 1474, and 1223 msat.

The same channels would be scored at 3611, 1972, 1464, and 1216
msat with a non-approximating scorer.
2022-04-10 21:29:33 +00:00
Matt Corallo
02bebee62e Add a test which demonstrates scores for some realistic payments 2022-04-03 21:18:15 +00:00
Matt Corallo
0a0f87c00f
Merge pull request #1397 from jkczyz/2022-03-release-0.0.106
Cut 0.0.106
2022-04-03 16:31:54 +00:00
Jeffrey Czyz
de8bb8d261
Bump crate versions to 0.0.106/invoice 0.14 2022-04-03 08:05:08 -05:00
Matt Corallo
af318312c5
Merge pull request #1399 from jkczyz/2022-03-scoring-tweaks
ProbabilisticScorer improvements
2022-04-02 01:50:55 +00:00
Jeffrey Czyz
5425b2b77e
Add an amount penalty to ProbabilisticScorer
The cost of large payments tends to be dominated by the channel fees. To
avoid this, add an amount penalty to ProbabilisticScorer with a user
configurable multiplier. The multiplier is applied for every 2^20th of
the amount weighted by the negative log10 of the channel's success
probability for the payment.
2022-04-01 15:52:10 -05:00
Jeffrey Czyz
5337f89d8b
Avoid retrying over recently failed channels
In ProbabilisticScorer, the channel liquidity balance is reduced
whenever a payment fails at the corresponding channel. The payment may
still be retried through the channel, however, because the liquidity
penalty is capped. Use u64::max_value instead in this situation to avoid
retrying over the same path. This effectively makes u64::max_value the
penalty for amounts exceeding the upper bound, as well.

As an edge case, avoid using u64::max_value on attempts where the amount
is equal to the effective capacity, which may be the HTLC maximum when
the channel capacity is unknown.
2022-04-01 15:52:10 -05:00
Matt Corallo
8ddfe66046
Don't consider a path as having hit HTLC-min if it isn't sufficient
During the first pass of path finding, we seek a single path with the
exact payment amount, and only seek additional paths if (a) no single
path can carry the entire balance of the payment or (b) we found a good
path, but along the way we found candidate paths with the potential to
result in a lower total fee. This commit fixes the behavior of (b) -- we
were previously considering some paths to be candidates for a lower fee
when in fact they never would have worked. This caused us to re-run
Dijkstra's when it might not have been beneficial.
2022-03-31 21:36:22 -05:00
Jeffrey Czyz
f9cdf93da0
Select best route by lowest total cost
Selecting only by fees rather than cost (fees plus penalty) may result
in preferring higher cost routes over lower cost ones.
2022-03-31 21:36:18 -05:00
Jeffrey Czyz
30b6873d03
Correctly pick middle hop to victimize
For even-length paths, preferring a later hop avoids overly limiting the
possible paths on the next iteration.
2022-03-30 17:42:00 -05:00
Jeffrey Czyz
37a947bc36
Fix build warnings without grind_signatures 2022-03-30 17:41:42 -05:00
Matt Corallo
7671ae5452
Merge pull request #1351 from TheBlueMatt/2022-03-scid-privacy
Implement the SCIDAlias Channel Type and provide SCID Privacy
2022-03-28 20:33:55 +00:00
Valentine Wallace
847f26013f
Move inbound_payment module into its own file
As part of preparing to expose some of its methods as pub for ChannelManager-less
phantom invoice generation.

Pure code move of the module + the addition of module-level documentation
2022-03-28 16:04:37 -04:00
Matt Corallo
952cee4a16 Add notes about SCID alias rotation to ChannelDetails docs 2022-03-28 14:24:16 +00:00
Matt Corallo
c47acd76e8 Drop the Writeable::encode_with_len method in non-test buidls
There's not a lot of reason to keep it given its used in one place
outside of tests, and this lets us clean up some of the byte_utils
calls that are still lying around.
2022-03-27 17:12:17 +00:00
Matt Corallo
d2256301e8 Use the correct SCID when failing HTLCs to aliased channels
When we fail an HTLC which was destined for a channel that the HTLC
sender didn't know the real SCID for, we should ensure we continue
to use the alias in the channel_update we provide them. Otherwise
we will leak the channel's real SCID to HTLC senders.
2022-03-27 17:12:17 +00:00
Matt Corallo
99b7219cfc Make all callsites to get_channel_update_for_unicast fallible
This reduces unwraps in channelmanager by a good bit, providing
robustness for the upcoming 0conf changes which allow SCIDs to be
missing after a channel is in use, making
`get_channel_update_for_unicast` more fallible.

This also serves as a useful refactor for the next commit,
consolidating the channel_update creation sites which are changed
in the next commit.
2022-03-27 17:12:17 +00:00
Matt Corallo
dc4e62da5d Add simple tests for our SCIDAlias implementation and negotiation 2022-03-27 17:12:17 +00:00
Matt Corallo
2eb6e1f741 Negotiate scid_alias for private channels based on a new config
Because negotiating `scid_alias` for all of our channels will cause
us to create channels which LDK versions prior to 0.0.106 do not
understand, we disable `scid_alias` negotiation by default.
2022-03-27 17:12:17 +00:00
Matt Corallo
5d652bfec8 Add support for the SCIDAlias feature bit in incoming channels
This does not, however, ever send the scid_alias feature bit for
outgoing channels, as that would cause the immediately prior
version of LDK to be unable to read channel data.
2022-03-27 17:12:17 +00:00
Matt Corallo
b42ebd892b Expose chan type in Event::OpenChannelRequest & ChannelDetails
As we add new supported channel types, inbound channels which use
new features may cause backwards-compatibility issues for clients.
If a new channel is opened using new features while a client still
wishes to ensure support for downgrading to a previous version of
LDK, that new channel may cause the `ChannelManager` to fail
deserialization due to unsupported feature flags.

By exposing the channel type flags to the user in channel requests,
users wishing to support downgrading to previous versions of LDK
can reject channels which use channel features which previous
versions of LDK do not understand.
2022-03-27 17:12:17 +00:00
Arik Sosman
6176e2f13f
Merge pull request #1388 from lightning-signer/2022-03-grind 2022-03-25 16:35:21 -07:00
valentinewallace
eb68b5fe9d
Merge pull request #1375 from jkczyz/2022-03-scorer-followup
ProbabilisticScorer optimizations
2022-03-25 17:01:46 -04:00
Matt Corallo
77cab14a7a
Merge pull request #1382 from TheBlueMatt/2022-03-gossip-queries-sucks
Fix gossip using `gossip_timestamp_filter` instead of queries
2022-03-25 19:49:37 +00:00
Devrandom
8d7b38fcf1 Add low_r signature grinding
default on, can be turned off via a feature gate
2022-03-25 20:34:02 +01:00
valentinewallace
eb50201ed5
Merge pull request #1381 from shamardy/2022-03-set-inbound-user-chan-id
Add `user_channel_id` to `accept_inbound_channel` method
2022-03-25 14:28:57 -04:00
Matt Corallo
1386a0c96b Fix gossip using gossip_timestamp_filter instead of queries
See large comment added for more details
2022-03-25 17:12:09 +00:00
Jeffrey Czyz
9596cc7110
Increase default liquidity_penalty_multiplier_msat
Using a larger multiplier gives more reasonable penalties for larger
success probabilities.
2022-03-25 11:31:04 -05:00
Jeffrey Czyz
c6348cb552
Move max penalty cap in ProbabilisticScorer
This reduce a branch in the 0 and u6::max_value cases.
2022-03-25 09:35:35 -05:00
Jeffrey Czyz
4ea18e3232
Fix overflow in ProbabilisticScorer
When a routing hint is given in an invoice, the effective capacity of
the channel is assumed to be infinite (i.e., u64::max_value) if the hop
is private. Adding 1 to this in the success probability calculation will
cause an overflow and ultimately an `index out of bounds panic` in
log10_times_1024. This was not an issue with using log10 because the use
of f64 would give infinite which casts to 0 for u64.
2022-03-25 09:16:22 -05:00
Jeffrey Czyz
5b36449c59
Add a base penalty to ProbabilisticScorer
ProbabilisticScorer tends to prefer longer routes to shorter ones. Make
the default scoring behavior include a customizable base penalty to
avoid longer routes.
2022-03-25 09:12:49 -05:00
Jeffrey Czyz
188f919a15
Don't serialize FixedPenaltyScorer parameters
Serializing scorer parameters makes it difficult to experiment with
different settings.
2022-03-25 08:53:19 -05:00
Omar Shamardy
edd4babb1c set user_channel_id in accept_inbound_channel fn
fix docs

edit user_channel_id docs for Event::ChannelClosed

review fixes
2022-03-25 05:39:58 +02:00
Matt Corallo
216225c00b
Merge pull request #1359 from tnull/2022-03-real-random-shuffle
Randomize candidate paths during route selection.
2022-03-24 23:13:12 +00:00
Matt Corallo
4e89e5741b
Merge pull request #1380 from TheBlueMatt/2022-03-skip-redundant-sig-checks
Skip `channel_update` signature checks if we have a newer state
2022-03-24 22:51:17 +00:00