Commit graph

3116 commits

Author SHA1 Message Date
Valentine Wallace
8464875555
Drop need to store pending inbound payments
and replace payment_secret with encrypted metadata

See docs on `inbound_payment::verify` for details

Also add min_value checks to all create_inbound_payment* methods
2021-12-16 15:32:21 -08:00
Valentine Wallace
1d516a6fc5
Add get_single_block to chacha20 module
In the next commit, we'll want to get a single block from a chacha stream that
takes a 16-byte nonce.
2021-12-16 15:30:52 -08:00
Valentine Wallace
063b7583c1
Macro-ize checking that the total value of an MPP's parts is sane
This DRY-ed code will be used in upcoming commits when we stop storing inbound
payment data
2021-12-16 15:30:52 -08:00
Valentine Wallace
6dd1ec1fed
Add get_inbound_payment_key_material to KeysInterface
This will allow us to retrieve key material for encrypting/decrypting inbound
payment info, in upcoming commits
2021-12-16 15:30:52 -08:00
Matt Corallo
cec8ce0fcb
Merge pull request #1212 from TheBlueMatt/2021-12-timeout-graph
Add a method to prune stale channels from NetworkGraph
2021-12-16 23:04:00 +00:00
Matt Corallo
73e8dc41a6 Automatically prune NetworkGraph of stale channels hourly in BP 2021-12-16 18:33:24 +00:00
Matt Corallo
cd43ff4a5e Reject channel_update messages with timestamps too old or new
Because we time out channel info that is older than two weeks now,
we should also reject new channel info that is older than two
weeks, in addition to rejecting future channel info.
2021-12-16 18:33:24 +00:00
Matt Corallo
4677e14c00 Add a method to prune stale channels from NetworkGraph
We define "stale" as "haven't heard an updated channel_update in
two weeks", as described in BOLT 7.

We also filter out stale channels at write-time for `std` users, as
we can look up the current time.
2021-12-16 18:33:24 +00:00
Matt Corallo
c575429639 Drop allow_wallclock_use feature in favor of simply using std
Fixes #1147.
2021-12-16 18:33:24 +00:00
Matt Corallo
11d644824e DRY up network_graph tests substantially with message creation fns 2021-12-16 18:33:24 +00:00
Matt Corallo
6e27ca0316
Merge pull request #1214 from TheBlueMatt/2021-12-fix-tokio-msrv-bump 2021-12-16 17:44:21 +00:00
Matt Corallo
01ef55ae86 Build no-std on 1.47 now that core2 supports it 2021-12-16 02:22:56 +00:00
Matt Corallo
144145e4f9 Pin tokio to 1.14.0 in CI for older rustc's 2021-12-16 02:22:56 +00:00
Matt Corallo
064d709910
Merge pull request #1148 from dunxen/2021-11-new-onion-errors
Add mpp_timeout and invalid_onion_payload descriptions
2021-12-15 23:32:30 +00:00
Conor Okus
88a86d126f
Merge pull request #1211 from ConorOkus/2021-11-add-max-conversion
Update docs to add max return value to conversion list
2021-12-15 16:15:21 +00:00
Matt Corallo
54114c9d85
Merge pull request #1202 from TheBlueMatt/2021-12-fix-retries-races
Fix payment retry races and inform users when a payment fails
2021-12-15 04:58:46 +00:00
Matt Corallo
05d7a33a58 Make attempting to retry a succeeded payment an APIError, not Route
This is symmetric with the new failure once a payment is abandoned.
2021-12-15 03:57:13 +00:00
Matt Corallo
3086bd8c8e Use Event::PaymentFailed in InvoicePayer to remove retry count
This finally fixes the bug described in the previous commits where
we retry a payment after its retry count has expired due to early
removal of the payment from the retry count tracking map. A test is
also added which demonstrates the bug in previous versions and
which passes now.

Fixes #1164.
2021-12-15 03:57:13 +00:00
Matt Corallo
7782d0a1ef Expose an event when a payment has failed and retries complete
When a payment fails, a payer needs to know when they can consider
a payment as fully-failed, and when only some of the HTLCs in the
payment have failed. This isn't possible with the current event
scheme, as discovered recently and as described in the previous
commit.

