Commit graph

7257 commits

Author SHA1 Message Date
Matt Corallo
8084cec3e4 Add bindings no-export tags to doc test types
We don't actually intend these to be public as they're just for
docs but the bindings don't currently parse `#[doc(hidden)]` as
"no-export" so we add manual no-export tags as well.
2024-05-01 16:04:37 +00:00
Matt Corallo
84070e1138 Add derives where they make sense and the bindings require them 2024-05-01 16:04:37 +00:00
Matt Corallo
89a67e59ab Rename and expose message-specific NextHop
`onion::message::messenger::PeeledOnion` is a public enum which
included the private enum `NextHop`, which is not acceptable. Thus,
we here expose `NextHop` but rename it `NextMessageHop` to make
clear that it is specific to messages.
2024-05-01 15:16:57 +00:00
Matt Corallo
b403411c24
Merge pull request #3032 from valentinewallace/2024-04-pico-btc-overflow
Fix overflow in lightning-invoice `amount_pico_btc`
2024-05-01 06:08:45 -07:00
valentinewallace
c90369897b
Merge pull request #3031 from TheBlueMatt/2024-04-new-rustc-warning
Fix new rustc `#[macro_export]` warning in doctests
2024-04-30 13:16:11 -04:00
Matt Corallo
c8ddf36f9c Fix new rustc #[macro_export] warning in doctests
rustc now warns any time a `#[macro_export]` is used inside a
function as it generates surprising results. Because doctests are
run inside implicit test functions this means any use of
`#[macro_export]` inside a doctest will now warn. We do this in
`lightning-custom-message` to demonstrated how to use the crate,
which now fails to compile.

Here we fix this by adding an `fn main() {}` to the doctest, which
causes doctests to be compiled as freestanding code rather than
inside a test function.

Note that while discussing this upstream it came up that rustc is
also planning on changing the way doctests are compiled to compile
an entire crate's doctests in one go rather than in separate
crates, causing doctests to have a shared namespace which may
generate future surprising outcomes.
2024-04-30 14:13:12 +00:00
Valentine Wallace
c6ae9288b9
Fix overflow in lightning-invoice amount_pico_btc. 2024-04-30 10:05:35 -04:00
Matt Corallo
b811cba748 Send peers error messages for failures due to invalid batch funding
If we fail to fund a batch open we'll force-close all channels in
the batch, however would previously fail to send error messages to
our peers for any channels we were due to test after the one that
failed.

This commit fixes that issue, sending the required error messages
to allow our peers to clean up their state.
2024-04-30 13:43:32 +00:00
Matt Corallo
6960210f60 Close channels when find_funding_output fails to find an output
In `funding_transaction_generated_intern`, if `find_funding_output`
fails (e.g. due to the require output not being present in the
provided funding transaction) we'd previously not generated a
`ChannelClosed` event which leaves users possibly in a confused
state.

Here we fix this, also fixing the relevant tests to check for the
new event.

