Commit graph

6591 commits

Author SHA1 Message Date
Wilmer Paulino
9ab7a48ff1
Use clear helper on flags copy to mask off bits 2024-01-29 13:57:19 -08:00
Wilmer Paulino
e82dba5e94
Assert we never write channels in pre-funded/shutdown state 2024-01-10 18:29:01 -08:00
Wilmer Paulino
4ac2a04ec8
Check funding transaction on outbound channels only
This was a slight regression, but not a critical one. Only outbound
channels should have a funding transaction present.
2024-01-10 18:29:00 -08:00
Wilmer Paulino
12f06c3fff
Simplify ChannelState checks 2024-01-10 18:29:00 -08:00
Wilmer Paulino
178c9ee45b
Rename should_force_holding_cell to can_generate_new_commitment
This better reflects the intent behind the callsites of the method.
2024-01-10 18:28:59 -08:00
Wilmer Paulino
a6572442df
Add note and test regarding ChannelState's implicit ordering 2024-01-10 18:28:56 -08:00
Matt Corallo
db81c650ba
Merge pull request #2791 from valentinewallace/2023-12-multihop-recv-followups
Follow-ups to #2688
2024-01-11 00:04:39 +00:00
Matt Corallo
ccf710d860
Merge pull request #2809 from TheBlueMatt/2023-12-closing-event-cleanup-fixes
Clean Up Funding Error Handling and shutdown
2024-01-10 22:37:07 +00:00
Valentine Wallace
3ec4d52277
Rename parameter from err_packet to err_contents.
This name is more accurate since the method has been generalized to support
malformed HTLCs.
2024-01-10 11:23:44 -05:00
Valentine Wallace
c1fbb90847
Remove outdated comment. 2024-01-10 11:23:44 -05:00
Valentine Wallace
95b3ef4910
Normalize order of (sha256_of_onion, failure_code) in trait.
This helps avoid destructuring the tuple.
2024-01-10 11:23:44 -05:00
Valentine Wallace
04e70bad0a
DRY malformed HTLC handling during htlc batch processing. 2024-01-10 11:23:44 -05:00
Valentine Wallace
5c880a0549
Fix logger usage during batched htlc processing of malforms.
Introduced due to a rebase error.
2024-01-10 11:23:44 -05:00
Valentine Wallace
d0d1634d95
Clean up code DRY'd in previous commit. 2024-01-10 11:19:09 -05:00
Matt Corallo
f352d03ee9
Merge pull request #2748 from TheBlueMatt/2023-11-2675-followups
Doc and style followups from #2675
2024-01-09 23:22:48 +00:00
Matt Corallo
3b6d6937bb Update docs on HTLC and DelayedPayment keys for clarity
This also adds required linebreaks to keep the docs to a reasonable
width.
2024-01-09 22:24:59 +00:00
Matt Corallo
c5e3f5fa82 Drop the unused PaymentKey type
935a716cc6 added new wrappers for the
various channel keys, including a payment_key. However, the
`payment_key` has been unused in lightning since the introduction
(and broad requiring) of the `static_remotekey` feature.

Thus, we simply remove it (and an incredibly stale TODO) here.
2024-01-09 22:24:59 +00:00
Matt Corallo
bc273a2939 Update docs for slightly more clarity on channel key derivation 2024-01-09 22:24:59 +00:00
Matt Corallo
52c225351b
Merge pull request #2807 from Jossec101/log-errors-do-accept-inbound-channel
Log the errors before we return them from ChannelManager::do_accept_inbound_channel
2024-01-09 20:08:25 +00:00
Matt Corallo
0d513fd6e5
Merge pull request #2817 from tnull/2024-01-time-in-electrum
Feature-gate `time` use also in `ElectrumSyncClient`
2024-01-09 16:57:16 +00:00
José A.P
dbe69ba3f0 Improved error logging in ChannelManager::do_accept_inbound_channel
This refactor ensures that all API errors in do_accept_inbound_channel
are logged before they are returned.
2024-01-09 11:26:14 +01:00
Elias Rohrer
2bd12137a4
Feature-gate time use also in ElectrumSyncClient
A previous commit introduced the `time` feature to gate the use of
`SystemTime` dependent APIs in `EsploraSyncClient`. It however omitted
doing the same for the Electrum side of things. Here, we address this
oversight.
2024-01-09 09:37:14 +01:00
Matt Corallo
78ac48ca9e
Merge pull request #2802 from TheBlueMatt/2023-12-no-pub-enum
Move `CandidateRouteHop` enum variant fields into structs
2024-01-08 21:33:00 +00:00
Matt Corallo
3fbee852b3
Merge pull request #2808 from TheBlueMatt/2023-12-fuzzing-fixes-1 2024-01-08 20:58:30 +00:00
Matt Corallo
7f24e833fb Fix reachable unwrap on non-channel_type manual channel acceptance
If we receive an `OpenChannel` message without a `channel_type`
with `manually_accept_inbound_channels` set, we will `unwrap()`
`None`.