This adds a new event which describes when a payment is fully and
irrevocably failed, generating it only after the payment has
expired or been marked as expired with
`ChannelManager::mark_retries_exceeded` *and* all HTLCs for it
have failed. With this, a payer can more simply deduce when a
payment has failed and use that to remove payment state or
finalize a payment failure.
2021-12-15 03:57:13 +00:00
Matt Corallo
0b3240ee6a Add a variant to PendingOutboundPayment for retries-exceeded
When a payer gives up trying to retry a payment, they don't know
for sure what the current state of the event queue is.
Specifically, they cannot be sure that there are not multiple
additional `PaymentPathFailed` or even `PaymentSuccess` events
pending which they will see later. Thus, they have a very hard
time identifying whether a payment has truly failed (and informing
the UI of that fact) or if it is still pending. See [1] for more
information.

In order to avoid this mess, we will resolve it here by having the
payer give `ChannelManager` a bit more information - when they
have given up on a payment - and using that to generate a
`PaymentFailed` event when all paths have failed.

This commit adds the neccessary storage and changes for the new
state inside `ChannelManager` and a public method to mark a payment
as failed, the next few commits will add the new `Event` and use
the new features in our `PaymentRetrier`.

[1] https://github.com/lightningdevkit/rust-lightning/issues/1164
2021-12-15 03:57:13 +00:00
Matt Corallo
8c9615e8d6 DRY up payment failure macros in functional_test_utils
... with a more extensible expectation-checking framework for them.
2021-12-15 03:55:55 +00:00
Duncan Dean
e88c7210f8
Add mpp_timeout and invalid_onion_payload descriptions & handling 2021-12-14 21:11:32 +02:00
Conor Okus
0c34737e35 Updates Fee estimator docs to include a max return value for get_est_sat_per_1000_weight
Updates docs to include a max return value for get_est_sat_per_1000_weight

Adds max to both conversions

Additional detail
2021-12-14 12:36:34 +00:00
Matt Corallo
09714e6fe2
Merge pull request #1169 from TheBlueMatt/2021-11-fix-update-announcements
Fix announcements of our own gossip
2021-12-09 18:21:55 +00:00
Matt Corallo
0fe2aef0e6 Add a comment describing the timestamp field's use 2021-12-09 03:49:50 +00:00
Matt Corallo
61518f9721
Merge pull request #1203 from lightning-signer/2021-12-value-to-self
Getter for the total channel balance
2021-12-08 02:24:32 +00:00
Matt Corallo
3cf1b15b78
Merge pull request #1210 from TheBlueMatt/2021-12-new-codecod-upload
Upgrade to codecov uploader v2
2021-12-08 01:01:34 +00:00
Matt Corallo
4fc7bcee58 Upgrade to codecov uploader v2
Some time ago codecov stopped supporting their old v1 uploader, and
it seems they've now finally turned it off, so we aren't getting
any coverage reports anymore. Hopefully upgrading is pretty trivial.
2021-12-07 22:16:41 +00:00
Matt Corallo
cd4dc39a8c
Merge pull request #1208 from TheBlueMatt/2021-12-less-force-close
Reduce force-closures with user fee estimators which round poorly
2021-12-07 20:11:47 +00:00
Matt Corallo
cd9cd47f68
Merge pull request #1205 from TheBlueMatt/2021-12-new-feature-bit
Support the channel_type feature bit.
2021-12-07 19:28:29 +00:00
Matt Corallo
d5e70ad185 Reduce force-closures with user fee estimators which round poorly
See comment for more
2021-12-07 18:49:05 +00:00
Matt Corallo
8f4a22fe31 Support the channel_type feature bit.
Note that this feature bit does absolutely nothing. We signal it
(as we already support channel type negotiation), but do not bother
to look to see if peers support it, as we don't care - we simply
look for the TLV entry and deduce if a peer supports channel type
negotiation from that.

The only behavioral change at all here is that we don't barf if a
peer sets channel type negotiation to required via the feature bit
(instead of failing the channel at open-time), but of course no
implementations do this, and likely won't for some time (if ever -
you can simply fail channels with unknown types later, and there's
no reason to refuse connections, really).

