Commit graph

5545 commits

Author SHA1 Message Date
Matt Corallo
60ce627b23 Remove spurious double comma in documentation 2023-06-06 00:44:06 +00:00
Matt Corallo
632c0d22b5 Remove spurious docs which imply you cannot retry a failed payment
If a payment (fully) fails, users are free to retry it, its only
once a payment succeeds that a user must never retry it.
2023-06-05 23:53:45 +00:00
Jeffrey Czyz
486c16a26d
Merge pull request #2290 from upjohnc/2240_replace_vectors_with_iterators
Set return type to Iterator for functions in file: `lightning-invoice/src/utils.rs` : issue #2240
2023-06-05 13:43:46 -05:00
Matt Corallo
166f32621d
Merge pull request #2329 from dunxen/2023-05-initgenesischeck
Add support for `networks` field in `Init` message
2023-06-05 18:14:17 +00:00
Duncan Dean
b52b936bdd
Send and handle networks field in Init messages
If the `networks` field is present in a received `Init` message, then
we need to make sure our genesis chain hash matches one of those, otherwise
we should disconnect the peer.

We now also always send our genesis chain hash in `Init` messages to
our peers.
2023-06-05 09:45:48 +02:00
Duncan Dean
e23102f565
Add networks TLV to Init's TLV stream
This was a fairly old introduction to the spec to allow nodes to indicate
to their peers what chains they are interested in (i.e. will open channels
and gossip for).

We don't do any of the handling of this message in this commit and leave
that to the very next commit, so the behaviour is effectively the same
(ignore networks preference).
2023-06-05 09:45:41 +02:00
Jeffrey Czyz
ede06d84de
Merge pull request #2332 from danielgranhao/fix/wrong-docs-link-channel-manager-send-payment
Fix wrong link in `ChannelManager::send_payment()` docs
2023-06-02 15:47:51 -05:00
Jeffrey Czyz
b6bb32ce14
Remove duplicate BOLT 12 test vector 2023-06-02 14:20:30 -05:00
Daniel Granhão
490ab6e453
Fix wrong link in ChannelManager::send_payment() docs 2023-06-02 17:29:52 +01:00
Matt Corallo
fb140b55c7
Merge pull request #2328 from benthecarman/partial-eq-in-mem-signer
Impl PartialEq and Debug for InMemorySigner
2023-06-01 19:51:24 +00:00
Chad Upjohn
ec67ee7020 Refactor lightning-invoice/src/utils.rs to yield iterators
- two functions refatored: `select_phantom_hints`, `sort_and_filter_channels`
2023-06-01 14:45:38 -05:00
benthecarman
a8a7fc1092
Impl PartialEq and Debug for InMemorySigner
These are needed for being able to compare a
ChannelMonitor<InMemorySigner> and are just nice to haves for
developers.
2023-05-31 18:19:31 -05:00
Matt Corallo
32eb89474c
Merge pull request #2167 from TheBlueMatt/2023-04-monitor-e-monitor-prep
Add infra to block ChannelMonitorUpdates on forwarded claims
2023-05-31 22:48:34 +00:00
Matt Corallo
91536edb0d
Merge pull request #2324 from dunxen/2023-05-rgscheckgenesishash
Fail RGS data processing early if there is a chain hash mismatch
2023-05-31 19:21:10 +00:00
Chad Upjohn
31807bc2f6 Adding rotate_through_iterators for select_phantom_hints refactor
- adding function to allow for select_phantom_hints to yield an iterator
2023-05-31 11:46:08 -05:00
Matt Corallo
394f54da31 Add infra to block ChannelMonitorUpdates on forwarded claims
When we forward a payment and receive an `update_fulfill_htlc`
message from the downstream channel, we immediately claim the HTLC
on the upstream channel, before even doing a `commitment_signed`
dance on the downstream channel. This implies that our
`ChannelMonitorUpdate`s "go out" in the right order - first we
ensure we'll get our money by writing the preimage down, then we
write the update that resolves giving money on the downstream node.

This is safe as long as `ChannelMonitorUpdate`s complete in the
order in which they are generated, but of course looking forward we
want to support asynchronous updates, which may complete in any
order.

