rust-lightning
2 years agoBe less aggressive in outbound HTLC CLTV timeout checks 2021-10-less-aggressive-htlc-timeouts
Matt Corallo [Wed, 13 Oct 2021 04:19:13 +0000 (04:19 +0000)]
Be less aggressive in outbound HTLC CLTV timeout checks

We currently assume our counterparty is naive and misconfigured and
may force-close a channel to get an HTLC we just forwarded them.

There shouldn't be any reason to do this - we don't have any such
bug, and we shouldn't start by assuming our counterparties are
buggy. Worse, this results in refusing to forward payments today,
failing HTLCs for largely no reason.

Instead, we keep a fairly conservative check, but not one which
will fail HTLC forwarding spuriously - testing only that the HTLC
doesn't expire for a few blocks from now.

Fixes #1114.

2 years agoMerge pull request #1077 from jkczyz/2021-09-failing-route-hop
Matt Corallo [Wed, 13 Oct 2021 01:13:41 +0000 (01:13 +0000)]
Merge pull request #1077 from jkczyz/2021-09-failing-route-hop

Include short channel id in PaymentPathFailed

2 years agoAdd failing short channel id to PaymentPathFailed
Jeffrey Czyz [Thu, 16 Sep 2021 04:22:44 +0000 (23:22 -0500)]
Add failing short channel id to PaymentPathFailed

This will be useful for scoring channels when a payment fails.

2 years agoMerge pull request #1116 from TheBlueMatt/2021-10-test-local-chan-routing
Matt Corallo [Tue, 12 Oct 2021 18:29:05 +0000 (18:29 +0000)]
Merge pull request #1116 from TheBlueMatt/2021-10-test-local-chan-routing

Use local channel state when constructing routes in test macro  + Fix compile-warning

2 years agoFix loop label shadowing warning 2021-10-test-local-chan-routing
Matt Corallo [Sat, 9 Oct 2021 20:14:13 +0000 (20:14 +0000)]
Fix loop label shadowing warning

2 years agoUse local channel state when constructing routes in test macro
Matt Corallo [Tue, 12 Oct 2021 02:29:01 +0000 (02:29 +0000)]
Use local channel state when constructing routes in test macro

This is a bit more realistic and needed to route over non-public
channels.

2 years agoClean up fee_insufficient computation
Jeffrey Czyz [Mon, 11 Oct 2021 18:18:49 +0000 (13:18 -0500)]
Clean up fee_insufficient computation

2 years agoMerge pull request #1098 from 1nF0rmed/2021-09-adds-discard-funding-event
Matt Corallo [Sat, 9 Oct 2021 17:17:55 +0000 (17:17 +0000)]
Merge pull request #1098 from 1nF0rmed/2021-09-adds-discard-funding-event

Add Event::DiscardFunding generation

2 years agoAdds DiscardFunding event
1nF0rmed [Mon, 27 Sep 2021 16:50:07 +0000 (22:20 +0530)]
Adds DiscardFunding event

During the event of a channel close, if the funding transaction
is yet to be broadcasted then a DiscardFunding event is issued
along with the ChannelClose event.

2 years agoMerge pull request #1107 from dunxen/2021-10-swap-pubkey-for-bytearray
Matt Corallo [Fri, 8 Oct 2021 21:02:53 +0000 (21:02 +0000)]
Merge pull request #1107 from dunxen/2021-10-swap-pubkey-for-bytearray

Replace PublicKey with [u8; 33] in NetworkGraph

2 years agoMerge pull request #1062 from galderz/t_payment_hash_999
Matt Corallo [Fri, 8 Oct 2021 20:49:19 +0000 (20:49 +0000)]
Merge pull request #1062 from galderz/t_payment_hash_999

2 years agoReplace PublicKey with [u8; 33] in NetworkGraph
Duncan Dean [Tue, 5 Oct 2021 20:40:34 +0000 (22:40 +0200)]
Replace PublicKey with [u8; 33] in NetworkGraph

2 years agoAdd payment_hash to PaymentSent #999
Galder Zamarreño [Tue, 31 Aug 2021 07:56:21 +0000 (08:56 +0100)]
Add payment_hash to PaymentSent #999

2 years agoMerge pull request #1109 from TheBlueMatt/2021-10-init-fail-payment-retry-leak
Matt Corallo [Thu, 7 Oct 2021 23:14:06 +0000 (23:14 +0000)]
Merge pull request #1109 from TheBlueMatt/2021-10-init-fail-payment-retry-leak

