Commit graph

1324 commits

Author SHA1 Message Date
Matt Corallo
e635db0da3
Merge pull request #1062 from galderz/t_payment_hash_999 2021-10-08 20:49:19 +00:00
Duncan Dean
fce631ca21
Replace PublicKey with [u8; 33] in NetworkGraph 2021-10-08 18:37:55 +02:00
Galder Zamarreño
204bfd260c Add payment_hash to PaymentSent #999 2021-10-08 06:53:10 +02:00
Matt Corallo
6582aaebae
Merge pull request #1109 from TheBlueMatt/2021-10-init-fail-payment-retry-leak
Move pending payment tracking to after the new HTLC flies
2021-10-07 23:14:06 +00:00
Matt Corallo
a58c617c42 Correct error returned when retry_payment doesn't have a payment 2021-10-07 22:27:58 +00:00
Matt Corallo
928bfb12d2 Move pending payment tracking to after the new HTLC flies
If we attempt to send a payment, but the HTLC cannot be send due to
local channel limits, we'll provide the user an error but end up
with an entry in our pending payment map. This will result in a
memory leak as we'll never reclaim the pending payment map entry.
2021-10-07 22:27:58 +00:00
Jeffrey Czyz
f5abc93978
Pass hop index in construct_onion_keys_callback
This simplifies failing route hop calculation, which will be useful for
later identifying the failing hop for PaymentFailed events.
2021-10-06 23:31:59 -05:00
Jeffrey Czyz
42bb0af11d
Remove special case for onion error expiry_too_far
With channel scoring and payment retries, it is no longer necessary to
have expiry_too_far imply a payment failure.
2021-10-06 23:31:27 -05:00
Matt Corallo
ab0739e3ea
Merge pull request #1079 from TheBlueMatt/2021-09-stale-docs
Update Event::PaymentReceived docs since we require payment secret
2021-10-05 23:16:20 +00:00
Matt Corallo
7478207d5c Update Event::PaymentReceived docs since we require payment secret
Users no longer need to verify the amounts of received payments as
the payment secret will protect us against the probing attacks such
verification was intended to fix.
2021-10-05 22:35:04 +00:00
Matt Corallo
bb4ff74da1 Move tests of payment retries into a new module 2021-10-05 19:26:45 +00:00
Matt Corallo
17d75a845a
Merge pull request #1100 from TheBlueMatt/2021-09-multihop-route-hint-fix
Consider many first-hop paths to the same counterparty in routing
2021-10-05 18:43:39 +00:00
Matt Corallo
7aa2caccd8
Merge pull request #1096 from valentinewallace/2021-09-mpp-retries 2021-09-30 01:19:04 +00:00
Valentine Wallace
3e6297a664
Expire outbound payments after 3 blocks if no parts are pending 2021-09-29 20:25:42 -04:00
Valentine Wallace
207479f32f
Don't remove failed payments when all paths fail
This is because we want the ability to retry completely failed
payments.

Upcoming commits will remove these payments on timeout to prevent
DoS issues

Also test that this removal allows retrying single-path payments
2021-09-29 20:25:42 -04:00
Valentine Wallace
8db9c50b8b
Add method to retry payments 2021-09-29 20:25:39 -04:00
Matt Corallo
730d5639a4
Merge pull request #1080 from valentinewallace/2021-09-dup-chan-outpoint
Fix fuzzer-found panic from duplicate channel outpoint
2021-09-30 00:01:35 +00:00
Matt Corallo
cc704465c3 f readability improvements from val 2021-09-29 23:16:22 +00:00
Matt Corallo
2352587811
Merge pull request #1076 from TheBlueMatt/2021-09-forwardable-regen 2021-09-29 20:24:37 +00:00
Matt Corallo
0fcc34b9b5 Regenerate PendingHTLCsForwardable on reload instead of serializing
When we are prepared to forward HTLCs, we generate a
PendingHTLCsForwardable event with a time in the future when the
user should tell us to forward. This provides some basic batching
of forward events, improving privacy slightly.

After we generate the event, we expect users to spawn a timer in
the background and let us know when it finishes. However, if the
user shuts down before the timer fires, the user will restart and
have no idea that HTLCs are waiting to be forwarded/received.

To fix this, instead of serializing PendingHTLCsForwardable events
to disk while they're pending (before the user starts the timer),
we simply regenerate them when a ChannelManager is deserialized
with HTLCs pending.

