Commit graph

4246 commits

Author SHA1 Message Date
Devrandom
e6b9694498 Re-add support for non-zero-fee-anchors to chan_utils and InMemorySigner 2022-11-22 12:28:51 +01:00
Matt Corallo
8245128c05
Merge pull request #1859 from TheBlueMatt/2022-11-rm-redundant-holding-cell-wipe
Wait to free the holding cell during channel_reestablish handling
2022-11-22 01:07:03 +00:00
Matt Corallo
32fdeb7b4e
Merge pull request #1772 from ViktorTigerstrom/2022-10-move-claimable-htlcs-to-seperate-lock
Move `claimable_htlcs` to separate lock
2022-11-22 01:06:29 +00:00
Viktor Tigerström
782eb3658f Don't hold per_peer_state lock during chain monitor update
For Windows build only, the
`TestPersister::chain_sync_monitor_persistences` lock has a lock order
before the `ChannelManager::per_peer_state` lock. This fix ensures that
the `per_peer_state` lock isn't held before the
`TestPersister::chain_sync_monitor_persistences` lock is acquired.
2022-11-21 21:49:21 +01:00
Viktor Tigerström
6b12117782 Lock pending inbound and outbound payments to before channel_state
As the `channel_state` lock will be removed, we prepare for that by
flipping the lock order for `pending_inbound_payments` and
`pending_outbound_payments` locks to before the `channel_state` lock.
2022-11-21 21:49:21 +01:00
Viktor Tigerström
f0c6dfbd80 Move claimable_htlcs to separate lock 2022-11-21 21:49:21 +01:00
Matt Corallo
a4c4301730
Merge pull request #1830 from jurvis/jurvis/2022-10-calculate-inflight-with-chanmanager
Calculate `InFlightHtlcs` based on information in `ChannelManager`
2022-11-21 19:32:58 +00:00
Matt Corallo
e82cfa7d84 Remove the post_handle_chan_restoration macro
Now that `handle_channel_resumption` can't fail, the error handling
in `post_handle_chan_restoration` is now dead code. Removing it
makes `post_handle_chan_restoration` only a single block, so here
we simply remove the macro and inline the single block into the two
places the macro was used.
2022-11-21 18:43:48 +00:00
jurvis
3136d731ba
Remove pub visibility of InFlightHtlcs HashMap 2022-11-19 11:20:16 -08:00
jurvis
84ba180201
Add functional test for inflight HTLC tracking with ChanManager 2022-11-19 11:20:14 -08:00
jurvis
2e818131c4
Remove paths from PaymentInfo in payment_cache
In c70bd1f, we implemented tracking HTLCs by adding path information
for pending HTLCs to `InvoicePayer`’s `payment_cache` when receiving
specific events.

Since we can now track inflight HTLCs entirely within ChannelManager,
there is no longer a need for this to exist.
2022-11-19 11:19:25 -08:00
jurvis
89f162c168
Compute InflightHtlcs from available information in ChannelManager 2022-11-19 11:19:23 -08:00
Matt Corallo
d7d3b0ec75
Merge pull request #1846 from TheBlueMatt/2022-11-more-robust-unconfirmed
Handle `transaction_unconfirmed` as a full reorg to the tx height
2022-11-19 00:06:32 +00:00
Matt Corallo
087c0bdd87
Merge pull request #1852 from TheBlueMatt/2022-11-accept-bad-but-better-fee-updates
Accept feerate increases even if they aren't high enough for us
2022-11-18 20:50:27 +00:00
Matt Corallo
66d7b7ded0 Handle transaction_unconfirmed as a full reorg to the tx height
In `ChannelMonitor`, if we see a `transaction_unconfirmed` for a
transaction we last saw in a block at height X, we shouldn't
*only* remove the `onchain_events_awaiting_threshold_conf` entry
for the given tx but rather for all transactions that we last saw
at height >= X.

This avoids any potential `onchain_events_awaiting_threshold_conf`
inconsistencies due to the order in whcih users mark transactions
unconfirmed (which the `chain::Confirm` docs do not currently set
any requirements on).

This also matches the `OnchainTxHandler` behavior, which does the
same lookup.
2022-11-18 20:49:44 +00:00
Matt Corallo
8d93dba370
Merge pull request #1726 from jkczyz/2022-09-offer-parsing
BOLT 12 offer parsing
2022-11-18 19:46:51 +00:00
Jeffrey Czyz
1e26a2bc19
Expose the default Quantity::one as pub 2022-11-18 11:33:07 -06:00
Jeffrey Czyz
94a07d9cae
Limit TLV stream decoding to type ranges
BOLT 12 messages are limited to a range of TLV record types. Refactor
decode_tlv_stream into a decode_tlv_stream_range macro for limiting
which types are parsed. Requires a SeekReadable trait for rewinding when
a type outside of the range is seen. This allows for composing TLV
streams of different ranges.

