Commit graph

3815 commits

Author SHA1 Message Date
Matt Corallo
34f36d5ffe Drop various bounds on types passed to MonitorUpdatingPersister
The new `MonitorUpdatingPersister` has a few redundant type bounds
(re-specified on functions after having been specified on the
struct itself), which we remove here.

Further, it requires a `Deref<FeeEstimator>` which is `Clone`able.
This is generally fine in rust, but annoying in bindings, so we
simply elide it in favor if a `&Deref<FeeEstimator>`.
2023-10-01 00:05:01 +00:00
Matt Corallo
07205a2869 Make create_onion_message a freestanding function
The new `create_onion_message` function in `OnionMessenger` is hard
to handle - it has various generic requirements indirectly via the
struct, but they're not bounded by any of the method parameters.
Thus, you can't simply call `OnionMessenger::create_onion_message`,
as various bounds are not specified.

Instead, we move it to a freestanding function so that it can be
called directly without explicitly setting bounds.
2023-10-01 00:05:01 +00:00
Matt Corallo
6ce4c6cbc5 Mark AChannelManager no-export
The trait itself has no purpose for bindings, as all structs are
concretized anyway. Further, the bindings have specific handling
for generic bounding traits like this.
2023-10-01 00:05:01 +00:00
Matt Corallo
09cd4ed976 Mark SpendableOutputDescriptor::to_psbt_input as no-export
Its honestly likely not all that useful as its not materially
interoperable with other PSBT libraries. Instead, users should
simply fetch the full PSBT and use the inputs from it as they see
fit.
2023-10-01 00:05:01 +00:00
Matt Corallo
9c78d8e90e Drop unnecessary crate:: prefix when accessing bitcoin in macro
Unexported macros don't need to use the `$crate` prefix.
2023-10-01 00:05:01 +00:00
Matt Corallo
095fca9293 Avoid ref to a Vec when accessing custom onion TLVs
The bindings can't easily return a reference to a `Vec`, so we
instead split the implementation into vec/slice depending on the
`c_bindings` flag.
2023-10-01 00:05:01 +00:00
Matt Corallo
087c8f683a Avoid blanket impls in bindings builds
The C bindings implements `Deref` for all traits, so having a
blanket `Deref` implementation ends up conflicting with this.
2023-10-01 00:05:01 +00:00
Matt Corallo
0bc0de46fa Simplify score bounding with a unified type
In a few places we require a unified scorer, which implements both
`ScoreLookUp` and `ScoreUpdate`. Rather than double-bounding (which
the bindings generator can't handle directly), we use a top-level
`Score` trait which requires both and is implemented for all
implementers of both supertraits.
2023-10-01 00:05:01 +00:00
Matt Corallo
748bebadb4 Remove unnecessary bounds in scoring
In our scoring logic we have a handful of unnecessary bounds,
leading to extra diff in the bindings branch when those bounds have
to be removed as well as a few cases where bindings generation
simply gets confused.

Here we remove a number of bounds across the scoring traits and
impls, cleaning things up and simplifying bindings changes.
2023-10-01 00:05:01 +00:00
Matt Corallo
26c1639ab6 Use Default::default() to construct () as score-updating param
In 6b0d94a302 we switched most tests
to `Default::default()` for scoring parameters passed to
route-fetching. Here we do the same for the scoring parameters when
passed to score-updating.
2023-10-01 00:05:01 +00:00
Matt Corallo
20f287f439
Merge pull request #2630 from TheBlueMatt/2023-09-117-rc1
Bump crate versions to 0.0.117-rc1/invoice 0.25-rc1
2023-09-30 00:38:27 +00:00
Matt Corallo
cff2061335
Merge pull request #2610 from wpaulino/missing-htlc-claim-balance
Fix matching of second-stage HTLC claim in get_htlc_balance
2023-09-29 23:55:04 +00:00
Matt Corallo
f534ce26c9
Merge pull request #2621 from G8XSU/dont-persist-erroneous-update
Persist entire monitor if there is an error while applying monitor_update
2023-09-29 23:45:57 +00:00
Matt Corallo
7036681728 Bump crate versions to 0.0.117-rc1/invoice 0.25-rc1 2023-09-29 23:39:18 +00:00
Wilmer Paulino
fd66a298f3
Fix wrong node broadcaster in test_yield_anchors_events 2023-09-29 16:28:22 -07:00
Wilmer Paulino
4a393ee540
Add anchors coverage to test_revoked_counterparty_aggregated_claims 2023-09-29 16:28:20 -07:00
Wilmer Paulino
fe45af62a5
Add anchors coverage to test_revoked_counterparty_htlc_tx_balances 2023-09-29 16:27:10 -07:00
Gursharan Singh
976acd8af0
Add update_persisted_channel doc to indicate rare case for None update 2023-09-29 16:26:40 -07:00
Gursharan Singh
5e6a0d5f38
Persist full monitor if there is an error while applying monitor_update
Motivation: When there is an error while applying monitor_update to a
channel_monitor,  we don't want to persist a 'monitor_update' which
results in a failure to apply later while reading 'channel_monitor' with
updates from storage. Instead, we should persist the entire 'channel_monitor'
here.
2023-09-29 16:26:40 -07:00
Gursharan Singh
13eac47ed9
Correctly mark chain_sync updates in test_utils
We were incorrectly marking updates as chain_sync
or not in test_utils based on whether monitor_update
is None or not. Instead, use UpdateOrigin to determine it.
2023-09-29 16:26:29 -07:00
Wilmer Paulino
4156d7c53d
Add anchors coverage to test_revoked_counterparty_commitment_balances 2023-09-29 16:24:45 -07:00
Wilmer Paulino
898a20066c
Add anchors coverage to test_balances_on_local_commitment_htlcs 2023-09-29 16:24:44 -07:00
Wilmer Paulino
ea4b187df4
Add anchors coverage to test_claim_value_force_close 2023-09-29 16:24:44 -07:00
Wilmer Paulino
28f2dac844
Add anchors coverage to chanmon_claim_value_coop_close 2023-09-29 16:24:44 -07:00
Wilmer Paulino
52d76f97fc
Add test util to handle bump HTLC events 2023-09-29 16:24:42 -07:00
Matt Corallo
0930be3304
Fix matching of second-stage HTLC claim in get_htlc_balance
We incorrectly assumed that the descriptor's output index from
second-stage HTLC transaction would always match the HTLC's output index
in the commitment transaction. This doesn't make any sense though, we
need to make sure we map the descriptor to it's corresponding HTLC in
the commitment. Instead, we check that the transaction from which the
descriptor originated from spends the HTLC in question.

Note that pre-anchors, second-stage HTLC transactions are always 1
input-1 output, so previously we would only match if the HTLC was the
first output in the commitment transaction. Post-anchors, they are
malleable, so  we can aggregate multiple HTLC claims into a single
transaction making this even more likely to happen. Unfortunately, we
lacked proper coverage in this area so the bug went unnoticed. To
address this, we aim to extend our existing coverage of
`get_claimable_balances` to anchor outputs channels in the following
commits.
2023-09-29 16:24:39 -07:00
Matt Corallo
e0fe325402
Merge pull request #2629 from jkczyz/2023-09-invreqfailed
Config-guard `Event::InvoiceRequestFailed`
2023-09-29 22:42:50 +00:00
Matt Corallo
620244dc2e
Merge pull request #2605 from wpaulino/anchors-monitor-track-to-remote-script
Use correct to_remote script in counterparty commitments
2023-09-29 22:06:58 +00:00
Jeffrey Czyz
92e5cb6805
Remove unused imports 2023-09-29 15:03:23 -07:00
Jeffrey Czyz
5f58f8d127
Fix build warning for unused method 2023-09-29 15:03:23 -07:00
Jeffrey Czyz
6bd962bc51
Remove an unnecessary enumerate 2023-09-29 15:03:23 -07:00
Jeffrey Czyz
c7219e4683
Config-guard Event::InvoiceRequestFailed
The event cannot be generated publicly, so remove it for now to avoid
users needing to handle it.
2023-09-29 15:03:13 -07:00
Matt Corallo
d007d1b79f
Merge pull request #2628 from wvanlint/fix_multiple_shutdown_results
Fix handling multiple ShutdownResults
2023-09-29 21:25:51 +00:00
Wilmer Paulino
f464aa97c3
Expose witness_script for StaticPaymentOutputDescriptor 2023-09-29 14:22:04 -07:00
Wilmer Paulino
9f3bb7d7a5
Fix incorrect anchors counterparty_payment_script upon deserialization 2023-09-29 14:22:02 -07:00
Matt Corallo
b58f057345
Merge pull request #2622 from wpaulino/funding-and-commitment-tx-confirm-same-block
Avoid early return upon confirmation of channel funding
2023-09-29 21:06:55 +00:00
Matt Corallo
efbaa19a05
Merge pull request #2626 from TheBlueMatt/2023-09-revert-2476
Revert "Remove AvailableBalances::balance_msat"
2023-09-29 21:06:41 +00:00
Wilmer Paulino
3299d88595
Fix off-by-one max witness estimate for P2WPKH StaticPaymentDescriptor
We were not accounting for the extra byte denoting the number of items
in the witness stack.
2023-09-29 13:46:59 -07:00
Wilmer Paulino
fa2a2efef4
Support signing to_remote anchors variant for StaticPaymentOutput
`to_remote` outputs on commitment transactions with anchor outputs have
an additional `1 CSV` constraint on its spending condition,
transitioning away from the previous P2WPKH script to a P2WSH.

Since our `ChannelMonitor` was never updated to track the proper
`to_remote` script on anchor outputs channels, we also missed updating
our signer to handle the new script changes.
2023-09-29 13:46:59 -07:00
Wilmer Paulino
33b745f54e
Use correct to_remote script in counterparty commitments
While our commitment transactions did use the correct `to_remote`
script, the `ChannelMonitor`'s was not as it is tracked separately. This
would lead to users never receiving an `Event::SpendableOutputs` with a
`StaticPaymentOutput` descriptor to claim the funds.

Luckily, any users affected which had channel closures confirmed by a
counterparty commitment just need to replay the closing transaction to
receive the event.
2023-09-29 13:46:56 -07:00
Matt Corallo
955e81086f
Merge pull request #2624 from wpaulino/2609-follow-up
Address 2609 follow-up comments
2023-09-29 20:07:16 +00:00
Willem Van Lint
db79ed07f4 Fix handling multiple ShutdownResults 2023-09-29 12:06:36 -07:00
Matt Corallo
fbc86cb564
Merge pull request #2623 from wpaulino/htlc-claim-receive-preimage-after-close
Claim HTLCs with preimage from currently confirmed commitment
2023-09-29 18:53:44 +00:00
Wilmer Paulino
92fcdd39e1
Avoid early return upon confirmation of channel funding
This early return is only possible if the channel requires a single
confirmation, allowing a `channel_ready` message to go out. This can be
problematic though if a commitment transaction (specifically from the
counterparty, as the channel would be immediately closed if a local
commitment is broadcast) also confirms within the same block. The
`ChannelMonitor` will detect both, but it won't inform the
`ChannelManager` at all. Luckily, while the channel still is considered
open to the `ChannelManager`, the `ChannelMonitor` will reject any
further updates to the channel state.
2023-09-29 11:46:25 -07:00
Matt Corallo
c7c4226e99 Revert "Remove AvailableBalances::balance_msat"
While removing the `balance_msat` field absolutely makes sense -
it is, at best, confusing - we really need a solid replacement for
it before we can do so. While one such replacement is in progress,
it is not complete and we'd like to not block our current release
on its completion.

This reverts commit ef5be580f5.
2023-09-29 18:32:25 +00:00
Wilmer Paulino
f267a30cc7
Only yield DelayedPaymentOutput descriptors once their delay expires
Otherwise, we could give users a descriptor ahead of time that will
result in an invalid transaction spend/broadcast.
2023-09-29 10:56:48 -07:00
Matt Corallo
5e871a7bfc
Merge pull request #2617 from wpaulino/no-persist-same-channel-update
Avoid persisting on same counterparty's ChannelUpdate
2023-09-29 17:39:49 +00:00
Elias Rohrer
a8fa5a1685
Merge pull request #2591 from TheBlueMatt/2023-09-2562-followups
Doc and comment followups to #2562
2023-09-29 19:08:36 +02:00
Wilmer Paulino
6cf0351462
Note required levels of descendant transactions in get_spendable_outputs
Three levels of descendant transactions starting from the channel's
funding transaction should cover all potential spendable outputs.

The first level covers the commitment transaction.

The second level covers the to_self claims, to_remote claims,
second-stage HTLC claims and justice transactions.

The third levels covers the justice transactions on second-stage HTLCs,
and to_self claims on second-stage HTLCs.
2023-09-29 10:01:21 -07:00
Wilmer Paulino
d82e6ba7a3
Test preimage claim after reorg of counterparty commitment
This test adds coverage for receiving a preimage after seeing a
counterparty commitment confirm, followed by a reorg and the
confirmation of a different commitment instead.

The first test covers the case where a holder commitment confirms after
the counterparty commitment reorg.

The second test covers the case where a previous counterparty commitment
confirms after the latest counterparty commitment reorg.
2023-09-29 09:58:38 -07:00