Commit graph

1555 commits

Author SHA1 Message Date
Matt Corallo
ba69536843
Merge pull request #1699 from TheBlueMatt/2022-08-announcement-rework 2022-09-09 00:34:10 +00:00
Matt Corallo
989cb064b5 Move broadcast_node_announcement to PeerManager
Some `NodeFeatures` will, in the future, represent features which
are not enabled by the `ChannelManager`, but by other message
handlers handlers. Thus, it doesn't make sense to determine the
node feature bits in the `ChannelManager`.

The simplest fix for this is to change to generating the
node_announcement in `PeerManager`, asking all the connected
handlers which feature bits they support and simply OR'ing them
together. While this may not be sufficient in the future as it
doesn't consider feature bit dependencies, support for those could
be handled at the feature level in the future.

This commit moves the `broadcast_node_announcement` function to
`PeerHandler` but does not yet implement feature OR'ing.
2022-09-08 19:50:36 +00:00
Matt Corallo
6b0afbe4d4 Send channel_{announcement,update} msgs on connection, not timer
When we connect to a new peer, immediately send them any
channel_announcement and channel_update messages for any public
channels we have with other peers. This allows us to stop sending
those messages on a timer when they have not changed and ensures
we are sending messages when we have peers connected, rather than
broadcasting at startup when we have no peers connected.
2022-09-08 19:50:36 +00:00
Matt Corallo
66011920bc Improve debuggability when tests fail due to excess events 2022-09-08 18:54:20 +00:00
Matt Corallo
e7673971be Dont use PaymentPathFailed a probe fails without making it out
When we fail to forward a probe HTLC at all and immediately fail it
(e.g. due to the first hop channel closing) we'd previously
spuriously generate only a `PaymentPathFailed` event. This violates
the expected API, as users expect a `ProbeFailed` event instead.

This fixes the oversight by ensuring we generate the correct event.

Thanks to @jkczyz for pointing out this issue.
2022-09-08 18:54:08 +00:00
Matt Corallo
fd328e71da Drop redundant code in fail_holding_cell_htlcs
`fail_holding_cell_htlcs` calls through to
`fail_htlc_backwards_internal` for HTLCs that need to be
failed-backwards but opts to generate its own payment failure
events for `HTLCSource:;OutboundRoute` HTLCs. There is no reason
for that as `fail_htlc_backwards_internal` will also happily
generate (now-)equivalent events for `HTLCSource::OutboundRoute`
HTLCs.

Thus, we can drop the redundant code and always call
`fail_htlc_backwards_internal` for each HTLC in
`fail_holding_cell_htlcs`.
2022-09-08 18:54:05 +00:00
Matt Corallo
5e65c49a82
Merge pull request #1702 from TheBlueMatt/2022-09-one-hop-retryable
Mark failed one-hop HTLCs as retrably
2022-09-08 17:34:04 +00:00
Matt Corallo
c57bb42204 Rename rejected_by_dest -> payment_failed_permanently
The `rejected_by_dest` field of the `PaymentPathFailed` event has
always been a bit of a misnomer, as its really more about retry
than where a payment failed. Now is as good a time as any to
rename it.
2022-09-07 20:58:05 +00:00
Matt Corallo
f76f60ff85 Mark failed counterparty-is-destination HTLCs retryable
When our counterparty is the payment destination and we receive
an `HTLCFailReason::Reason` in `fail_htlc_backwards_internal` we
currently always set `rejected_by_dest` in the `PaymentPathFailed`
event, implying the HTLC should *not* be retried.

There are a number of cases where we use `HTLCFailReason::Reason`,
but most should reasonably be treated as retryable even if our
counterparty was the destination (i.e. `!rejected_by_dest`):
 * If an HTLC times out on-chain, this doesn't imply that the
   payment is no longer retryable, though the peer may well be
   offline so retrying may not be very useful,
 * If a commitment transaction "containing" a dust HTLC is
   confirmed on-chain, this definitely does not imply the payment
   is no longer retryable
 * If the channel we intended to relay over was closed (or
   force-closed) we should retry over another path,
 * If the channel we intended to relay over did not have enough
   capacity we should retry over another path,
 * If we received a update_fail_malformed_htlc message from our
   peer, we likely should *not* retry, however this should be
   exceedingly rare, and appears to nearly never appear in practice

