Commit graph

7636 commits

Author SHA1 Message Date
Elias Rohrer
a60f7a7fcf
Prepare lightning-background-processor/src/lib.rs 2024-07-09 10:25:47 +02:00
Alec Chen
315193daec Fix bug failing CS-RAA resend order on pending commitment signatures 2024-07-08 17:35:25 -07:00
Matt Corallo
bcacf85a79
Merge pull request #3120 from TheBlueMatt/2023-11-mon-claim-bug
Block monitor updates to ensure preimages are in each MPP part
2024-07-08 13:50:06 -07:00
shaavan
7f82cde861 Introduce MessageContext in ReceiveTlvs
1. New Enum for Enhanced Data Handling:
   - Introduced the `MessageContext` enum, which allows the node to include
     additional context data along with the `reply_path` sent to the counterparty.
   - The node anticipates receiving this data back for further processing.

2. Variants in MessageContext:
   - The `MessageContext` enum includes two variants: "Offers" and
     "Context"
   - One of the variants, `Offers`, holds the `payment_id`
     of the associated Outbound BOLT12 Payment.

3. Future Usage:
   - This enum will be utilized in a subsequent commit to abandon outbound
     payments that have failed to complete for various reasons.
2024-07-09 01:45:13 +05:30
shaavan
7e2fde7054 Remove path_id from Responder, and OnionMessageResponse struct
1. The path_id will be removed from the codebase in the following
   commits.
2024-07-09 01:44:14 +05:30
Matt Corallo
2d1306a324 Test the new RAAMonitorUpdateBlockingAction::ClaimedMPPPayment 2024-07-08 19:07:11 +00:00
Matt Corallo
9cc6e08965 Block monitor updates to ensure preimages are in each MPP part
If we claim an MPP payment and only persist some of the
`ChannelMonitorUpdate`s which include the preimage prior to
shutting down, we may be in a state where some of our
`ChannelMonitor`s have the preimage for a payment while others do
not.

This, it turns out, is actually mostly safe - on startup
`ChanelManager` will detect there's a payment it has as unclaimed
but there's a corresponding payment preimage in a `ChannelMonitor`
and go claim the other MPP parts. This works so long as the
`ChannelManager` has been persisted after the payment has been
received but prior to the `PaymentClaimable` event being processed
(and the claim itself occurring). This is not always true and
certainly not required on our API, but our
`lightning-background-processor` today does persist prior to event
handling so is generally true subject to some race conditions.

In order to address this we need to use copy payment preimages
across channels irrespective of the `ChannelManager`'s payment
state, but this introduces another wrinkle - if one channel makes
substantial progress while other channel(s) are still waiting to
get the payment preimage in `ChannelMonitor`(s) while the
`ChannelManager` hasn't been persisted after the payment was
received, we may end up without the preimage on disk.

Here, we address this issue by using the new
`RAAMonitorUpdateBlockingAction` variant for this specific case. We
block persistence of an RAA `ChannelMonitorUpdate` which may remove
the preimage from disk until all channels have had the preimage
added to their `ChannelMonitor`.

We do this only in-memory (and not on disk) as we can recreate this
blocker during the startup re-claim logic.

This will enable us to claim MPP parts without using the
`ChannelManager`'s payment state in later work.
2024-07-08 19:07:11 +00:00
Matt Corallo
8933a71aed Add a RAAMonitorUpdateBlockingAction::ClaimedMPPPayment
If we claim an MPP payment and only persist some of the
`ChannelMonitorUpdate`s which include the preimage prior to
shutting down, we may be in a state where some of our
`ChannelMonitor`s have the preimage for a payment while others do
not.

This, it turns out, is actually mostly safe - on startup
`ChanelManager` will detect there's a payment it has as unclaimed
but there's a corresponding payment preimage in a `ChannelMonitor`
and go claim the other MPP parts. This works so long as the
`ChannelManager` has been persisted after the payment has been
received but prior to the `PaymentClaimable` event being processed
(and the claim itself occurring). This is not always true and
certainly not required on our API, but our
`lightning-background-processor` today does persist prior to event
handling so is generally true subject to some race conditions.

In order to address this race we need to use copy payment preimages
across channels irrespective of the `ChannelManager`'s payment
state, but this introduces another wrinkle - if one channel makes
substantial progress while other channel(s) are still waiting to
get the payment preimage in `ChannelMonitor`(s) while the
`ChannelManager` hasn't been persisted after the payment was
received, we may end up without the preimage on disk.

Here, we address this issue with a new
`RAAMonitorUpdateBlockingAction` variant for this specific case. We
block persistence of an RAA `ChannelMonitorUpdate` which may remove
the preimage from disk until all channels have had the preimage
added to their `ChannelMonitor`.

We do this only in-memory (and not on disk) as we can recreate this
blocker during the startup re-claim logic.