Updates offer parsing accordingly and adds a test demonstrating failure
if a type outside of the range is included.
2022-11-18 11:33:07 -06:00
Jeffrey Czyz
03d0a4b497
Offer parsing tests
Test semantic errors when parsing offer bytes.
2022-11-18 11:33:07 -06:00
Jeffrey Czyz
3a6d7b867e
Use SemanticError in OfferBuilder::build 2022-11-18 11:33:06 -06:00
Jeffrey Czyz
60d7ffce10
Offer parsing from bech32 strings
Add common bech32 parsing for BOLT 12 messages. The encoding is similar
to bech32 only without a checksum and with support for continuing
messages across multiple parts.

Messages implementing Bech32Encode are parsed into a TLV stream, which
is converted to the desired message content while performing semantic
checks. Checking after conversion allows for more elaborate checks of
data composed of multiple TLV records and for more meaningful error
messages.

The parsed bytes are also saved to allow creating messages with mirrored
data, even if TLV records are unknown.
2022-11-18 11:33:06 -06:00
Matt Corallo
f1c6cd8b3e Convert the handle_chan_restoration_locked macro to a function
There is no reason anymore for `handle_chan_restoration_locked` to
be a macro, and our long-term desire is to move away from macros as
they substantially bloat our compilation time (and binary size).
Thus, we simply remove `handle_chan_restoration_locked` here and
turn it into a function.
2022-11-17 17:57:17 +00:00
Matt Corallo
7e9b88a5cd Wait to free the holding cell during channel_reestablish handling
When we process a `channel_reestablish` message we free the HTLC
update holding cell as things may have changed while we were
disconnected. However, some time ago, to handle freeing from the
holding cell when a monitor update completes, we added a holding
cell freeing check in `get_and_clear_pending_msg_events`. This
leaves the in-`channel_reestablish` holding cell clear redundant,
as doing it immediately or is `get_and_clear_pending_msg_events` is
not a user-visible difference.