Here we add infrastructure to handle downstream
`ChannelMonitorUpdate`s which are blocked on an upstream
preimage-containing one. We don't yet actually do the blocking which
will come in a future commit.
2023-05-30 23:05:03 +00:00
Matt Corallo
785bdb84cb Reapply pending ChannelMonitorUpdates on startup
If a `ChannelMonitorUpdate` was created and given to the user but
left uncompleted when the `ChannelManager` is persisted prior to a
restart, the user likely lost the `ChannelMonitorUpdate`(s). Thus,
we need to replay them for the user, which we do here using the
new `BackgroundEvent::MonitorUpdateRegeneratedOnStartup` variant.
2023-05-30 23:05:03 +00:00
Matt Corallo
e5070c4880 Process background events when taking the total_consistency_lock
When we generated a `ChannelMonitorUpdate` during `ChannelManager`
deserialization, we must ensure that it gets processed before any
other `ChannelMonitorUpdate`s. The obvious hook for this is when
taking the `total_consistency_lock`, which makes it unlikely we'll
regress by forgetting this.

Here we add that call in the `PersistenceNotifierGuard`, with a
test-only atomic bool to test that this criteria is met.
2023-05-30 23:05:02 +00:00
Matt Corallo
acbe41abe2 Handle BackgroundEvents replaying non-closing monitor updates
`BackgroundEvent` was used to store `ChannelMonitorUpdate`s which
result in a channel force-close, avoiding relying on
`ChannelMonitor`s having been loaded while `ChannelManager`
block-connection methods are called during startup.

In the coming commit(s) we'll also generate non-channel-closing
`ChannelMonitorUpdate`s during startup, which will need to be
replayed prior to any other `ChannelMonitorUpdate`s generated from
normal operation.

In the next commit we'll handle that by handling `BackgroundEvent`s
immediately after locking the `total_consistency_lock`.
2023-05-30 23:00:59 +00:00
Matt Corallo
eec5ec6b50
Merge pull request #2293 from wpaulino/disconnect-peers-timer-tick
Disconnect peers on timer ticks to unblock channel state machine
2023-05-30 18:30:49 +00:00
Matt Corallo
a2989129a7 Make AChannelManager trait slightly more generic and always on
Rather than letting `AChannelManager` be bounded by all traits
being `Sized` we make them explicitly `?Sized`. We also make the
trait no longer test-only as it will be used in a coming commit.
2023-05-30 18:15:32 +00:00
Matt Corallo
34d5f2afc4 Return the counterparty node_id as a part of a force-shutdown res
In the coming commits we'll need the counterparty node_id when
handling a background monitor update as we may need to resume
normal channel operation as a result. Thus, we go ahead and pipe it
through from the shutdown end, as it makes the codepaths
consistent.

Sadly, the monitor-originated shutdown case doesn't allow for a
required counterparty node_id as some versions of LDK didn't have
it present in the ChannelMonitor.
2023-05-30 18:15:32 +00:00
Matt Corallo
3ce1a5e087 Move the ShutdownResult type alias to channel.rs
This allows us to make the `force_shutdown` definition less verbose
2023-05-30 18:15:32 +00:00
Matt Corallo
660daaacdf Fix held_by_thread in no-std to return instead of panicing
Our `no-std` locks simply panic if a lock cannot be taken as there
should be no lock contention in a single-threaded environment.
However, the `held_by_thread` debug methods were delegating to the
lock methods which resulted in a panic when asserting that a lock
*is* held by the current thread.