Fixes #2843.
2024-04-30 13:43:32 +00:00
Matt Corallo
2b14cc40a6
Merge pull request #3017 from jkczyz/2024-04-optional-pubkey
Sending to `Offer` without `signing_pubkey`
2024-04-29 12:05:30 -07:00
Matt Corallo
d00e55077a
Merge pull request #3028 from jkczyz/2024-04-offer-id-followups
Follow-ups to #2970
2024-04-29 11:26:44 -07:00
Jeffrey Czyz
33b6162fd2
Remove InvoiceRequestFields::features
InvoiceRequestFeatures may contain a large, odd bit. Including this in
InvoiceRequestFields, which is in each BlindedPath of a Bolt12Invoice,
could cause the invoice's onion message to exceed the maximum size. The
features are already checked before sending an invoice.
2024-04-29 12:27:39 -05:00
Jeffrey Czyz
7b864425ea
Remove InvoiceRequestFields::amount_msats
Event::PaymentClaimable and Event::PaymentClaimed already contain the
paid amount, so there's no need to included the requested amount in
InvoiceRequestFields.
2024-04-29 12:27:38 -05:00
Jeffrey Czyz
8e562be5d4
Remove PaymentContext from OnionPayload
PaymentContext is already stored in ClaimablePayment via PaymentPurpose,
so there is no need to repeat it in each ClaimableHTLC via OnionPayload.
This avoids cloning the PaymentContext each time an HTLC is received,
other than for the first HTLC for a payment.
2024-04-29 12:27:34 -05:00
Gursharan Singh
4d5de1fe61
Remove ChainMonitor::sync_persistence_id
It was used earlier for generating unique MonitorUpdateId for
UpdateOrigin::ChainSync monitor updates.
2024-04-26 20:29:02 -07:00
Gursharan Singh
c1125f00b3
Remove MonitorUpdateId from persist trait
MonitorUpdateId was an opaque abstraction for id's generated by
UpdateOrigin:Offchain and UpdateOrigin::ChainSync monitor updates.
It was mainly needed to map calls made to
ChainMonitor::channel_monitor_updated. We no longer track
UpdateOrigin::ChainSync MonitorUpdates and can directly use
ChannelMonitor::get_latest_update_id() for tracking
UpdateOrigin::Offchain monitor updates.
2024-04-26 20:28:55 -07:00
Jeffrey Czyz
db7e696673
Don't require Refund::description in API
Refunds currently require a description, though this may change to be
optional. Remove the description requirement from the API, setting and
empty string by default.
2024-04-26 18:14:30 -05:00
Jeffrey Czyz
48cba2954b
Don't require Offer::description in API
Offers currently require a description, though this may change to be
optional. Remove the description requirement from the API, setting and
empty string by default.
2024-04-26 18:14:30 -05:00
Jeffrey Czyz
b7635c4dc2
Bolt12Invoice for Offer without signing_pubkey
When parsing a Bolt12Invoice use both the Offer's signing_pubkey and
paths to determine if it is for an Offer or a Refund. Previously, an
Offer was required to have a signing_pubkey. But now that it is
optional, the Offers paths can be used to make the determination.
Additionally, check that the invoice matches one of the blinded node ids
from the paths' last hops.
2024-04-26 18:14:09 -05:00
Jeffrey Czyz
61e4fcea8e
Add InvoiceRequestTlvStream::paths
Instead of reusing OfferTlvStream::paths, add a dedicated paths TLV to
InvoiceRequestTlvStream such that it can be used in Refund. This allows
for an Offer without a signing_pubkey and still be able to differentiate
whether an invoice is for an offer or a refund.
2024-04-26 18:14:09 -05:00
Jeffrey Czyz
94d5af663d
Allow parsing Offer without signing_pubkey
If an offer has at least one path, it may omit the signing pubkey and
use the blinded node id of the last hop of a path to sign an invoice.
Allow parsing such offers but not yet creating them.
2024-04-26 18:14:09 -05:00
Jeffrey Czyz
520fecf8fc
Optional OfferContents::signing_pubkey
If an Offer contains a path, the blinded_node_id of the path's final hop
can be used as the signing pubkey. Make Offer::signing_pubkey and
OfferContents::signing_pubkey return an Option to support this. Upcoming
commits will implement this behavior.
2024-04-26 18:14:09 -05:00
Gursharan Singh
7de602a38a
Stop tracking MonitorUpdates from ChainSync in pending_monitor_updates
We no longer need to track them since we no longer hold events for
pending MonitorUpdates resulting from ChainSync.
2024-04-26 16:06:44 -07:00
Gursharan Singh
e084ab26e1
Stop storing last_chain_persist_height
We only used to store last_chain_persist_height to release
events held for more than LATENCY_GRACE_PERIOD_BLOCKS due to
pending monitor update with UpdateOrigin::ChainSync. Since we no
longer pause events for ChainSync persistence, we no longer need to
store last_chain_persist_height.
2024-04-26 16:02:20 -07:00
Gursharan Singh
cb86399f2e
Don't pause events for chainsync persistence
We used to wait on ChannelMonitor persistence to avoid
duplicate payment events. But this can still happen in cases where
ChannelMonitor handed the event to ChannelManager and we did not persist
ChannelManager after event handling.
It is expected to receive payment duplicate events and clients should handle these
events in an idempotent manner. Removing this hold-up of events simplifies
the logic and makes it easier to not persist ChannelMonitors on every block connect.
2024-04-26 14:37:41 -07:00
Gursharan Singh
8701b1bbe3
Merge pull request #3003 from TheBlueMatt/2024-04-2964-followups
#2964 Followups
2024-04-25 13:19:09 -07:00
Matt Corallo
dfb250b976
Merge pull request #3021 from TheBlueMatt/2024-04-drop-blocked-completed-updates
Drop completed blocked `ChannelMonitorUpdate`s on startup
2024-04-25 11:33:18 -07:00
Matt Corallo
eebab4015d
Merge pull request #3004 from TheBlueMatt/2024-04-2761-followups
#2761 Followups
2024-04-25 10:52:12 -07:00
Matt Corallo
c40504a0fc Drop completed blocked ChannelMonitorUpdates on startup
If a user receives a payment preimage for an outbound payment, the
`PaymentSent` event will block any eventual RAA
`ChannelMonitorUpdate` from the same channel, assuming it comes in
before the event can be processed. If this blocking kicks in, but
the flow eventually completes with the RAA `ChannelMonitorUpdate`
being persisted, but the `ChannelManager` is only persisted prior
to the event being handled, on startup we'll have a fully
up-to-date `ChannelMonitor` but a pending, blocked
`ChannelMonitorUpdate`. When the `PaymentSent` event is replayed
we'll end up trying to apply a redundant `ChannelMonitorUpdate`
which will panic.