Thus, this commit simply disables the behavior here, opting to
treat all `HTLCFailReason::Reason` errors as retryable.

Note that prior to 93e645daf4 this
change would not have made sense as it would have resulted in us
retrying the payment over the same channel in some cases, however
we now "blame" our own channel and will avoid it when routing for
the same payment.
2022-09-07 20:43:17 +00:00
valentinewallace
301efc8a81
Merge pull request #1697 from TheBlueMatt/2022-08-event-docs
Clarify and consolidate event handling requirements
2022-09-06 22:04:39 -04:00
valentinewallace
e45db2bf6c
Merge pull request #1691 from TheBlueMatt/2022-08-dust-retry
Correct payment resolution after on chain failure of dust HTLCs
2022-09-06 20:02:50 -04:00
Matt Corallo
ce7e7d302a Clarify and consolidate event handling requirements
We've seen a bit of user confusion about the requirements for event
handling, largely because the idempotency and consistency
requirements weren't super clearly phrased. While we're at it, we
also consolidate some documentation out of the event handling
function onto the trait itself.

Fixes #1675.
2022-09-06 20:56:24 +00:00
Matt Corallo
a795e45b42 Correct payment resolution after on chain failure of dust HTLCs
Previously, we wouldn't mark a dust HTLC as permanently resolved if
the commitment transaction went on chain. This resulted in us
always considering the HTLC as pending on restart, when we load the
pending payments set from the monitors.

Fixes #1653.
2022-09-06 20:23:18 +00:00
valentinewallace
8c6cb9953a
Merge pull request #1657 from TheBlueMatt/2022-08-async-man-update
Add a background processor which is async
2022-09-06 16:06:06 -04:00
Matt Corallo
ee2f1a929e
Merge pull request #1695 from TheBlueMatt/2022-08-log-chan_update
Ensure we log private channel_updates at a non-GOSSIP log level
2022-09-06 19:15:05 +00:00
Matt Corallo
602cf5c12b Ensure we log private channel_updates at a non-GOSSIP log level
If we receive a channel_update for one of our private channels, we
will not log the message at the usual TRACE log level as the
message falls into the gossip range. However, for our own channels
they aren't *just* gossip, as we store that info and it changes
how we generate invoices. Thus, we add a log in `ChannelManager`
here at the DEBUG log level.
2022-09-06 17:49:40 +00:00
Matt Corallo
c6890cfc33 Add a Future which can receive manager persistence events
This allows users who don't wish to block a full thread to receive
persistence events.

The `Future` added here is really just a trivial list of callbacks,
but from that we can build a (somewhat ineffecient)
std::future::Future implementation and can (at least once a mapping
for Box<dyn Trait> is added) include the future in no-std bindings
as well.

Fixes #1595
2022-09-06 17:42:21 +00:00
Matt Corallo
2035cebe8a Remove internal references to persistence in waker.rs 2022-09-06 16:22:58 +00:00
Matt Corallo
c8ae6c1923 Move open_zero_conf_channel utility to common test utils 2022-09-02 21:29:32 +00:00
Valentine Wallace
b9b02b48fb
Refuse to send and forward OMs to disconnected peers
We also refuse to connect to peers that don't advertise onion message
forwarding support.
2022-09-02 16:27:30 -04:00
Valentine Wallace
f4834def9d
Implement buffering onion messages for peers.
In this commit, we check if a peer's outbound buffer has room for onion
messages, and if so pulls them from an implementer of a new trait,
OnionMessageProvider.

Makes sure channel messages are prioritized over OMs, and OMs are prioritized
over gossip.