Fixes #1042
2021-09-29 19:20:38 +00:00
Matt Corallo
56c75f0bac Consider many first-hop paths to the same counterparty in routing
Previously we'd simply overwritten "the" first hop path to each
counterparty when routing, however this results in us ignoring all
channels except the last one in the `ChannelDetails` list per
counterparty.
2021-09-29 19:15:16 +00:00
Matt Corallo
6edb4fe42f Correct step number in get_route 2021-09-29 18:51:14 +00:00
Valentine Wallace
bf527b0ddb
channelmanager: Add retry data to pending_outbound_payments 2021-09-28 19:39:37 -04:00
Valentine Wallace
72e1c91d46
Refactor send_payment internals for retries 2
Retrying a partial payment means send_payment_internal needs to be parameterized
by a total payment amount, else 'HTLC values do not match' errors
2021-09-28 19:39:37 -04:00
Valentine Wallace
5d316302df
Refactor send_payment internals for retries
We want to reuse send_payment internal functions for retries,
so some need to now be parameterized by PaymentId to avoid
generating a new PaymentId on retry
2021-09-28 19:39:37 -04:00
Valentine Wallace
a1fc379151
Return PaymentId from send_*payment functions
Used in upcoming commits for retries
2021-09-28 19:39:37 -04:00
Valentine Wallace
28eea12bbe
Rename MppId to PaymentId
Leftover from previous PR Jeff feedback.

Useful in upcoming commits as we'll expose this to users for payment retries
2021-09-28 19:39:34 -04:00
Matt Corallo
ad819ea705
Merge pull request #1065 from TheBlueMatt/2021-08-bump-dust
Increase our default/minimum dust limit and decrease our max
2021-09-27 20:39:02 +00:00
Matt Corallo
2da0d6c0c9 Rename MIN_DUST_LIMIT_SATOSHIS constant to disambiguate chan vs P2P
While channel and P2P network dust limits are related, they're
ultimately two different things, and thus their constant names
should reference that.
2021-09-27 18:19:51 +00:00
Matt Corallo
9279890089 Force-close channels if closing transactions may be non-standard
If a counterparty (or an old channel of ours) uses a non-segwit
script for their cooperative close payout, they may include an
output which is unbroadcastable due to not meeting the network dust
limit.

Here we check for this condition, force-closing the channel instead
if we find an output in the closing transaction which does not meet
the limit.
2021-09-27 18:19:51 +00:00
Matt Corallo
1b70d9ee8f Require user cooperative close payout scripts to be Segwit
There is little reason for users to be paying out to non-Segwit
scripts when closing channels at this point. Given we will soon, in
rare cases, force-close during shutdown when a counterparty closes
to a non-Segwit script, we should also require it of our own users.
2021-09-27 18:19:51 +00:00
Matt Corallo
c43db96062 Reduce the maximum allowed counterparty dust limit to 546 sat/vbyte
546 sat/vbyte is the current default dust limit on most
implementations, matching the network dust limit for P2SH outputs.
Implementations don't currently appear to send any larger dust
limits, and allowing a larger dust limit implies higher payment
failure risk, so we'd like to be as tight as we can here.
2021-09-27 18:19:51 +00:00
Matt Corallo
6c569d82b0 Make NetworkGraph Clone-able again
There isn't a lot of user-utility for cloning `NetworkGraph`
directly (its a rather large struct, and there probably isn't a lot
of reason to have *multiple* `NetworkGraph`s). Thus, when locks
were pushed down into it, the `Clone`-ability of it was dropped as
well.

Sadly, mapping the Java memory model onto:
 * `Read`-ing a `NetworkGraph`, creating a Java-owned
   `NetworkGraph` object that the JVM will destruct for us,
 * Passing it to a `NetGraphMsgHandler`, which now expects to own
   the `NetworkGraph`, including destructing it,
isn't really practical without adding a clone in between.

Given this, and the fact that there's nothing inherently wrong with
clone-ing a `NetworkGraph`, we simply re-add `Clone` here.
2021-09-26 04:31:29 +00:00
Matt Corallo
43fe3d55f1 Bump Crate versions to 0.0.101 (and invoice to 0.9) 2021-09-23 18:22:59 +00:00
Matt Corallo
ab49e4101f Make method time on trait impl explitit to help bindings generator
Associated types in C bindings is somewhat of a misnomer - we
concretize each trait to a single struct. Thus, different trait
implementations must still have the same type, which defeats the
point of associated types.

In this particular case, however, we can reasonably special-case
the `Infallible` type, as an instance of it existing implies
something has gone horribly wrong.