Instead, they are updated here to call the relevant `RefCell`
testing methods.
2023-05-30 18:15:32 +00:00
Matt Corallo
a9d49aee5f
Merge pull request #2323 from ariard/2023-05-remove-ariard-pgp-key
Remove ariard key from the security team
2023-05-29 22:18:42 +00:00
Duncan Dean
142fdca66e
Fail RGS data processing early if there is a chain hash mismatch
No point in doing any extra processing if we don't even have a match
for the chain hash.
2023-05-29 16:15:42 +02:00
Antoine Riard
34322e1fad Remove ariard key from the security team 2023-05-28 20:58:06 +01:00
Alec Chen
749ae12e22
Allow user to opt-in to accepting MPP keysend
To support receiving MPP keysends, we will add a new non-backward
compatible field to `PendingHTLCRouting::ReceiveKeysend`, which will
break deserialization of `ChannelManager` on downgrades, so we allow the
user choose whether they want to do this. Note that this commit only
adds the config flag, while full MPP support is added in later commits.
2023-05-27 22:36:09 -05:00
Wilmer Paulino
5bf7fac69f
Disconnect peers on timer ticks to unblock channel state machine
At times, we've noticed that channels with `lnd` counterparties do not
receive messages we expect to in a timely manner (or at all) after
sending them a `ChannelReestablish` upon reconnection, or a
`CommitmentSigned` message. This can block the channel state machine
from making progress, eventually leading to force closes, if any pending
HTLCs are committed and their expiration is met.

It seems common wisdom for `lnd` node operators to periodically restart
their node/reconnect to their peers, allowing them to start from a fresh
state such that the message we expect to receive hopefully gets sent. We
can achieve the same end result by disconnecting peers ourselves
(regardless of whether they're a `lnd` node), which we opt to implement
here by awaiting their response within two timer ticks.
2023-05-26 14:40:19 -07:00
Wilmer Paulino
5ba2f8091f
Add new DisconnectPeerWithWarning variant to ErrorAction 2023-05-26 14:40:18 -07:00
Wilmer Paulino
6d4f105536
Remove unreachable warning message send on UnknownRequiredFeature read
`enqueue_message` simply adds the message to the outbound queue, it
still needs to be written to the socket with `do_attempt_write_data`.
However, since we immediately return an error causing the socket to be
closed, the message never actually gets sent.
2023-05-26 14:40:17 -07:00
Wilmer Paulino
55a7a03248
Implement enqueue_message trait requirements on Message enum
The inner structs of each enum variant already implemented them and we
plan to pass in `Message`s to `enqueue_message` in a future commit.
2023-05-26 14:40:14 -07:00
Wilmer Paulino
4dce209e97
Merge pull request #2316 from benthecarman/payment-err-dervies
Derive a PartialEq and Eq for PaymentError
2023-05-25 09:41:59 -07:00
benthecarman
3003f7d719
Derive a PartialEq and Eq for PaymentError
This lets users compare error types more easily without needing a match
statement.
2023-05-24 17:40:48 -05:00
Wilmer Paulino
64c58a565b
Merge pull request #2280 from TheBlueMatt/2023-05-event-deadlock
Never block a thread on the `PeerManager` event handling lock
2023-05-24 10:51:16 -07:00
Matt Corallo
0c034e9a82 Never block a thread on the PeerManager event handling lock
If thre's a thread currently handling `PeerManager` events, the
next thread which attempts to handle events will block on the first
and then handle events after the first completes. (later threads
will return immediately to avoid blocking more than one thread).

This works fine as long as the user has a spare thread to leave
blocked, but if they don't (e.g. are running with a single-threaded
tokio runtime) this can lead to a full deadlock.

Instead, here, we never block waiting on another event processing
thread, returning immediately after signaling that the first thread
should start over once its complete to ensure all events are
handled.

While this could lead to starvation as we cause one thread to go
around and around and around again, the risk of that should be
relatively low as event handling should be pretty quick, and it's
certainly better than deadlocking.

Fixes https://github.com/lightningdevkit/rapid-gossip-sync-server/issues/32

Atomic lock simplification suggestion from @andrei-21
2023-05-24 02:39:37 +00:00
Matt Corallo
7f3701a399
Merge pull request #2284 from dunxen/2023-05-netgraphpartialeqtotallock
Use a total lockorder for `NetworkGraph`'s `PartialEq` impl
2023-05-24 00:14:25 +00:00
Duncan Dean
6418a86e51
Use a total lockorder for NetworkGraph's PartialEq impl
`NetworkGraph`'s `PartialEq` impl before this commit was deadlock-prone.
Similarly to `ChannelMonitor`'s, `PartialEq` impl, we use position in
memory for a total lockorder. This uses the assumption that the objects
cannot move within memory while the inner locks are held.
2023-05-23 22:51:22 +02:00
Matt Corallo
b09ccd10be Consider HTLC in-flight count limits when assembling a route
When calculating the amount available to send for the next HTLC, if
we over-count we may create routes which are not actually usable.