The onion_message module remains private until further rate limiting is added.
2022-08-26 19:03:07 -04:00
Valentine Wallace
544f72b37c
PeerManager: bump the read pause limit
...to make sure we can still get channel messages out after enqueuing some big gossip messages.
2022-08-26 19:03:05 -04:00
Valentine Wallace
4adff1039f
Add boilerplate for sending and receiving onion messages in PeerManager
Adds the boilerplate needed for PeerManager and OnionMessenger to work
together, with some corresponding docs and misc updates mostly due to the
PeerManager public API changing.
2022-08-26 19:02:59 -04:00
Matt Corallo
2358b0b05f
Merge pull request #1683 from valentinewallace/2022-08-multiqueue-peerman 2022-08-25 21:30:15 +00:00
Valentine Wallace
47e818f198
Separate gossip broadcasts into their own queue in PeerManager
This allows us to better prioritize channel messages over gossip broadcasts and
lays groundwork for rate limiting onion messages more simply, since they won't
be competing with gossip broadcasts for space in the main message queue.
2022-08-25 14:57:43 -04:00
Valentine Wallace
ab149dc9d5
PeerMan: rename drop_gossip util to be more accurate
It's more accurate to name it as dropping gossip broadcasts, as it won't drop
all gossip.
2022-08-25 14:57:43 -04:00
Valentine Wallace
1de698fdd9
PeerMan: fix bug in drop_gossip util
Fixes a flipped bool that was introduced in
4a1ee5f9a9
2022-08-25 14:56:50 -04:00
Matt Corallo
39cede60d0 Rename MaybeClaimableHTLCAwaitingTimeout for consistency
As we now have a MaybePreimageClaimableHTLC, its more consistent
to rename `MaybeClaimableHTLCAwaitingTimeout` to
`MaybeTimeoutClaimableHTLC`.
2022-08-25 18:51:42 +00:00
Matt Corallo
4c9231371b Expose a Balance for inbound HTLCs even without a preimage
If we don't currently have the preimage for an inbound HTLC, that
does not guarantee we can never claim it, but instead only that we
cannot claim it unless we receive the preimage from the channel we
forwarded the channel out on.

Thus, we cannot consider a channel to have no claimable balances if
the only remaining output on the commitment ransaction is an
inbound HTLC for which we do not have the preimage, as we may be
able to claim it in the future.

This commit addresses this issue by adding a new `Balance` variant
- `MaybePreimageClaimableHTLCAwaitingTimeout`, which is generated
until the HTLC output is spent.

Fixes #1620
2022-08-25 18:51:42 +00:00
Matt Corallo
dc54c583de
Merge pull request #1495 from TheBlueMatt/2022-04-all-claimables
Expose counterparty-revoked-outputs in `get_claimable_balance`
2022-08-17 22:50:49 +00:00
Matt Corallo
12687d75d5
Merge pull request #1660 from TheBlueMatt/2022-08-cleanup-ratelimits
Backfill gossip without buffering directly in LDK
2022-08-16 04:43:02 +00:00
Matt Corallo
5a8ede09fb Expose counterparty-revoked-outputs in get_claimable_balance
This uses the various new tracking added in the prior commits to
expose a new `Balance` type - `CounterpartyRevokedOutputClaimable`.

Some nontrivial work is required, however, as we now have to track
HTLC outputs as spendable in a transaction that comes *after* an
HTLC-Success/HTLC-Timeout transaction, which we previously didn't
need to do. Thus, we have to check if an
`onchain_events_awaiting_threshold_conf` event spends a commitment
transaction's HTLC output while walking events. Further, because
we now need to track HTLC outputs after the
HTLC-Success/HTLC-Timeout confirms, and because we have to track
the counterparty's `to_self` output as a contentious output which
could be claimed by either party, we have to examine the
`OnchainTxHandler`'s set of outputs to spend when determining if
certain outputs are still spendable.

Two new tests are added which test various different transaction
formats, and hopefully provide good test coverage of the various
revoked output paths.
2022-08-16 01:06:00 +00:00
Matt Corallo
8ffaacb3c3 Drop uneccessary if {...; bool} pattern in PeerManager 2022-08-16 00:52:44 +00:00
Matt Corallo
e76ac33330 Fix off-by-one in test_onchain_htlc_claim_reorg_remote_commitment
The test intended to disconnect a transaction previously connected
but didn't disconnect enough blocks to do so, leading to it
confirming two conflicting transactions.

In the next few commits this will become an assertion failure.
2022-08-15 23:18:12 +00:00
Matt Corallo
7717fa23a8 Backfill gossip without buffering directly in LDK
Instead of backfilling gossip by buffering (up to) ten messages at
a time, only buffer one message at a time, as the peers' outbound
socket buffer drains. This moves the outbound backfill messages out
of `PeerHandler` and into the operating system buffer, where it
arguably belongs.