Move pending payment tracking to after the new HTLC flies

2 years agoCorrect error returned when `retry_payment` doesn't have a payment 2021-10-init-fail-payment-retry-leak
Matt Corallo [Tue, 5 Oct 2021 22:28:32 +0000 (22:28 +0000)]
Correct error returned when `retry_payment` doesn't have a payment

2 years agoMove pending payment tracking to after the new HTLC flies
Matt Corallo [Mon, 4 Oct 2021 04:47:33 +0000 (04:47 +0000)]
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.

2 years agoPass hop index in construct_onion_keys_callback
Jeffrey Czyz [Tue, 14 Sep 2021 16:44:19 +0000 (11:44 -0500)]
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.

2 years agoRemove special case for onion error expiry_too_far
Jeffrey Czyz [Mon, 20 Sep 2021 16:25:39 +0000 (11:25 -0500)]
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.

2 years agoMerge pull request #1079 from TheBlueMatt/2021-09-stale-docs
Matt Corallo [Tue, 5 Oct 2021 23:16:20 +0000 (23:16 +0000)]
Merge pull request #1079 from TheBlueMatt/2021-09-stale-docs

Update Event::PaymentReceived docs since we require payment secret

2 years agoUpdate Event::PaymentReceived docs since we require payment secret 2021-09-stale-docs
Matt Corallo [Fri, 17 Sep 2021 17:51:13 +0000 (17:51 +0000)]
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.

2 years agoMove tests of payment retries into a new module
Matt Corallo [Tue, 5 Oct 2021 19:10:42 +0000 (19:10 +0000)]
Move tests of payment retries into a new module

2 years agoMerge pull request #1100 from TheBlueMatt/2021-09-multihop-route-hint-fix
Matt Corallo [Tue, 5 Oct 2021 18:43:39 +0000 (18:43 +0000)]
Merge pull request #1100 from TheBlueMatt/2021-09-multihop-route-hint-fix

Consider many first-hop paths to the same counterparty in routing

2 years agoMerge pull request #1096 from valentinewallace/2021-09-mpp-retries
Matt Corallo [Thu, 30 Sep 2021 01:19:04 +0000 (01:19 +0000)]
Merge pull request #1096 from valentinewallace/2021-09-mpp-retries

2 years agoExpire outbound payments after 3 blocks if no parts are pending
Valentine Wallace [Tue, 28 Sep 2021 22:31:39 +0000 (18:31 -0400)]
Expire outbound payments after 3 blocks if no parts are pending

2 years agoDon't remove failed payments when all paths fail
Valentine Wallace [Tue, 28 Sep 2021 00:47:32 +0000 (20:47 -0400)]
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

2 years agoAdd method to retry payments
Valentine Wallace [Fri, 24 Sep 2021 20:04:47 +0000 (16:04 -0400)]
Add method to retry payments

2 years agoMerge pull request #1080 from valentinewallace/2021-09-dup-chan-outpoint
Matt Corallo [Thu, 30 Sep 2021 00:01:35 +0000 (00:01 +0000)]
Merge pull request #1080 from valentinewallace/2021-09-dup-chan-outpoint

Fix fuzzer-found panic from duplicate channel outpoint

2 years agof readability improvements from val 2021-09-multihop-route-hint-fix
Matt Corallo [Wed, 29 Sep 2021 23:16:22 +0000 (23:16 +0000)]
f readability improvements from val

2 years agoMerge pull request #1076 from TheBlueMatt/2021-09-forwardable-regen
Matt Corallo [Wed, 29 Sep 2021 20:24:37 +0000 (20:24 +0000)]
Merge pull request #1076 from TheBlueMatt/2021-09-forwardable-regen

2 years agoRegenerate PendingHTLCsForwardable on reload instead of serializing 2021-09-forwardable-regen
Matt Corallo [Wed, 15 Sep 2021 19:20:44 +0000 (19:20 +0000)]
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

2 years agoConsider many first-hop paths to the same counterparty in routing
Matt Corallo [Wed, 29 Sep 2021 19:15:16 +0000 (19:15 +0000)]
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.

2 years agoCorrect step number in `get_route`
Matt Corallo [Wed, 29 Sep 2021 18:51:14 +0000 (18:51 +0000)]
Correct step number in `get_route`