Historically this has been an issue, which we resolve over a few
commits.

Here we consider the number of in-flight HTLCs which we are allowed
to push towards a counterparty at once, setting the available
balance to zero if we cannot push any further HTLCs.

We also add some testing when sending to ensure that send failures
are accounted for in our balance calculations.
2023-05-21 19:05:22 +00:00
Gleb Naumenko
e43cfbd5f1 Consider commitment tx fee while assembling a route
When calculating the amount available to send for the next HTLC, if
we over-count we may create routes which are not actually usable.

Historically this has been an issue, which we resolve over a few
commits.

Here we include the cost of the commitment transaction fee in our
calculation, subtracting the commitment tx fee cost from the
available as we do in `send_payment`.

We also add some testing when sending to ensure that send failures
are accounted for in our balance calculations.

This commit is based on original work by
Gleb Naumenko <naumenko.gs@gmail.com> and modified by
Matt Corallo <git@bluematt.me>.
2023-05-21 19:05:22 +00:00
Matt Corallo
4b900b7e08 Simplify test_fail_holding_cell_htlc_upon_free_multihop somewhat
In the coming commits we redo our next-HTLC-available logic which
requires some minor test changes for tests which relied on
calculating routes which were not usable.

Here we do a minor prefactor to simplify a test which now no longer
requires later changes.
2023-05-21 19:05:22 +00:00
Matt Corallo
2290141ed9 Disallow sending an HTLC when the balance needed is pending removal
While its nice to be able to push an HTLC which spends balance that
is removed in our local commitment transaction but awaiting an RAA
from our peer for final removal its by no means a critical feature.

Because peers should really be sending RAAs quickly after we send
a commitment, this should be an exceedingly rare case, and we
already don't expose this as available balance when routing, so
this isn't even made available when sending, only forwarding.

Note that `test_pending_claimed_htlc_no_balance_underflow` is
removed as it tested a case which was only possible because of this
and now is no longer possible.
2023-05-21 19:05:22 +00:00
Matt Corallo
6775b957bc
Merge pull request #2272 from benthecarman/package-broadcast
Support broadcasting multiple transactions at once
2023-05-21 01:53:35 +00:00
Matt Corallo
bada71394e
Merge pull request #2235 from TheBlueMatt/2023-04-criterion
Replace std's unmaintained bench with criterion
2023-05-20 23:02:44 +00:00
Matt Corallo
6aca7e1c4d
Merge pull request #2226 from alecchendev/2023-04-persist-network-graph-on-rgs
Update BP `NetworkGraph` and `Scorer` persist frequency
2023-05-20 22:55:43 +00:00
Matt Corallo
498f233145
Merge pull request #2204 from jkczyz/2023-04-custom-feature-bits
Support for custom feature bits
2023-05-18 19:28:19 +00:00
Matt Corallo
78663947a8
Merge pull request #1841 from ariard/2022-11-revoked-balance-non-aggregable
Post-anchor: do not aggregate claim of revoked output
2023-05-18 19:24:55 +00:00
Valentine Wallace
88821cbd0c
Rename EffectiveCapacity::MaximumHTLC to ::AdvertisedMaxHTLC
Also get rid of some trailing whitespace because my text editor likes to do
that.

We'll next add a new variant for max_htlc provided in route hints, which will
be treated differently in scoring.
2023-05-17 18:43:56 -04:00
Antoine Riard
5e968ed107 Remove aggregable flag from PackageTemplate constructor 2023-05-16 23:02:03 +01:00
Antoine Riard
b9aa902e51 Anchor: do not aggregate claim of revoked output
See https://github.com/lightning/bolts/pull/803

This protect the justice claim of counterparty revoked output. As
otherwise if the all the revoked outputs claims are batched in a
single transaction, low-feerate HTLCs transactions can delay our
honest justice claim transaction until BREAKDOWN_TIMEOUT expires.
2023-05-16 01:51:48 +01:00