Not buffering causes us to walk the gossip B-Trees somewhat more
often, but avoids allocating vecs for the responses. While its
probably (without having benchmarked it) a net performance loss, it
simplifies buffer tracking and leaves us with more room to play
with the buffer sizing constants as we add onion message forwarding
which is an important win.

Note that because we change how often we check if we're out of
messages to send before pinging, we slightly change how many
messages are exchanged at once, impacting the
`test_do_attempt_write_data` constants.
2022-08-15 21:35:05 +00:00
valentinewallace
ca4e31d751
Merge pull request #1659 from valentinewallace/2022-08-fix-payload-decode
Fix payment onion payload decode
2022-08-15 14:32:47 -04:00
Valentine Wallace
dfbebbf4c3
Rename HighZeroBytesDroppedVarInt to HighZeroBytesDroppedBigSize
As observed by @wpaulino, this struct encodes its bytes as big-endian,
therefore it's a BigSize, not a VarInt.
2022-08-15 11:41:59 -04:00
Valentine Wallace
a23681fde1
Fix bug in onion payment payload decode
Prior to this change, we could have failed to decode a valid payload of size
>253. This is because we were decoding the length (a BigSize, big-endian) as a
VarInt (little-endian).

Found in #1652.
2022-08-15 11:41:56 -04:00
Matt Corallo
47e9ca15b2 Rename PersistenceNotifier to simply Notifier
... as it is no longer persistence-specific (though still only used
for persistence).
2022-08-12 23:55:28 +00:00
Devrandom
11166aa836 Modify ecdh to take Scalar 2022-08-11 00:21:26 +02:00
Devrandom
7e05623bef Update bitcoin crate to 0.29.0 2022-08-11 00:21:26 +02:00
Matt Corallo
4f6da92c4e Clarify comment on BUFFER_DRAIN_MSGS_PER_TICK. 2022-08-10 19:29:39 +00:00
Valentine Wallace
4a1ee5f9a9 Use util methods in Peer to decide when to forward
This consolidates our various checks on peer buffer space into the
`Peer` impl itself, making the thresholds at which we stop taking
various actions on a peer more readable as a whole.

This commit was primarily authored by `Valentine Wallace
<vwallace@protonmail.com>` with some amendments by `Matt Corallo
<git@bluematt.me>`.
2022-08-10 19:29:39 +00:00
Matt Corallo
68b3d2e453 Move PersistenceNotifier to a new util module
It was always somewhat strange to have a bunch of notification
logic in `channelmanager`, and with the next commit adding a bunch
more, its moved here first.
2022-08-09 06:06:18 +00:00
Valentine Wallace
dcef41d17b
Minor msgs::OnionHopData cleanups 2022-08-05 22:34:36 -04:00
Matt Corallo
b4521f52e2
Merge pull request #1638 from ViktorTigerstrom/2022-07-update-decode-update-add-htlc-onion-return-parameters
Don't return `channel_state` from `decode_update_add_htlc_onion`
2022-08-03 17:44:46 +00:00
Matt Corallo
736c0b9e7f
Merge pull request #1619 from G8XSU/main
Add config support for 'their_channel_reserve_proportional_millionths' [#1498]
2022-08-03 17:37:51 +00:00
Matt Corallo
28c9b56113
Merge pull request #1503 from valentinewallace/2022-05-onion-msgs
Onion messages v1
2022-08-03 04:39:56 +00:00
Valentine Wallace
17ec697f8f
Fix possible incomplete read bug on onion packet decode
Pre-existing to this PR, we were reading next packet bytes with io::Read::read,
which is not guaranteed to read all the bytes we need, only guaranteed to read
*some* bytes.

We fix this to be read_exact, which is guaranteed to read all the next hop
packet bytes.
2022-08-02 19:19:39 -04:00
Valentine Wallace
bf007ea763
Implement receiving and forwarding onion messages
This required adapting `onion_utils::decode_next_hop` to work for both payments
and onion messages.

Currently we just print out the path_id of any onion messages we receive. In
the future, these received onion messages will be redirected to their
respective handlers: i.e. an invoice_request will go to an InvoiceHandler,
custom onion messages will go to a custom handler, etc.
2022-08-02 19:19:37 -04:00