2 years agochannelmanager: Add retry data to pending_outbound_payments
Valentine Wallace [Fri, 24 Sep 2021 20:02:11 +0000 (16:02 -0400)]
channelmanager: Add retry data to pending_outbound_payments

2 years agoRefactor send_payment internals for retries 2
Valentine Wallace [Fri, 24 Sep 2021 16:12:16 +0000 (12:12 -0400)]
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

2 years agoRefactor send_payment internals for retries
Valentine Wallace [Thu, 23 Sep 2021 20:30:15 +0000 (16:30 -0400)]
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

2 years agoReturn PaymentId from send_*payment functions
Valentine Wallace [Thu, 23 Sep 2021 20:13:30 +0000 (16:13 -0400)]
Return PaymentId from send_*payment functions

Used in upcoming commits for retries

2 years agoRename MppId to PaymentId
Valentine Wallace [Thu, 23 Sep 2021 20:06:12 +0000 (16:06 -0400)]
Rename MppId to PaymentId

Leftover from previous PR Jeff feedback.

Useful in upcoming commits as we'll expose this to users for payment retries

2 years agoMerge pull request #1065 from TheBlueMatt/2021-08-bump-dust
Matt Corallo [Mon, 27 Sep 2021 20:39:02 +0000 (20:39 +0000)]
Merge pull request #1065 from TheBlueMatt/2021-08-bump-dust

Increase our default/minimum dust limit and decrease our max

2 years agoRename MIN_DUST_LIMIT_SATOSHIS constant to disambiguate chan vs P2P 2021-08-bump-dust
Matt Corallo [Mon, 27 Sep 2021 17:56:21 +0000 (17:56 +0000)]
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.

2 years agoForce-close channels if closing transactions may be non-standard
Matt Corallo [Wed, 1 Sep 2021 20:33:49 +0000 (20:33 +0000)]
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.

2 years agoRequire user cooperative close payout scripts to be Segwit
Matt Corallo [Wed, 1 Sep 2021 20:22:49 +0000 (20:22 +0000)]
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.

2 years agoReduce the maximum allowed counterparty dust limit to 546 sat/vbyte
Matt Corallo [Wed, 1 Sep 2021 20:18:47 +0000 (20:18 +0000)]
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.

2 years agoMerge pull request #1097 from TheBlueMatt/2021-09-clonable-netgraph
Matt Corallo [Mon, 27 Sep 2021 18:19:19 +0000 (18:19 +0000)]
Merge pull request #1097 from TheBlueMatt/2021-09-clonable-netgraph

Make `NetworkGraph` Clone-able again

2 years agoMake `NetworkGraph` Clone-able again 2021-09-clonable-netgraph
Matt Corallo [Sun, 26 Sep 2021 04:20:44 +0000 (04:20 +0000)]
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.

2 years agoMerge pull request #1095 from TheBlueMatt/2021-09-0.0.101 v0.0.101
Matt Corallo [Thu, 23 Sep 2021 18:43:25 +0000 (18:43 +0000)]
Merge pull request #1095 from TheBlueMatt/2021-09-0.0.101

Bump Crate versions to 0.0.101 (and invoice to 0.9)

2 years agoBump Crate versions to 0.0.101 (and invoice to 0.9) 2021-09-0.0.101
Matt Corallo [Thu, 23 Sep 2021 18:22:29 +0000 (18:22 +0000)]
Bump Crate versions to 0.0.101 (and invoice to 0.9)

2 years agoMerge pull request #1085 from TheBlueMatt/2021-09-0.0.101
Matt Corallo [Thu, 23 Sep 2021 18:12:02 +0000 (18:12 +0000)]
Merge pull request #1085 from TheBlueMatt/2021-09-0.0.101

Cut 0.0.101

2 years agoUpdate CHANGELOG for 0.0.101
Matt Corallo [Mon, 20 Sep 2021 22:07:03 +0000 (22:07 +0000)]
Update CHANGELOG for 0.0.101

2 years agoMerge pull request #1094 from TheBlueMatt/2021-09-type-explicit-bounds
Matt Corallo [Thu, 23 Sep 2021 16:59:36 +0000 (16:59 +0000)]
Merge pull request #1094 from TheBlueMatt/2021-09-type-explicit-bounds

Use Infallible for the unconstructable default custom message type

2 years agoMake method time on trait impl explitit to help bindings generator 2021-09-type-explicit-bounds
Matt Corallo [Thu, 23 Sep 2021 04:02:58 +0000 (04:02 +0000)]
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.