As defined in https://github.com/lightning/bolts/pull/906
2021-12-07 18:05:29 +00:00
Devrandom
02a9f92ea4 Getter for the total channel balance
The existing balance getters subtract reserve, this one does not.
2021-12-07 15:06:22 +01:00
Matt Corallo
3ec529d7cc
Merge pull request #1201 from jkczyz/2021-12-idempotent-channelmanager
Ensure ChannelManager methods are idempotent
2021-12-07 00:42:02 +00:00
Jeffrey Czyz
c453d04137
Ensure ChannelManager methods are idempotent
During event handling, ChannelManager methods may need to be called as
indicated in the Event documentation. Ensure that these calls are
idempotent for the same event rather than panicking. This allows users
to persist events for later handling without needing to worry about
processing the same event twice (e.g., if ChannelManager is not
persisted but the events were, the restarted ChannelManager would return
some of the same events).
2021-12-06 17:18:33 -06:00
Matt Corallo
9c6961ea84
Merge pull request #1204 from TheBlueMatt/2021-12-no-torv2
Remove OnionV2 parsing support
2021-12-06 22:49:18 +00:00
Matt Corallo
d47aebca38
Merge pull request #1130 from TheBlueMatt/2021-10-mon-fail-after-conf
Always return failure in update_monitor after funding spend
2021-12-06 19:35:58 +00:00
Matt Corallo
1b88f1638e Add trivial test of monitor update failure during block connection 2021-12-06 18:39:37 +00:00
Matt Corallo
9fe0cf19f6 Add a test for MonitorEvent holding when they complete out-of-order 2021-12-06 18:39:37 +00:00
Matt Corallo
fa62775f9d Add a simple test for ChainMonitor MonitorUpdate-holding behavior 2021-12-06 18:39:37 +00:00
Matt Corallo
6bcb270ae1 Make APIError debug output more clear by including the variant 2021-12-06 18:39:37 +00:00
Matt Corallo
87b6879622 Drop MonitorUpdateErr in favor of opaque errors.
We don't expect users to ever change behavior based on the string
contained in a `MonitorUpdateErr`, except log it, so there's little
reason to not just log it ourselves and return a `()` for errors.

We do so here, simplifying the callsite in `ChainMonitor` as well.
2021-12-06 18:39:37 +00:00
Matt Corallo
25542b8157 Always return failure in update_monitor after funding spend
Previously, monitor updates were allowed freely even after a
funding-spend transaction confirmed. This would allow a race
condition where we could receive a payment (including the
counterparty revoking their broadcasted state!) and accept it
without recourse as long as the ChannelMonitor receives the block
first, the full commitment update dance occurs after the block is
connected, and before the ChannelManager receives the block.

Obviously this is an incredibly contrived race given the
counterparty would be risking their full channel balance for it,
but its worth fixing nonetheless as it makes the potential
ChannelMonitor states simpler to reason about.

The test in this commit also tests the behavior changed in the
previous commit.
2021-12-06 18:39:37 +00:00
Matt Corallo
aa5e5f9673 Define public getters for all feature flags
There's not a ton of reason not to do this, and moving it to the
macro removes some code.
2021-12-06 00:15:07 +00:00
Matt Corallo
361639decf Remove OnionV2 parsing support
OnionV2s don't (really) work on Tor anymore anyway, and the field
is set for removal in the BOLTs [1]. Sadly because of the way
addresses are parsed we have to continue to understand that type 3
addresses are 12 bytes long. Thus, for simplicity we keep the
`OnionV2` enum variant around and just make it an opaque 12 bytes,
with the documentation updated to note the deprecation.

[1] https://github.com/lightning/bolts/pull/940
2021-12-06 00:12:35 +00:00
Matt Corallo
ea89286569
Merge pull request #1197 from jkczyz/2021-11-score-successful-payment-path
Score successful payment paths
2021-12-03 21:04:41 +00:00
Jeffrey Czyz
857b4c08a5
Fix shift overflow in Scorer::channel_penalty_msat
An unchecked shift of more than 64 bits on u64 values causes a shift
overflow panic. This may happen if a channel is penalized only once and
(1) is not successfully routed through and (2) after 64 or more half
life decays. Use a checked shift to prevent this from happening.
2021-12-03 14:00:52 -06:00
Jeffrey Czyz
d28d6a5403
Decay channel failure penalty upon success
If a payment failed to route through a channel, a penalty is applied to
the channel in the future when finding a route. This penalty decays over
time. Immediately decay the penalty by one half life when a payment is
successfully routed through the channel.
2021-12-03 14:00:52 -06:00
Jeffrey Czyz
c36bf92499
Score successful payment paths
Expand the Score trait with a payment_path_successful function for
scoring successful payment paths. Called by InvoicePayer's EventHandler
implementation when processing PaymentPathSuccessful events. May be used
by Score implementations to revert any channel penalties that were
applied by calls to payment_path_failed.
2021-12-03 14:00:51 -06:00
Matt Corallo
a3e4af0bb8
Merge pull request #1196 from TheBlueMatt/2021-11-bad-rustdoc
Fix compilation in `payment` rustdoc examples
2021-12-01 20:14:14 +00:00