See the test added in this commit for an implementation of this
situation.

In this commit we fix this issue by simply dropping blocked
`ChannelMonitorUpdate`s the same as we do pending ones.
2024-04-25 15:13:56 +00:00
Elias Rohrer
9a438eea3b
Merge pull request #3015 from tnull/2024-04-sweeper-error-on-persistence-failure
Make `OutputSweeper::track_spendable_outputs` fallible
2024-04-24 16:35:51 +02:00
Elias Rohrer
afb452a813
Make OutputSweeper::track_spendable_outputs fallible
.. as otherwise we might only log an error and continue if we fail to
persist the sweeper state.
2024-04-24 09:46:34 +02:00
Matt Corallo
0e22b1245a
Merge pull request #2981 from dunxen/2024-03-PR2419fixups
Fixups for #2419
2024-04-23 06:48:40 -07:00
Duncan Dean
59a8bd5d65
Add intermediate ConstructedTransaction 2024-04-23 11:33:05 +02:00
Duncan Dean
a04dde7664
Add lower bound segwit input weight estimates 2024-04-23 11:30:59 +02:00
Duncan Dean
a6bee822fb
Add descriptions to test cases 2024-04-23 11:30:33 +02:00
Duncan Dean
62d4952348
Abort if we add a duplicate input 2024-04-23 11:30:00 +02:00
Duncan Dean
ebd57c5d53
Make sent_tx_* fallible and handle errors & simplify counterparty_weight_contributed calc 2024-04-23 11:29:45 +02:00
Duncan Dean
774b048d8f
Check if msg.script.is_witness_program() before checking version 2024-04-23 11:29:24 +02:00
Duncan Dean
4eb70fdf7a
Use HashMaps as, well, HashMaps (don't iter for key match) 2024-04-23 11:29:18 +02:00
Jeffrey Czyz
d6900723df
Remove unnecessary PaymentPreimage clone 2024-04-22 16:43:26 -05:00
Gursharan Singh
d25d55a682
Merge pull request #2990 from TheBlueMatt/2024-04-log-in-flights
Log pending in-flight updates when we are missing a monitor
2024-04-22 10:29:35 -07:00
Matt Corallo
6ab91cb43f Drop the rustup-specific calling in ci/rustfmt.sh
The +rustversion call semantics are specific to rustup and do not
work with standard rust toolchains. However, because rustfmt
formatting differs slightly between stable and our 1.63 target, we
need to keep the +1.63.0 for rustup users.

Thus, here, we check for the presence of a `rustup` command and
pass the "+1.63.0" argument if we find one.
2024-04-22 13:05:53 +00:00
Matt Corallo
eeea0f473e Include channel_keys.rs in the rustfmt list
Since its already formatted and there's not much active work going
on in it.
2024-04-22 13:00:38 +00:00
Matt Corallo
57c8275e0e Only include derive_add_tweak for base key types that use it
Specifically `RevocationBasepoint` has a different derivation, so
shouldn't have a `derive_add_tweak` at all. We also use this
opportunity to link to the `from_basepoint` function in the
`derive_add_tweak` docs.
2024-04-22 13:00:29 +00:00
Matt Corallo
db31f43b87 Word-wrap new doc comment in DelayedPaymentOutputDescriptor 2024-04-22 13:00:29 +00:00
Matt Corallo
9f1c9062db Use Sha256s for tweaks in sign to enforce randomness
We assume that tweaks are the output of a SHA-256 hash function
(and thus that failing to create a private key from the has
negligible probability) in `add_public_key_tweak` and elsewhere.

Thus, we really shouldn't be taking byte arrays in the public API
but rather `Sha256` objects, and communicating in the docs for
`add_public_key_tweak` that we can panic if its not the output of
a hash function, both of which we do here.
2024-04-22 13:00:29 +00:00
Matt Corallo
23d9514259 Simplify and clarify derive_add_tweak documentation 2024-04-22 13:00:29 +00:00
Matt Corallo
fd0c3e4579 Log when a ChannelMonitor's claimable balances set goes empty 2024-04-22 12:24:00 +00:00
Matt Corallo
93e77632d6 Debug-log monitor update starts and completions in ChainMonitor
When a `ChannelMonitor[Update]` persistence completes, we rely on
logging in `ChannelManager` to hear about it. However, this won't
happen at all if there's still pending updates as no `MonitorEvent`
will be generated.

Thus, here, we add logging directly in `ChainMonitor`, ensuring we
can deduce when individual updates completed from debug logs.
2024-04-22 12:21:33 +00:00
Matt Corallo
6ee8d81a58
Merge pull request #3009 from tnull/2024-04-fix-sweeper-typo
Fix typo in `OutputSweeper`
2024-04-22 04:36:41 -07:00