2 years agoDrop redundant generic bounds when the trait requires the bounds
Matt Corallo [Wed, 22 Sep 2021 23:45:27 +0000 (23:45 +0000)]
Drop redundant generic bounds when the trait requires the bounds

2 years agoUse Infallible for the unconstructable default custom message type
Matt Corallo [Wed, 22 Sep 2021 19:00:30 +0000 (19:00 +0000)]
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.

2 years agoMerge pull request #1093 from TheBlueMatt/2021-09-type-explicit-bounds
Matt Corallo [Wed, 22 Sep 2021 16:49:02 +0000 (16:49 +0000)]
Merge pull request #1093 from TheBlueMatt/2021-09-type-explicit-bounds

Make `ChainMonitor::get_claimable_balances` take a slice of refs

2 years agoMake `ChainMonitor::get_claimable_balances` take a slice of refs
Matt Corallo [Wed, 22 Sep 2021 03:57:53 +0000 (03:57 +0000)]
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.

2 years agoMerge pull request #1092 from TheBlueMatt/2021-09-type-explicit-bounds
Matt Corallo [Wed, 22 Sep 2021 02:46:25 +0000 (02:46 +0000)]
Merge pull request #1092 from TheBlueMatt/2021-09-type-explicit-bounds

Move trait bounds on `wire::Type` from use to the trait itself

2 years agoMove trait bounds on `wire::Type` from use to the trait itself
Matt Corallo [Wed, 22 Sep 2021 01:04:35 +0000 (01:04 +0000)]
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.

2 years agoMerge pull request #1091 from TheBlueMatt/2021-09-997-winblowz
Matt Corallo [Tue, 21 Sep 2021 22:34:00 +0000 (22:34 +0000)]
Merge pull request #1091 from TheBlueMatt/2021-09-997-winblowz

Fix windows-only test failure added in #997

2 years agoMerge pull request #1084 from valentinewallace/2021-09-rename-paymentfailed
Matt Corallo [Tue, 21 Sep 2021 22:14:42 +0000 (22:14 +0000)]
Merge pull request #1084 from valentinewallace/2021-09-rename-paymentfailed

Rename Event PaymentFailed -> PaymentPathFailed

2 years agoMerge pull request #1061 from sr-gi/add-transaction-convert
Matt Corallo [Tue, 21 Sep 2021 22:04:15 +0000 (22:04 +0000)]
Merge pull request #1061 from sr-gi/add-transaction-convert

Adds Transaction to lighting-block-sync::convert

2 years agoMerge pull request #1088 from TheBlueMatt/2021-09-1063-fixups
Matt Corallo [Tue, 21 Sep 2021 21:59:11 +0000 (21:59 +0000)]
Merge pull request #1088 from TheBlueMatt/2021-09-1063-fixups

Fix a panic in Route's new fee-calculation methods and clean up

2 years agoAdd path field to PaymentPathFailed event
Valentine Wallace [Mon, 20 Sep 2021 16:56:33 +0000 (12:56 -0400)]
Add path field to PaymentPathFailed event

2 years agoRename PaymentFailed -> PaymentPathFailed
Valentine Wallace [Mon, 20 Sep 2021 16:18:49 +0000 (12:18 -0400)]
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

2 years agoMerge pull request #1087 from TheBlueMatt/2021-09-event-backwards-compat-fix
Matt Corallo [Tue, 21 Sep 2021 21:37:32 +0000 (21:37 +0000)]
Merge pull request #1087 from TheBlueMatt/2021-09-event-backwards-compat-fix

Fix future unknown `Event` variant backwards compatibility

2 years agoFix windows-only test failure added in #997 2021-09-997-winblowz
Matt Corallo [Tue, 21 Sep 2021 20:31:16 +0000 (20:31 +0000)]
Fix windows-only test failure added in #997

This is a trivial bugfix to add a missing test updated required in
PR 997.

2 years agoMerge pull request #1090 from TheBlueMatt/2021-09-absurd-timeouts
Matt Corallo [Tue, 21 Sep 2021 21:12:34 +0000 (21:12 +0000)]
Merge pull request #1090 from TheBlueMatt/2021-09-absurd-timeouts

Bump HTTP read timeout to match reality of Bitcoin Core blocking

2 years agoAdds Transaction to lighting-block-sync::convert
Sergi Delgado Segura [Wed, 25 Aug 2021 14:26:19 +0000 (16:26 +0200)]
Adds Transaction to lighting-block-sync::convert