This will enable us to claim MPP parts without using the
`ChannelManager`'s payment state in later work.
2024-07-08 19:06:59 +00:00
Matt Corallo
453ed11f80 Track the cp node_id which originated an HTLC in the HTLCSource
Because we track pending `ChannelMonitorUpdate`s per-peer, we
really need to know what peer an HTLC came from when we go to claim
it on-chain, allowing us to look up any blocked actions in the
`PeerState`. While we could do this by moving the blocked actions
to some global "closed-channel update queue", its simpler to do it
this way.

While this trades off `ChannelMonitorUpdate` size somewhat (the
`HTLCSource` is included in many of them), which we should be
sensitive to, it will also allow us to (eventually) remove the
SCID -> peer + channel_id lookups we do when claiming or failing
today, which are somewhat annoying to deal with.
2024-07-08 19:06:59 +00:00
Matt Corallo
1c6ce8e789 Add skipping variants to impl_writeable_tlv_based_enum_upgradable
In some cases, we have variants of an enum serialized using
`impl_writeable_tlv_based_enum_upgradable` which we don't want to
write/read. Here we add support for such variants by writing them
using the (odd) type 255 without any contents and using
`MaybeReadable` to decline to read them.
2024-07-08 19:06:59 +00:00
Matt Corallo
40283e7153
Merge pull request #3151 from alecchendev/2024-06-async-test-util-followup
Async signing test util follow ups
2024-07-08 11:28:16 -07:00
jbesraa
8403755a2a
Add FundingTxBroadcastSafe event
The `FundingTxBroadcastSafe` event indicates that we have received
`funding_signed` message from our counterparty and that you should
broadcast the funding transaction.

This event is only emitted if upon generating the funding transaction
you call `ChannelManager::unsafe_manual_funding_transaction_generated`
that will emit this event instead of `ChannelPending` event.

`ChannelManager::unsafe_manual_funding_transaction_generated` wont check
if the funding transaction is signed, those its unsafe. It is manual
because you are responsibile on broadcasting the transaction once the
event is received.
2024-07-08 20:10:19 +03:00
valentinewallace
bfc20f8f34
Merge pull request #3156 from valentinewallace/2024-07-b12-max-path-len
Set max path length when paying BOLT 12 invoices.
2024-07-08 12:45:20 -04:00
Valentine Wallace
678aac0f0f
Set max path length when paying BOLT 12 invoices. 2024-07-08 10:35:48 -04:00
Elias Rohrer
0c3196c52d
Merge pull request #3158 from dunxen/2024-07-excludemergesfrommutants
Skip incremental-mutants job for main
2024-07-08 10:06:43 +02:00
Duncan Dean
8400cfc0d8
Fix CI for unused PendingOnionMessage 2024-07-04 17:08:16 +02:00
Duncan Dean
b1d7829565
Skip incremental-mutants job for main
There is no diff when running against main, so we skip incremental-mutants.
Before this commit, we'd get `Error: Failed to parse diff: Line 1: Error while parsing:`
as the diff file was empty.
2024-07-04 15:48:08 +02:00
Valentine Wallace
c8888e6d66
Test router: support expecting blinded payment paths. 2024-07-03 14:31:13 -04:00
Valentine Wallace
c239b1c899
Remove spurious commented out code line. 2024-07-03 14:28:20 -04:00
Elias Rohrer
669a4596a6
Merge pull request #3154 from TheBlueMatt/2024-06-message-flags
Fix spelling in comment
2024-07-03 03:15:37 -04:00
Alec Chen
3775edd7ee Allow sending RAA upon unblocking the signer 2024-07-02 19:11:44 -07:00
Matt Corallo
46ba6a8fbb Fix spelling in comment
From @valentinewallace at
https://github.com/lightningdevkit/rust-lightning/pull/3144#discussion_r1661404243
2024-07-02 22:18:17 +00:00
Matt Corallo
8d240cfe3e
Merge pull request #3144 from TheBlueMatt/2024-06-message-flags
(Re-)add handling for `ChannelUpdate::message_flags`
2024-07-02 15:16:59 -07:00
Matt Corallo
162b81fbb1 Use test_msg_exact in channl_update fuzz testing
Gossip messages should always use `test_msg_exact` to ensure they
round-trip during signature validation.
2024-07-01 23:46:34 +00:00
Matt Corallo
dc3f826123 (Re-)add handling for ChannelUpdate::message_flags
When the `htlc_maximum_msat` field was made mandatory in
`ChannelUpdate` (in b0e8b739b7) we
started ignoring the `message_flags` field entirely and always
writing `1`. The comment updates indicated that the `message_flags`
field was deprecated, but this is not true - only the
`htlc_maximum_msat` indicator bit was deprecated, requiring it to
be 1.

If a node creates a `channel_update` with `message_flags` bits set
other than the low bit, this will cause us to spuriously reject
the message with an invalid signature error as we will check the
message against the wrong hash.