In order to help our bindings code figure out how to do so when
referencing a parent trait's associated type, we specify the
explicit type in the implementation method signature.
2021-09-23 04:02:58 +00:00
Matt Corallo
401d03599d Drop redundant generic bounds when the trait requires the bounds 2021-09-22 23:46:40 +00:00
Matt Corallo
e82318d374 Use Infallible for the unconstructable default custom message type
When we landed custom messages, we used the empty tuple for the
custom message type for `IgnoringMessageHandler`. This was fine,
except that we also implemented `Writeable` to panic when writing
a `()`. Later, we added support for anchor output construction in
CommitmentTransaction, signified by setting a field to `Some(())`,
which is serialized as-is.

This causes us to panic when writing a `CommitmentTransaction`
with `opt_anchors` set. Note that we never set it inside of LDK,
but downstream users may.

Instead, we implement `Writeable` to write nothing for `()` and use
`core::convert::Infallible` for the default custom message type as
it is, appropriately, unconstructable.

This also makes it easier to implement various things in bindings,
as we can always assume `Infallible`-conversion logic is
unreachable.
2021-09-22 22:01:40 +00:00
Matt Corallo
d718822874 Make ChainMonitor::get_claimable_balances take a slice of refs
For the same reason as `get_route`, a slice of objects isn't
practical to map to bindings - the objects in the bindings space
are structs with a pointer and some additional metadata. Thus, to
create a slice of them, we'd need to take ownership of the objects
behind the pointer, place them into a slace, and then restore them
to the pointer.

This would be a lot of memory copying and marshalling, not to
mention wouldn't be thread-safe, which the same function otherwise
would be if we used a slice of references instead of a slice of
objects.
2021-09-22 04:42:31 +00:00
Matt Corallo
4c813186dc Move trait bounds on wire::Type from use to the trait itself
`wire::Type` is only (publicly) used as the `CustomMessage`
associated type in `CustomMessageReader`, where it has additional
trait bounds on `Debug` and `Writeable`. The documentation for
`Type` even mentions that you need to implement `Writeable` because
this is the one place it is used.

To make this more clear, we move the type bounds onto the trait
itself and not on the associated type.

This is also the only practical way to build C bindings for `Type`
as we cannot have a concrete, single, `Type` struct in C which only
optionally implements various subtraits, at least not without
runtime checking of the type bounds.
2021-09-22 01:07:30 +00:00
Matt Corallo
0273ac52db
Merge pull request #1084 from valentinewallace/2021-09-rename-paymentfailed
Rename Event PaymentFailed -> PaymentPathFailed
2021-09-21 22:14:42 +00:00
Matt Corallo
5af0cb2887
Merge pull request #1088 from TheBlueMatt/2021-09-1063-fixups
Fix a panic in Route's new fee-calculation methods and clean up
2021-09-21 21:59:11 +00:00
Valentine Wallace
e5310dd5f0
Add path field to PaymentPathFailed event 2021-09-21 17:40:09 -04:00
Valentine Wallace
bf16dfd153
Rename PaymentFailed -> PaymentPathFailed
Since we don't want to imply to users that a payment has
completely failed when it really has just partially
failed
2021-09-21 17:39:40 -04:00
Matt Corallo
71e0173d8d Fix future unknown Event variant backwards compatibility
In 8ffc2d1742, in 0.0.100, we added
a backwards compatibility feature to the reading of `Event`s - if
the type was unknown and odd, we'd simply ignore the event and
treat it as no event. However, we failed to read the
length-prefixed TLV stream when doing so, resulting in us reading
some of the skipped-event data as the next event or other data in
the ChannelManager.

We fix this by reading the varint length prefix written, then
skipping that many bytes when we come across an unknown odd event
type.
2021-09-21 20:37:35 +00:00
Matt Corallo
2cf42aa388
Merge pull request #997 from ariard/2021-07-add-chan-closed
Add Event::ChannelClosed generation
2021-09-21 20:35:29 +00:00
Antoine Riard
d13c5cfa30 Add pending_events deadlock detection in handle_error 2021-09-21 15:46:42 -04:00
Antoine Riard
6ce7f3e1ce Add ChannelClosed generation at cooperative/force-close/error processing
When we detect a channel `is_shutdown()` or call on it
`force_shutdown()`, we notify the user with a Event::ChannelClosed
informing about the id and closure reason.
2021-09-21 15:46:42 -04:00
Antoine Riard
c29092c235 Extend MsgHandleErrInternal with a new chan_id field Option<[u8; 32]>
This field is used in next commit to generate appropriate
ChannelClosed event at `handle_error()` processing.
2021-09-21 15:46:42 -04:00
Antoine Riard
ea03b946bd Rename MonitorEvent::CommitmentTxBroadcasted to CommitmentTxConfirmed 2021-09-21 15:46:42 -04:00
Antoine Riard
e64467f512 Add Event::ChannelClosed generation at channel shutdown 2021-09-21 15:46:40 -04:00