Includes disclaimer in docs, see https://github.com/rust-bitcoin/rust-lightning/pull/1061#issuecomment-911960862

2 years agoFix future unknown `Event` variant backwards compatibility 2021-09-event-backwards-compat-fix
Matt Corallo [Tue, 21 Sep 2021 17:48:40 +0000 (17:48 +0000)]
Fix future unknown `Event` variant backwards compatibility

In 8ffc2d1742ff1171a87b0410b21cbbd557ff8247, 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.

2 years agoMerge pull request #997 from ariard/2021-07-add-chan-closed
Matt Corallo [Tue, 21 Sep 2021 20:35:29 +0000 (20:35 +0000)]
Merge pull request #997 from ariard/2021-07-add-chan-closed

Add Event::ChannelClosed generation

2 years agoAdd `pending_events` deadlock detection in `handle_error`
Antoine Riard [Tue, 13 Jul 2021 16:59:39 +0000 (12:59 -0400)]
Add `pending_events` deadlock detection in `handle_error`

2 years agoAdd ChannelClosed generation at cooperative/force-close/error processing
Antoine Riard [Tue, 21 Sep 2021 16:25:38 +0000 (12:25 -0400)]
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.

2 years agoExtend MsgHandleErrInternal with a new chan_id field Option<[u8; 32]>
Antoine Riard [Tue, 13 Jul 2021 16:55:32 +0000 (12:55 -0400)]
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.

2 years agoRename MonitorEvent::CommitmentTxBroadcasted to CommitmentTxConfirmed
Antoine Riard [Tue, 21 Sep 2021 19:24:43 +0000 (15:24 -0400)]
Rename MonitorEvent::CommitmentTxBroadcasted to CommitmentTxConfirmed

2 years agoAdd Event::ChannelClosed generation at channel shutdown
Antoine Riard [Tue, 13 Jul 2021 17:04:54 +0000 (13:04 -0400)]
Add Event::ChannelClosed generation at channel shutdown

2 years agoBump HTTP read timeout to match reality of Bitcoin Core blocking 2021-09-absurd-timeouts
Matt Corallo [Tue, 21 Sep 2021 18:48:33 +0000 (18:48 +0000)]
Bump HTTP read timeout to match reality of Bitcoin Core blocking

2 years agoFix a panic in Route's new fee-calculation methods and clean up 2021-09-1063-fixups
Matt Corallo [Tue, 21 Sep 2021 18:09:15 +0000 (18:09 +0000)]
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.

2 years agoMerge pull request #1082 from vss96/process_events_docs
Matt Corallo [Tue, 21 Sep 2021 18:54:19 +0000 (18:54 +0000)]
Merge pull request #1082 from vss96/process_events_docs

Update docs to specify where PeerManager::process_events is called

2 years agoMerge pull request #1063 from galderz/t_total_fee_999
Matt Corallo [Tue, 21 Sep 2021 18:09:12 +0000 (18:09 +0000)]
Merge pull request #1063 from galderz/t_total_fee_999

Add method to count total fees in a Route #999

2 years agoUpdate docs to specify where process events is called
vss96 [Mon, 20 Sep 2021 19:05:26 +0000 (00:35 +0530)]
Update docs to specify where process events is called

2 years agoAdd methods to count total fees and total amount in a Route #999
Galder Zamarreño [Fri, 27 Aug 2021 18:22:26 +0000 (19:22 +0100)]
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.

2 years agoMerge pull request #1068 from TheBlueMatt/2021-09-ser-cleanup
Matt Corallo [Sat, 18 Sep 2021 01:42:29 +0000 (01:42 +0000)]
Merge pull request #1068 from TheBlueMatt/2021-09-ser-cleanup

Simplify Message Serialization and Parse TLV Suffix

2 years agoConvert most P2P msg serialization to a new macro with TLV suffixes 2021-09-ser-cleanup
Matt Corallo [Sun, 29 Aug 2021 06:03:41 +0000 (06:03 +0000)]
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.

2 years agoAdd forward-compat due serialization variants of HTLCFailureMsg
Matt Corallo [Sun, 29 Aug 2021 02:55:39 +0000 (02:55 +0000)]
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.

2 years ago[fuzz] Swap mode on most messages to account for TLV suffix
Matt Corallo [Sat, 4 Sep 2021 06:37:36 +0000 (06:37 +0000)]
[fuzz] Swap mode on most messages to account for TLV suffix