With today's current spec this is totally fine - the only other bit
defined for `message_flags` is the `dont_forward` bit, which when
set indicates we shouldn't accept the message into our gossip store
anyway (though this may lead to spurious `warning` messages being
sent to peers). However, in the future this may mean we start
rejecting valid `channel_update`s if new bits are defiend.
2024-07-01 23:46:34 +00:00
Alec Chen
1ce5bbd47a Async signing test util follow ups
- Remove unused unavailable signers in TestKeysInterface
- Remove unnecessary display implementation for SignerOp
- Move set of test disabled signer ops to EnforcementState
- Add method to enable/disable all signer ops at once
2024-07-01 16:11:20 -07:00
Matt Corallo
c64b8e4dd7
Merge pull request #2763 from dunxen/2023-11-mutation-testing
Introduce mutation testing
2024-07-01 10:40:17 -07:00
Duncan Dean
c42699d1af
Introduce basic incremental mutation testing
We introduce a CI job for mutation testing of PR diffs using cargo-mutants.
Missed cases do not trigger a fail of this job yet as we just introduce it
now for visibility. We may start enforcing stricter rules at a later stage.
2024-06-30 17:25:56 +02:00
Jeffrey Czyz
3ccf064160
Merge pull request #3129 from optout21/splicing-msgs-update
Update splice messages according to new spec draft
2024-06-27 14:39:26 -05:00
Elias Rohrer
b3223abbe1
Merge pull request #3147 from TheBlueMatt/2024-06-feerate-overflow
Handle feerates of `u32::MAX` without overflowing
2024-06-27 11:03:24 -04:00
dunxen
cb0849855b
Merge pull request #2989 from optout21/iatx-shared-output
Interactive TX negotiation tracks shared outputs
2024-06-27 10:37:39 +02:00
Matt Corallo
e8bc0c92ad Handle feerates of u32::MAX without overflowing
Though we generally shouldn't be seeing these, and the
`get_dust_buffer_feerate` implementation will still return
`u32::MAX` in spite of the overflow, we should handle the overflow
to avoid panic when `debug_assertions` are enabled.

Found by the `full_stack_target` fuzzer
2024-06-26 14:23:40 +00:00
valentinewallace
d43218ab8b
Merge pull request #3145 from valentinewallace/2024-06-AP-prefactor-followup
Followups to #3125
2024-06-26 10:19:22 -04:00
Valentine Wallace
969578703d
Implement AsyncPaymentsMessageHandler for ChanMan and use everywhere
Dummy implementation for now. This avoids having to change a bunch of type
signatures in the future when we replace the dummy impl with a real one.
2024-06-25 16:40:35 -04:00
Valentine Wallace
07b4cb6265
Onion message fuzzer: update held_htlc_available handling
Fuzzers should always do more, not less. Post-merge feedback on
e8f154dd3c.
2024-06-25 15:51:05 -04:00
valentinewallace
88e1b56d66
Merge pull request #3125 from valentinewallace/2024-06-async-payments-prefactor
Async payments message encoding and prefactor
2024-06-24 12:06:17 -04:00
optout
43a6ee34d7
Update splice messages according to new spec draft 2024-06-24 13:05:45 +02:00
Valentine Wallace
5c7af8c6d3
Cfg-gate async payments module and public enum variants. 2024-06-20 14:24:09 -04:00
Valentine Wallace
f20bd3de9f
Remove unused imports in static_invoice.rs 2024-06-20 14:24:09 -04:00
Valentine Wallace
6553d15aad
Add OffersMessage variant for static invoices. 2024-06-20 14:24:09 -04:00
Valentine Wallace
691e10f01e
DRY responder instantiation for onion messages. 2024-06-20 14:24:08 -04:00
Valentine Wallace
e8f154dd3c
AsyncPaymentsMessageHandler trait for OnionMessenger
Add a trait for handling async payments messages to OnionMessenger. This allows
users to either provide their own custom handling for async payments messages
or rely on a version provided by LDK.
2024-06-20 14:24:03 -04:00
Matt Corallo
07d991c82f
Merge pull request #2966 from G8XSU/2647-distribute
Optimize ChannelMonitor persistence on block connections.
2024-06-20 09:51:54 -07:00
optout
80eb5cee10
Interactive TX negotiation tracks shared outputs 2024-06-20 17:28:56 +02:00
Matt Corallo
38285167b1
Merge pull request #3127 from wvanlint/non_strict_forwarding
Implement non-strict forwarding
2024-06-20 07:26:43 -07:00
Valentine Wallace
445ec8d508
Onion message payload for async payments
Async payments uses onion messages to indicate when HTLCs are held and
released. Add these types along with the necessary parsing and encoding.
2024-06-20 10:09:03 -04:00
Elias Rohrer
321f2a8b4a
Merge pull request #3135 from tnull/2024-06-rustfmt-rgs
Run `rustfmt` on `lightning-rapid-gossip-sync`
2024-06-20 13:46:06 +02:00
Elias Rohrer
8be13f684f
rustfmt: Drop benches/src/bench.rs from excluded files 2024-06-20 10:59:21 +02:00
Elias Rohrer
945fb5b3c9
rustfmt: Run on lightning-rapid-gossip-sync/src/lib.rs 2024-06-20 10:55:49 +02:00
Elias Rohrer
6e81e1240b
rustfmt: Run on lightning-rapid-gossip-sync/src/processing.rs 2024-06-20 10:55:08 +02:00