This is uncommon these days as most nodes support `channel_type`,
but sadly is rather trivial for a peer to hit for those with manual
channel acceptance enabled.

Reported in and fixes #2804. Luckily, the updated
`full_stack_target` has no issue reaching this issue quickly.
2024-01-08 18:20:17 +00:00
Elias Rohrer
3c0420c39e
Merge pull request #2799 from benthecarman/tx-sync-wasm
Don't call system time in no-std
2024-01-08 18:55:07 +01:00
Matt Corallo
3c28767ceb Move CandidateRouteHop enum variant fields into structs
The bindings generator struggles a bit with the references in enum
variant fields in `CandidateRouteHop`. While we could probably fix
this, its much eaiser (and less risky) to inline the enum variant
fields from `CandidateRouteHop` into structs. This also lets us
make some of the fields non-public, which seems better at least for
the opaque `hint_idx` in the blinded paths.
2024-01-02 03:49:06 +00:00
Matt Corallo
7bc2a148b2 Fix handling of duplicate initial ChannelMonitor writing
In e06484b0f4, we added specific
handling for outbound-channel initial monitor updates failing -
in such a case we have a counterparty who tried to open a second
channel with the same funding info we just gave them, causing us
to force-close our outbound channel as it shows up as
duplicate-funding. Its largely harmless as it leads to a spurious
force-closure of a channel with a peer doing something absurd,
however it causes the `full_stack_target` fuzzer to fail.

Sadly, in 574c77e7bc, as we were
dropping handling of `PermanentFailure` handling for updates, we
accidentally dropped handling for initial updates as well.

Here we fix the issue (again) and add a test.
2023-12-29 06:27:31 +00:00
Matt Corallo
5eea3058c9 Do not panic if a peer learns our funding info before we fund
We'd previously assumed that LDK would receive
`funding_transaction_generated` prior to our peer learning the txid
and panicked if the peer tried to open a redundant channel to us
with the same funding outpoint.

While this assumption is generally safe, some users may have
out-of-band protocols where they notify their LSP about a funding
outpoint first, or this may be violated in the future with
collaborative transaction construction protocols, i.e. the upcoming
dual-funding protocol.
2023-12-29 06:27:31 +00:00
Matt Corallo
bfe911dadc Drop now-unused fields from MsgHandleErrInternal 2023-12-29 06:27:31 +00:00
Matt Corallo
080865dff9 Move ChannelClosed generation into finish_close_channel
Currently the channel shutdown sequence has a number of steps which
all the shutdown callsites have to call. Because many shutdown
cases are rare error cases, its relatively easy to miss a call and
leave users without `Event`s or miss some important cleanup.

One of those steps, calling `issue_channel_close_events`, is rather
easy to remove, as it only generates two events, which can simply
be moved to another shutdown step.

Here we remove `issue_channel_close_events` by moving
`ChannelClosed` event generation into `finish_force_close_channel`.
2023-12-29 06:27:31 +00:00
Matt Corallo
ee5b8c7003 Move DiscardFunding generation into finish_close_channel
Currently the channel shutdown sequence has a number of steps which
all the shutdown callsites have to call. Because many shutdown
cases are rare error cases, its relatively easy to miss a call and
leave users without `Event`s or miss some important cleanup.

One of those steps, calling `issue_channel_close_events`, is rather
easy to remove, as it only generates two events, which can simply
be moved to another shutdown step.