2 years agoDrop writer size hinting/message vec preallocation
Matt Corallo [Sun, 29 Aug 2021 05:26:39 +0000 (05:26 +0000)]
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.

2 years agoMerge pull request #1053 from valentinewallace/2021-08-dedup-payment-sent
Matt Corallo [Fri, 17 Sep 2021 20:59:29 +0000 (20:59 +0000)]
Merge pull request #1053 from valentinewallace/2021-08-dedup-payment-sent

Deduplicate PaymentSent events for MPP payments

2 years agoIncrease our default/minimum dust limit to 354 sat/vbytes
Matt Corallo [Tue, 31 Aug 2021 23:22:14 +0000 (23:22 +0000)]
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

2 years agoDrop broken test that is unfixable due to being undocumented
Matt Corallo [Wed, 1 Sep 2021 20:50:45 +0000 (20:50 +0000)]
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.

2 years agoAdd all_paths_failed field to PaymentFailed
Valentine Wallace [Fri, 17 Sep 2021 01:09:46 +0000 (21:09 -0400)]
Add all_paths_failed field to PaymentFailed

see field docs for details

2 years agoPrevent duplicate PaymentSent events
Valentine Wallace [Fri, 20 Aug 2021 00:44:45 +0000 (20:44 -0400)]
Prevent duplicate PaymentSent events

by removing all pending outbound payments associated with the same
MPP payment after the preimage is received

2 years agoAdd MPP ID to pending_outbound_htlcs
Valentine Wallace [Thu, 19 Aug 2021 23:56:53 +0000 (19:56 -0400)]
Add MPP ID to pending_outbound_htlcs

We'll use this to correlate MPP shards in upcoming commits

2 years agoImplement Readable/Writeable for HashSet
Valentine Wallace [Mon, 13 Sep 2021 00:46:11 +0000 (20:46 -0400)]
Implement Readable/Writeable for HashSet

To be used in upcoming commits for MPP ID storage

2 years agoAdd MppId field to HTLCSource as a way to correlate mpp payment paths
Valentine Wallace [Thu, 19 Aug 2021 20:45:55 +0000 (16:45 -0400)]
Add MppId field to HTLCSource as a way to correlate mpp payment paths

2 years agotest utils: refactor fail_payment_along_route for mpp
Valentine Wallace [Wed, 1 Sep 2021 21:30:11 +0000 (17:30 -0400)]
test utils: refactor fail_payment_along_route for mpp

2 years agoUpdate Watch docs to disallow dup channel outpoints
Valentine Wallace [Fri, 17 Sep 2021 18:50:44 +0000 (14:50 -0400)]
Update Watch docs to disallow dup channel outpoints

on watch_channel

2 years agoDon't apply monitor updates after watch_channel PermFail
Valentine Wallace [Fri, 17 Sep 2021 18:50:20 +0000 (14:50 -0400)]
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.

2 years agoMerge pull request #1070 from TheBlueMatt/2021-09-fix-bindings-ignore
Matt Corallo [Fri, 17 Sep 2021 17:26:54 +0000 (17:26 +0000)]
Merge pull request #1070 from TheBlueMatt/2021-09-fix-bindings-ignore

Move CounterpartyForwardingInfo from channel to channelmanager

2 years agoMerge pull request #1066 from valentinewallace/2021-08-fix-double-temp-failure
Matt Corallo [Wed, 15 Sep 2021 20:51:37 +0000 (20:51 +0000)]
Merge pull request #1066 from valentinewallace/2021-08-fix-double-temp-failure

Allow multiple calls to `monitor_update_failed`

2 years agoAllow multiple monitor_update_failed calls
Valentine Wallace [Fri, 3 Sep 2021 21:24:01 +0000 (17:24 -0400)]
Allow multiple monitor_update_failed calls

without requiring calls to channel_monitor_updated in between.

Found by the fuzzer

2 years agoUpdate fuzz README with latest instructions
Valentine Wallace [Thu, 26 Aug 2021 19:03:09 +0000 (15:03 -0400)]
Update fuzz README with latest instructions

2 years agoMerge pull request #1074 from p2pderivatives/add-node-id-to-custom-msg-cb
Matt Corallo [Wed, 15 Sep 2021 18:54:15 +0000 (18:54 +0000)]
Merge pull request #1074 from p2pderivatives/add-node-id-to-custom-msg-cb

Add node id to custom message callback