Thus, we remove the redundant code here, substantially simplifying
`handle_chan_restoration_locked` while we're at it.
2022-11-17 17:57:17 +00:00
Matt Corallo
c8c0997862 Remove log assertions in chanmon_update_fail_tests
Asserting that specific log entries were printed isn't all that
useful, we should really be focusing on the expected messages (or,
when a monitor udpate fails, the lack thereof). In the next commit
one of these log checks would otherwise break due to the particular
time a monitor update fails changing, but I also plan on reworking
the montior update flows substantially soon, breaking lots of them.
2022-11-17 17:57:17 +00:00
jurvis
05290c2860
Unparameterize HashMap from InFlightHtlcs initializer 2022-11-16 17:49:29 -08:00
Matt Corallo
7269fa2024
Merge pull request #1855 from tnull/2022-11-inbound-user-channel-id-randomization-fixup
Inbound `user_channel_id` randomization follow-up
2022-11-16 20:46:30 +00:00
Elias Rohrer
7f6713c813
Remove unused import 2022-11-16 18:50:43 +01:00
Elias Rohrer
c72d630ada
Mention user_channel_id rand. version req.
As it was previously omitted, we clarify here starting from which version users can expect the `user_channel_id` to be randomized for inbound channels.
2022-11-16 18:50:43 +01:00
Elias Rohrer
38c5a7b2ac
Also set user_channel_id when its overridden 2022-11-16 18:50:40 +01:00
Matt Corallo
d6aa1bc85a
Merge pull request #1826 from TheBlueMatt/2022-10-idempotency-err
Add a separate PaymentSendFailure for idempotency violation
2022-11-16 17:42:23 +00:00
Matt Corallo
4006717f6f
Merge pull request #1853 from TheBlueMatt/2022-11-reload-macro
Replace manual node reloading with a macro/function in tests
2022-11-16 17:36:41 +00:00
Matt Corallo
4d914b5b36
Merge pull request #1851 from TheBlueMatt/2022-11-fix-broken-futures-----again
Unset the needs-notify bit in a Notifier when a Future is fetched
2022-11-16 17:34:37 +00:00
Matt Corallo
a1404aac63 Accept feerate increases even if they aren't high enough for us
LND nodes have very broken fee estimators, causing them to suggest
feerates that don't even meet a current mempool minimum feerate
when fees go up over the course of hours. This can cause us to
reject their feerate estimates as they're not high enough, even
though their new feerate is higher than what we had already (which
is the feerate we'll use to broadcast a closing transaction). This
implies we force-close the channel and broadcast something with a
feerate lower than our counterparty was offering.

Here we simply accept such feerates as they are better than what we
had. We really should also close the channel, but only after we
get their signature on the new feerate. That should happen by
checking channel feerates every time we see a new block so is
orthogonal to this code.

Ultimately the fix is anchor outputs plus package-based relay in
Bitcoin Core, however we're still quite some ways from that, so
worth needlessly closing channels for now.
2022-11-16 03:54:00 +00:00
Matt Corallo
0a1e48f9c7 Await Future::poll Completed before unsetting notify-required
When we mark a future as complete, if the user is using the
`std::future::Future` impl to get notified, we shouldn't just
assume we have completed the `Future` when we call the `Waker`. A
`Future` may have been `drop`'d at that point (or may not be
`poll`'d again) even though we wake the `Waker`.

Because we now have a `callbacks_made` flag, we can fix this rather
trivially, simply not setting the flag until the `Future` is
`poll`'d `Complete`.
2022-11-16 00:21:43 +00:00
Matt Corallo
5f053e43af Wipe Notifier FutureState when returning from a waiter.
When we return from one of the wait functions in `Notifier`, we
should also ensure that the next `Future` doesn't start in the
`complete` state, as we have already notified the user, as far as
we're concerned.

This is technically a regression from the previous commit, but as
it is a logically separate change it is in its own commit.
2022-11-16 00:21:43 +00:00
Matt Corallo
7527e4b7df Unset the needs-notify bit in a Notifier when a Future is fetched
If a `Notifier` gets `notify()`ed and the a `Future` is fetched,
even though the `Future` is marked completed from the start and
the user may pass callbacks which are called, we'll never wipe the
needs-notify bit in the `Notifier`.

The solution is to keep track of the `FutureState` in the returned
`Future` even though its `complete` from the start, adding a new
flag in the `FutureState` which indicates callbacks have been made
and checking that flag when waiting or returning a second `Future`.
2022-11-16 00:21:43 +00:00
Matt Corallo
bcf8687301 Remove excess module
This appears to have been added with the intent of having a sealed
trait, which was never committed.
2022-11-16 00:21:41 +00:00
Matt Corallo
97b210dd97 Move restart-related tests to their own file 2022-11-15 22:38:12 +00:00
Matt Corallo
e359c40143 Replace manual node reloading with a macro/function in tests
Fixes #1696
2022-11-15 22:38:11 +00:00
Matt Corallo
8d8ee55463
Merge pull request #1790 from tnull/2022-10-inbound-user-channel-id-randomization
Randomize `user_channel_id` for inbound channels
2022-11-15 22:35:17 +00:00
Elias Rohrer
dc3ff5489a
Make user_channel_id a u128
We increase the `user_channel_id` type from `u64` to `u128`. In order to
maintain backwards compatibility, we have to de-/serialize it as two
separate `u64`s in `Event` as well as in the `Channel` itself.
2022-11-15 20:41:09 +01:00
Elias Rohrer
b2f8df0b61
Randomize user_channel_id for inbound channels
Previously, all inbound channels defaulted to a `user_channel_id` of 0,
which didn't allow for them being discerned on that basis. Here, we
simply randomize the identifier to fix this and enable the use of
`user_channel_id` as a true identifier for channels (assuming an equally
reasonable value is chosen for outbound channels and given upon
`create_channel()`).
2022-11-15 15:10:38 +01:00
Elias Rohrer
aa10f6464e
Introduce init_and_read_tlv_fields macro
We introduce a new macro that inits and reads tlv fields and DRY up
`impl_writeable_tlv_based` and other macros.
2022-11-15 15:10:23 +01:00
Matt Corallo
838d486983
Merge pull request #1845 from TheBlueMatt/2022-11-future-wake-fix
Fix persistence-required futures always completing instantly
2022-11-11 06:09:03 +00:00
Matt Corallo
49c9f1885d
Merge pull request #1806 from arik-so/2022-10-background-processor-deparametrization
Remove generic `Signer` parameter where it can be inferred from `KeysInterface`
2022-11-11 06:08:51 +00:00
Matt Corallo
f382f56cbb Fix persistence-required futures always completing instantly
After the first persistence-required `Future` wakeup, we'll always
complete additional futures instantly as we don't clear the
"need wake" bit. Instead, we need to just assume that if a future
was generated (and not immediately drop'd) that its sufficient to
notify the user.
2022-11-11 02:03:52 +00:00
Matt Corallo
593d8c4610
Merge pull request #1413 from ViktorTigerstrom/2022-04-default-to-bolt4-tlv-onions
Drop support for creating BOLT 4 Legacy onion format payloads
2022-11-11 00:49:45 +00:00
Viktor Tigerström
3ecc5aee4a Add test for only creating tlv format onions 2022-11-10 23:34:25 +01:00
Viktor Tigerström
f4e6d4a653 Remove OnionHopDataFormat::Legacy 2022-11-10 23:34:25 +01:00
Viktor Tigerström
7a50154d87 Update BOLT4 onion test vectors 2022-11-10 23:34:25 +01:00