Commit graph

1352 commits

Author SHA1 Message Date
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
Matt Corallo
59925c1fa0 Fix a panic in Route's new fee-calculation methods and clean up
This addresses Val's feedback on the new Route fee- and
amount-calculation methods, including fixing the panic she
identified and cleaning up various docs and comments.
2021-09-21 19:11:16 +00:00
Matt Corallo
4419191840
Merge pull request #1082 from vss96/process_events_docs
Update docs to specify where PeerManager::process_events is called
2021-09-21 18:54:19 +00:00
Matt Corallo
8f78bbda89
Merge pull request #1063 from galderz/t_total_fee_999
Add method to count total fees in a Route #999
2021-09-21 18:09:12 +00:00
vss96
2f0f0c9bf3 Update docs to specify where process events is called 2021-09-21 17:13:22 +00:00
Galder Zamarreño
03bb808e58 Add methods to count total fees and total amount in a Route #999
* Added `get_total_fees` method to route,
to calculate all the fees paid accross each path.
* Added `get_total_amount` method to route,
to calculate the total of actual amounts paid in each path.
2021-09-21 07:44:20 +02:00
Matt Corallo
801d6e5256
Merge pull request #1068 from TheBlueMatt/2021-09-ser-cleanup
Simplify Message Serialization and Parse TLV Suffix
2021-09-18 01:42:29 +00:00
Matt Corallo
997dc5f5f3 Convert most P2P msg serialization to a new macro with TLV suffixes
The network serialization format for all messages was changed some
time ago to include a TLV suffix for all messages, however we never
bothered to implement it as there isn't a lot of use validating a
TLV stream with nothing to do with it. However, messages are
increasingly utilizing the TLV suffix feature, and there are some
compatibility concerns with messages written as a part of other
structs having their format changed (see previous commit).

Thus, here we go ahead and convert most message serialization to a
new macro which includes a TLV suffix after a series of fields,
simplifying several serialization implementations in the process.
2021-09-18 01:01:41 +00:00
Matt Corallo
f60da31e56 Add forward-compat due serialization variants of HTLCFailureMsg
Going forward, all lightning messages have a TLV stream suffix,
allowing new fields to be added as needed. In the P2P protocol,
messages have an explicit length, so there is no implied length in
the TLV stream itself. HTLCFailureMsg enum variants have messages
in them, but without a size prefix or any explicit end. Thus, if a
HTLCFailureMsg is read as a part of a ChannelManager, with a TLV
stream at the end, there is no way to differentiate between the end
of the message and the next field(s) in the ChannelManager.

Here we add two new variant values for HTLCFailureMsg variants in
the read path, allowing us to switch to the new values if/when we
add new TLV fields in UpdateFailHTLC or UpdateFailMalformedHTLC so
that older versions can still read the new TLV fields.
2021-09-18 01:01:41 +00:00
Matt Corallo
07b674ecb1 Drop writer size hinting/message vec preallocation
In order to avoid significant malloc traffic, messages previously
explicitly stated their serialized length allowing for Vec
preallocation during the message serialization pipeline. This added
some amount of complexity in the serialization code, but did avoid
some realloc() calls.

Instead, here, we drop all the complexity in favor of a fixed 2KiB
buffer for all message serialization. This should not only be
simpler with a similar reduction in realloc() traffic, but also
may reduce heap fragmentation by allocating identically-sized
buffers more often.
2021-09-18 01:01:41 +00:00
Matt Corallo
831f124721
Merge pull request #1053 from valentinewallace/2021-08-dedup-payment-sent
Deduplicate PaymentSent events for MPP payments
2021-09-17 20:59:29 +00:00
Matt Corallo
8fad498900 Increase our default/minimum dust limit to 354 sat/vbytes
330 sat/vbyte, the current value, is not sufficient to ensure a
future segwit script longer than 32 bytes meets the dust limit if
used for a shutdown script. Thus, we can either check the value
on shutdown or we can simply require segwit outputs and require a
dust value of no less than 354 sat/vbyte.

We swap the minimum dust value to 354 sat/vbyte here, requiring
segwit scripts in a future commit.

See https://github.com/lightningnetwork/lightning-rfc/issues/905
2021-09-17 20:32:59 +00:00
Matt Corallo
57f54bcc11 Drop broken test that is unfixable due to being undocumented
This should be reverted at some point, but the test is deficient
and breaks on later changes that are important to land ASAP.
2021-09-17 20:32:59 +00:00
Valentine Wallace
c828ff42c0
Add all_paths_failed field to PaymentFailed
see field docs for details
2021-09-17 15:36:27 -04:00
Valentine Wallace
8f1763159e
Prevent duplicate PaymentSent events
by removing all pending outbound payments associated with the same
MPP payment after the preimage is received
2021-09-17 15:36:24 -04:00
Valentine Wallace
ad81addd98
Add MPP ID to pending_outbound_htlcs
We'll use this to correlate MPP shards in upcoming commits
2021-09-17 15:36:21 -04:00
Valentine Wallace
641e20763f
Implement Readable/Writeable for HashSet
To be used in upcoming commits for MPP ID storage
2021-09-17 15:23:45 -04:00
Valentine Wallace
c986e52ce8
Add MppId field to HTLCSource as a way to correlate mpp payment paths 2021-09-17 15:23:45 -04:00
Valentine Wallace
f6f950db75
test utils: refactor fail_payment_along_route for mpp 2021-09-17 15:23:42 -04:00
Valentine Wallace
612d1fb120
Update Watch docs to disallow dup channel outpoints
on watch_channel
2021-09-17 14:50:44 -04:00
Valentine Wallace
e06484b0f4
Don't apply monitor updates after watch_channel PermFail
The full stack fuzzer found an unreachable panic where we receive a
FundingSigned with a duplicate channel outpoint.
2021-09-17 14:50:20 -04:00
Matt Corallo
088daf79aa
Merge pull request #1070 from TheBlueMatt/2021-09-fix-bindings-ignore
Move CounterpartyForwardingInfo from channel to channelmanager
2021-09-17 17:26:54 +00:00
Valentine Wallace
3d77cc790c
Allow multiple monitor_update_failed calls
without requiring calls to channel_monitor_updated in between.

Found by the fuzzer
2021-09-15 15:37:27 -04:00