Commit graph

5255 commits

Author SHA1 Message Date
Matt Corallo
a1b5a1bba3 Add CondVar::wait_{timeout_,}while to debug_sync
These are useful, but we previously couldn't use them due to our
MSRV. Now that we can, we should use them, so we expose them via
our normal debug_sync wrappers.
2023-04-03 16:49:54 +00:00
Lucas Soriano del Pino
beb1d9a2bd
Implement chain::Confirm without mandating any owned values 2023-04-03 21:12:44 +10:00
Matt Corallo
2fab8873f9 Correct lightning-net-tokio documentation, remove stale example
The `lightning-net-tokio` crate-level example contained a carryover
from when it was the primary notifier of the background processor
and now just shows an "example" of creating a method to call
another method with the same parameters and then do event
processing (which doesn't make sense, the BP should do that).

Instead, the examples are simply removed and the documentation is
tweaked to include recent changes.
2023-03-31 01:54:28 +00:00
Wilmer Paulino
0e28bcb704
Merge pull request #2141 from TheBlueMatt/2023-03-fuck-rust
Drop `futures` dependency from `lightning-block-sync`
2023-03-30 18:41:21 -07:00
Matt Corallo
491100d8e5 Remove futures dependency in lightning-background-processor
As `futures` apparently makes no guarantees on MSRVs even in patch
releases we really can't rely on it at all, and while it currently
has an acceptable MSRV without the macros feature, its best to just
remove it wholesale.

Luckily, removing it is relatively trivial, even if it requires
the most trivial of unsafe tags.
2023-03-31 00:05:24 +00:00
Matt Corallo
54a51f8554 Replace futures select with our own select enum to fix MSRV
`futures` recently broke our MSRV by bumping the `syn` major
version in a patch release. This makes it impractical for us to
use, instead here we replace the usage of its `select_biased` macro
with a trivial enum.

Given its simplicity we likely should have done this without ever
taking the dependency.
2023-03-31 00:01:40 +00:00
Matt Corallo
9a50e301cb Avoid connection-per-RPC-call again by caching connections
In general, only one request will be in flight at a time in
`lightning-block-sync`. Ideally we'd only have one connection, but
without using the `futures` mutex type.

Here we solve this narrowly for the one-request-at-a-time case by
caching the connection and takeing the connection out of the cache
while we work on it.
2023-03-30 22:28:26 +00:00
Matt Corallo
6b55df93fb Drop futures dependency from lightning-block-sync
Some how I'd understood that `futures` had reasonable MSRV
guarantees (e.g. at least Debian stable), but apparently that isn't
actually the case, as they bumped it to upgrade to syn (with
apparently no actual features or bugfixes added as a result?) with
no minor version bump or any available alternative (unlike Tokio,
which does LTS releases).

Luckily its relatively easy to just drop the `futures` dependency -
it means a new connection for each request, which is annoying, but
certainly not the end of the world, and its easier than trying to
deal with pinning `futures`.

See https://github.com/rust-lang/futures-rs/pull/2733
2023-03-30 18:56:27 +00:00
Matt Corallo
783e8188a7
Merge pull request #2136 from marctyndel/2023-03-paymentforwarded-expose-amount-forwarded
Expose amount forwarded in `PaymentForwarded` event
2023-03-30 18:15:23 +00:00
Matt Corallo
a9534fe6b5
Merge pull request #2059 from wpaulino/broadcast-missing-anchors-event
Queue BackgroundEvent to force close channels upon ChannelManager::read
2023-03-29 21:54:58 +00:00
Marc Tyndel
ee2cb8ef21 add outbound_amount_forwarded_msat field to PaymentForwarded event 2023-03-29 14:42:35 -04:00
valentinewallace
723c1a62ca
Merge pull request #2062 from alecchendev/2023-02-allow-overshoot-mpp
Allow overshooting final htlc amount and expiry
2023-03-29 11:37:51 -04:00
Wilmer Paulino
9fe475057a
Add pending changelog noting possible backwards compat panic 2023-03-28 17:27:51 -07:00
Wilmer Paulino
2166c8a2c4
Ignore lockorder violation on same callsite with different construction
As long as the lock order on such locks is still valid, we should allow
them regardless of whether they were constructed at the same location or
not. Note that we can only really enforce this if we require one lock
call per line, or if we have access to symbol columns (as we do on Linux
and macOS). We opt for a smaller patch by relying on the latter.

This was previously triggered by some recent test changes to
`test_manager_serialize_deserialize_inconsistent_monitor`. When the
test ends and a node is dropped causing us to persist each, we'd detect
a possible lockorder violation deadlock across three different `Mutex`
instances that are held at the same location when serializing our
`per_peer_states` in `ChannelManager::write`.

The presumed lockorder violation happens because the first `Mutex` held
shares the same construction location with the third one, while the
second `Mutex` has a different construction location. When we hold the
second one, we consider the first as a dependency, and then consider the
second as a dependency when holding the third, causing a circular
dependency (since the third shares the same construction location as the
first).

This isn't considered a lockorder violation that could result in a
deadlock as the comment suggests inline though, since we are under a
dependent write lock which no one else can have access to.
2023-03-28 17:27:47 -07:00
Arik
9fd6127ded
Merge pull request #2082 from wpaulino/bump-htlc-resolution-tx-locktime
Expose HTLC transaction locktime in BumpTransactionEvent::HTLCResolution
2023-03-28 17:14:59 -07:00
Alec Chen
1d31b0e84e Use onion amount amt_to_forward for MPP set calculation
If routing nodes take less fees and pay the final node more than
`amt_to_forward`, the receiver may see that `total_msat` has been met
before all of the sender's intended HTLCs have arrived. The receiver
may then prematurely claim the payment and release the payment hash,
allowing routing nodes to claim the remaining HTLCs. Using the onion
value `amt_to_forward` to determine when `total_msat` has been met
allows the sender to control the set total.
2023-03-28 17:21:09 -05:00
Alec Chen
ee57738ca8 Allow overshooting final cltv_expiry
Final nodes previously had stricter requirements on HTLC contents
matching onion value compared to intermediate nodes. This allowed
for probing, i.e. the last intermediate node could overshoot the
value by a small amount and conclude from the acceptance or rejection
of the HTLC whether the next node was the destination. This also
applies to the msat amount, however this change was already present.
2023-03-28 17:21:09 -05:00
Alec Chen
f3d8e58374 Allow overshooting total_msat for an MPP
While retrying a failed path of an MPP, a node may want to overshoot
the `total_msat` in order to use a path with an `htlc_minimum_msat`
greater than the remaining value being sent. This commit no longer
fails MPPs that overshoot the `total_msat`, however it does fail
HTLCs with the same payment hash that are received *after* a
payment has become claimable.
2023-03-28 17:21:09 -05:00
Alec Chen
b9f4ebdd28 Add total_value_received to ClaimableHTLC for claim validation
This is pre-work for allowing nodes to overshoot onion values and
changing validation for MPP completion. This adds a field to
`ClaimableHTLC` that is separate from the onion values, which
represents the actual received amount reported in `PaymentClaimable`
which is what we want to validate against when a user goes to claim.
2023-03-28 17:21:09 -05:00
Wilmer Paulino
23e233ba25
Expose HTLC transaction locktime in BumpTransactionEvent::HTLCResolution
While users could easily figure it out based on the set of HTLC
descriptors included within, we already track it within the
`OnchainTxHandler`, so we might as well expose it to users as a
nice-to-have. It's also yet another thing they must get right to ensure
their HTLC transaction broadcasts are valid.
2023-03-28 12:42:25 -07:00
Wilmer Paulino
68122bd09d
Set transaction locktime on malleable packages to discourage fee sniping
This only applies to all malleable packages on channels pre-dating
anchors and malleables packages for counterparty commitments
post-anchors. Malleables packages for holder commitments post-anchors
should have their transaction locktime applied manually by the consumer
of `BumpTransactionEvent::HTLCResolution` events.
2023-03-28 12:42:23 -07:00
Wilmer Paulino
2ac09711d3
Re-work PackageSolvingData::absolute_tx_timelock
Previously, this would return the earliest height the output could be
confirmed, which seems to no longer be useful. The only use of the
method was to determine whether we should delay a package to a future
block. Instead, we choose to return the absolute locktime the
transaction spending the output should have, which better corresponds to
the method name and still supports the delay functionality mentioned.

Doing so also allows us to expose the locktime required for HTLC
transactions we need to broadcast based on our own commitments for
anchor channels.
2023-03-28 12:15:54 -07:00
Wilmer Paulino
31e78ff258
Merge pull request #2133 from tnull/2023-03-pin-syn
Pin`tokio` to fix CI
2023-03-28 10:16:39 -07:00
Matt Corallo
369eea45a1
Merge pull request #2132 from tnull/2023-03-tx-sync-even-more-robustness
Drop `OnceCell` in `lightning-transaction-sync` tests
2023-03-28 16:42:44 +00:00
Matt Corallo
2d4bf974e5
Merge pull request #2083 from wpaulino/events-module
Move events.rs into its own top-level module
2023-03-28 16:37:55 +00:00
Elias Rohrer
143c0f80cb
Pin tokio to fix CI
Recently `tokio` got updated to 1.27.0, which bumped MSRV from 1.49 to
1.56.

Here we pin `tokio` accordingly to unbreak CI.
2023-03-28 17:40:08 +02:00
Elias Rohrer
7b85ebadb6
Remove unnecessary restriction on esplora-client version 2023-03-28 17:13:58 +02:00
Elias Rohrer
f75ad8021b
Move test bitcoind/electrsd out of OnceCell
`OnceCell` doesn't call `drop`, which makes the spawned
`bitcoind`/`electrsd` instances linger around after our tests have
finished. To fix this, we move them out of `OnceCell` and let every test
that needs them spawn their own instances. This additional let us drop
the `OnceCell` dev dependency.
2023-03-28 17:13:54 +02:00
Matt Corallo
3c02e507d6
Merge pull request #2125 from benthecarman/invoice-expire-time
Add helper functions for invoice expiry
2023-03-27 22:54:05 +00:00
benthecarman
56878595d7
Add helper functions for invoice expiry 2023-03-27 14:41:43 -05:00
Matt Corallo
2223e92ac6
Merge pull request #2110 from munjesi/docs_fixes
Replacing (C-not exported) in the docs
2023-03-27 18:12:00 +00:00
Jeffrey Czyz
dbf3d576b5
Merge pull request #2123 from benthecarman/create-inv-desc
Add generic InvoiceDescription to invoice in InvoiceBuilder
2023-03-24 15:00:10 -05:00
Matt Corallo
b72f6b1b84 Support future removal of redundant per-HTLC data in ChanMonUpds
`ChannelMonitorUpdate`s are our most size-sensitive objects - they
are the minimal objects which need to be written to disk on each
commitment update. Thus, we should be careful to ensure we don't
pack too much extraneous information into each one.

Here we add future support for removing the per-HTLC explicit
`Option<Signature>` and `HTLCInCommitmentUpdate` for non-dust HTLCs
in holder commitment tx updates, which are redundant with the
`HolderCommitmentTransaction`.

While we cannot remove them entirely as previous versions rely on
them, adding support for filling in the in-memory structures from
the redundant fields will let us remove them in a future version.

We also add test-only generation logic to test the new derivation.
2023-03-24 19:02:08 +00:00
benthecarman
18c3318b78
Add generic InvoiceDescription to invoice in InvoiceBuilder 2023-03-23 00:07:16 -05:00
Wilmer Paulino
174e16426a
Add new sub-module for BumpTransactionEvent
Its accompanying event handler will also live here.
2023-03-22 11:49:36 -07:00
Wilmer Paulino
ca9ca75f08
Move events.rs into its own top-level module
This is largely motivated by some follow-up work for anchors that will
introduce an event handler for `BumpTransaction` events, which we can
now include in this new top-level `events` module.
2023-03-22 11:49:33 -07:00
Jeffrey Czyz
3d479c9de6
Merge pull request #2114 from Evanfeenstra/force_close_msg_display
use PrintableString to Display CounterpartyForceClosed peer_msg
2023-03-22 12:32:22 -05:00
munjesi
b0bf50fa24 Replacing (C-not exported) in the docs 2023-03-22 14:30:36 +03:00
Evan Feenstra
987ab9512c SanitizedString struct to safely Display CounterpartyForceClosed peer_msg 2023-03-21 21:37:38 -07:00
Wilmer Paulino
04ee948643
Remove unused broadcast_latest_holder_commitment_txn method 2023-03-21 16:25:47 -07:00
Wilmer Paulino
00cfc6b823
Avoid refusing ChannelMonitorUpdates we expect to receive after closing
There is no need to fill the user's logs with errors that are expected
to be hit based on specific edge cases, like providing preimages after
a monitor has seen a confirmed commitment on-chain.

This doesn't really change our behavior – we still apply and persist the
state changes resulting from processing these updates regardless of
whether they succeed or not.
2023-03-21 16:25:47 -07:00
Wilmer Paulino
bd4eb0da76
Queue BackgroundEvent to force close channels upon ChannelManager::read
This results in a new, potentially redundant, `ChannelMonitorUpdate`
that must be applied to `ChannelMonitor`s to broadcast the holder's
latest commitment transaction.

This is a behavior change for anchor channels since their commitments
may require additional fees to be attached through a child anchor
transaction. Recall that anchor transactions are only generated by the
event consumer after processing a `BumpTransactionEvent::ChannelClose`
event, which is yielded after applying a
`ChannelMonitorUpdateStep::ChannelForceClosed` monitor update. Assuming
the node operator is not watching the mempool to generate these anchor
transactions without LDK, an anchor channel which we had to fail when
deserializing our `ChannelManager` would have its commitment transaction
broadcast by itself, potentially exposing the node operator to loss of
funds if the commitment transaction's fee is not enough to be accepted
into the network's mempools.
2023-03-21 16:25:46 -07:00
Wilmer Paulino
5a90f014f2
Use CLOSED_CHANNEL_UPDATE_ID in force closing ChannelMonitorUpdates
Currently, all that is required to force close a channel is to broadcast
either of the available commitment transactions, but this changes with
anchor outputs – commitment transactions may need to have
additional fees attached in order to confirm in a timely manner. While
we may be able to just queue a new update using the channel's next
available update ID, this may result in a violation of the
`ChannelMonitor` API (each update ID must strictly increase by 1) if the
channel had updates that were persisted by its `ChannelMonitor`, but not
the `ChannelManager`. Therefore, we choose to re-purpose the existing
`CLOSED_CHANNEL_UPDATE_ID` update ID to also apply to
`ChannelMonitorUpdate`s that will force close their respective channel
by broadcasting the holder's latest commitment transaction.
2023-03-21 16:25:45 -07:00
Matt Corallo
14ee173593
Merge pull request #2102 from douglaz/node_info_addresses
Remove NodeAnnouncementInfo addresses
2023-03-21 22:42:16 +00:00
Matt Corallo
9f8e832c7b
Merge pull request #2034 from wpaulino/anchor-revoked-aggregate-claim
Add test for aggregated revoked HTLC claim on anchors channel
2023-03-21 22:32:18 +00:00
Matt Corallo
ea15f0f448
Merge pull request #2100 from douglaz/docs_fixes
Docs improvements
2023-03-21 18:44:23 +00:00
Allan Douglas R. de Oliveira
6f5e5e3898 Remove redundant addresses field from NodeAnnouncementInfo
...replacing it with an acessor `addresses()`.

Besides removing a redundant data structure already present on inner
`NodeAnnouncement`, this change makes it possible to discover new address types
upon deserialization thanks to `UnsignedNodeAnnouncement`'s implementation.
2023-03-21 17:27:48 +00:00
Allan Douglas R. de Oliveira
963d6c4a51 Docs improvements 2023-03-21 14:11:13 +00:00
Wilmer Paulino
881656ba9e
Test anchors build in CI 2023-03-20 16:46:38 -07:00
Matt Corallo
85b573ddad Add an optional_vec TLV format which makes sense, unlike vec_type
`vec_type` is confusing - it is happy to have a missing entry,
"reading" an empty `Vec` instead, but always writes something,
making a serialization round-trip different.

This is a problem for writing a new `Vec` which is
backwards-incompatible, but only if filled in. In that case we'd
really like the same read behavior, but not write anything if the
`Vec` is empty. Here we introduce such semantics via a new
`optional_vec` TLV format.
2023-03-20 23:29:22 +00:00