Here we move the first of the two events, `DiscardFunding`, into
`finish_force_close_channel`.
2023-12-29 06:27:31 +00:00
Matt Corallo
396c36b6ea Consider MONITOR_UPDATE_IN_PROGRESS as unbroadcasted funding
If we promote our channel to `AwaitingChannelReady` after adding
funding info, but still have `MONITOR_UPDATE_IN_PROGRESS` set, we
haven't broadcasted the funding transaction yet and thus should
return values from `unbroadcasted_funding[_txid]` and generate a
`DiscardFunding` event.
2023-12-29 06:27:31 +00:00
Matt Corallo
3b6a361ae7 Fix dust buffer feerate calculation overflow
If a peer provides a feerate which nears `u32::MAX`, we may
overflow calculating the dust buffer feerate, leading to spuriously
keeping non-anchor channels open when they should be force-closed.
2023-12-29 06:24:18 +00:00
Matt Corallo
5d8cd5a0a2 Fix debug assertion on opening a channel with a disconnected peer
If we try to open a channel with a peer that is disconnected (but
with which we have some other channels), we'll end up with an
unfunded channel which will lead to a panic when the peer
reconnects. Here we drop this debug assertion without bother to add
a new test, given this behavior will change in a PR very soon.
2023-12-29 06:24:18 +00:00
Matt Corallo
c946edb218 Fix REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH for contest delays >0x7fff
When contest delays are >= 0x8000, script pushes require an extra
byte to avoid being interpreted as a negative int. Thus, for
channels with CSV delays longer than ~7.5 months we may generate
transactions with slightly too little fee. This isn't really a huge
deal, but we should prefer to be conservative here, and slightly
too high fee in the general case is better than slightly too little
fee in other cases.
2023-12-29 06:24:18 +00:00
Matt Corallo
ddb54fc2d2 Stop including dust values in feerate affordability checks
When we or our counterparty are updating the fees on the channel,
we currently check that the resulting balance is sufficient not
only to meet the reserve threshold, but also not push it below
dust. This isn't required in the BOLTs and may lead to spurious
force-closures (which would be a bit safer, but reserve should
always exceed the dust threshold).

Worse, the current logic is broken - it compares the output value
in *billionths of satoshis* to the dust limit in satoshis. Thus,
the code is borderline dead anyway, but can overflow for channels
with several million Bitcoin, causing the fuzzer to get mad (and
lead to spurious force-closures for few-billion-dollar channels).
2023-12-29 06:24:18 +00:00
Matt Corallo
df1f981627 Fix Feature eq + hash to ignore excess zero bytes
If we get a `Feature` object which has excess zero bytes, we
shouldn't consider it a different `Feature` from another with the
same bits set, but no excess zero bytes. Here we fix both the
`Hash` and `PartialEq` implementation for `Features` to ignore
excess zero bytes.
2023-12-24 17:34:11 +00:00
Matt Corallo
15b7f667b0
Merge pull request #2788 from tnull/2023-12-enforce-no-warnings-ci
Deny warnings in CI
2023-12-20 19:54:59 +00:00
benthecarman
f836794e98
Don't call system time in unless feature enabled 2023-12-19 13:22:17 -06:00
Elias Rohrer
2d6464cd71
Allow unused_variables for one _test_vectors method 2023-12-18 08:53:28 +01:00
Elias Rohrer
15e14166da
Allow unused imports in lightning-invoice prelude 2023-12-18 08:53:28 +01:00
Elias Rohrer
5933af1f2d
Drop unused windows imports in FilesystemStore tests 2023-12-18 08:53:28 +01:00
Elias Rohrer
befde89fae
Drop unenforced bound in trait alias
... to fix:
```
  error: bounds on generic parameters are not enforced in type aliases
   --> lightning/src/onion_message/messenger.rs:267:33
```
2023-12-18 08:53:28 +01:00
Elias Rohrer
3b6e83c0fc
Fix unused import warnings in c_bindings 2023-12-18 08:53:28 +01:00
Elias Rohrer
be574f5c27
Fix unused imports in lightning-invoice no-std tests 2023-12-18 08:53:27 +01:00
Elias Rohrer
d8eababd8b
Drop unused sync module from lightning-invoice 2023-12-18 08:53:27 +01:00
Elias Rohrer
c80d9a74b5
Fix unused (import) warnings in no-std builds 2023-12-18 08:53:27 +01:00
Elias Rohrer
e76ad1a245
Fix redundant import warning in BP's futures 2023-12-18 08:53:27 +01:00
Elias Rohrer
b923e1a6f5
Feature-gate GetUtxosResponse in lightning-block-sync
.. as it's only used by the REST client.
2023-12-18 08:53:27 +01:00