Commit graph

7440 commits

Author SHA1 Message Date
Matt Corallo
2804377f9e Bump possiblyrandom to 0.2
I'd uploaded `possiblyrandom` 0.1 to reserve the crate name but
with a dummy library so now we need ot use 0.2 for the release.
2024-05-08 20:08:52 +00:00
Matt Corallo
df4a09a273 Add changelog entries for 0.0.123 2024-05-08 20:08:52 +00:00
Matt Corallo
8db1226ae4 Use consistent byte/char offsets when parsing invoice HRPs
When parsing lightning-invoice HRPs we want to read them
char-by-char, tracking at which offset different fields were. Prior
to this commit this was done first by reading char-by-char and then
by indexing using the byte offset which works for ASCII strings but
fails on multi-byte characters.

This commit fixes this issue by simply always walking byte-by-byte
and rejecting multi-byte characters which don't belong in HRPs.
2024-05-08 19:56:21 +00:00
Matt Corallo
65ba75d500 Substantially increase coverage in BOLT11 deserialization fuzzer 2024-05-08 19:56:21 +00:00
Matt Corallo
d14ea82b5d Move existing BOLT11 fuzz test to the fuzz crate 2024-05-08 19:36:15 +00:00
Matt Corallo
676f242796
Merge pull request #3046 from TheBlueMatt/2024-03-fees-are-dust
Fix the `full_stack_target` breakage test and doc feerate requests
2024-05-08 12:24:04 -07:00
shaavan
15d016ac52 Implement ResponseInstruction Usage in OnionMessage Handling
This commit integrates the newly introduced ResponseInstruction structs
and enums into the codebase for handling OnionMessage responses.
2024-05-08 17:57:57 +05:30
Matt Corallo
28d85af955 Fix the full_stack_target breakage test and doc feerate requests
When we added the additional deust exposure checks in
702196819e6445048b803574fcacef77d5ce8c9c we added several
additional feerate fetches which broke the `full_stack_target`
change-detection test.

This updates the hard-coded test to support the new feerate fetches
and also includes a comment on `FeeEstimator` to indicate that
users really need to be caching feerates as otherwise they'll slow
us down.
2024-05-07 16:51:38 +00:00
Matt Corallo
d1ac0717fe
Merge pull request #3045 from TheBlueMatt/2024-03-fees-are-dust
Include excess counterparty commitment transaction fees in dust exposure
2024-05-07 08:50:46 -07:00
Matt Corallo
5091c1fd68 Add a simple test of the new excess-fees-are-dust behavior 2024-05-07 14:13:55 +00:00
Matt Corallo
f0b3708c20 Update default dust exposure limit and the documentation thereof
Now that we're including excess counterparty commitment transaction
fees in our dust calculation, we need to update the docs
accordingly. We do so here, describing some of the considerations
and risks that come with the new changes.

We also take this opportunity to double the default value, as users
have regularly complained that non-anchor channels fail to send
HTLCs with the default settings with some feerates.

Fixes #2922
2024-05-07 14:13:55 +00:00
Matt Corallo
51bf78d604 Include excess commitment transaction fees in dust exposure
Transaction fees on counterparty commitment transactions are
ultimately not our money and thus are really "dust" from our PoV -
they're funds that may be ours during off-chain updates but are not
ours once we go on-chain.

Thus, here, we count any such fees in excess of our own fee
estimates towards dust exposure. We don't bother to make an
inbound/outbound channel distinction here as in most cases users
will use `MaxDustExposure::FeeRateMultiplier` which will scale
with the fee we set on outbound channels anyway.

Note that this also enables the dust exposure checks on anchor
channels during feerate updates. We'd previously elided these as
increases in the channel feerates do not change the HTLC dust
exposure, but now do for the fee dust exposure.
2024-05-07 14:13:55 +00:00
Gursharan Singh
8861a9acfa
Stop tracking chain_sync_monitor_persistences in TestPersister 2024-05-06 13:00:52 -07:00
Gursharan Singh
7cd6030886
Make ChannelMonitor chain-sync log a trace log 2024-05-06 12:55:28 -07:00
Gursharan Singh
a5933ae248
Minor Doc fixes after #2957 2024-05-06 12:55:19 -07:00
Matt Corallo
78ab54ff82
Merge pull request #3039 from valentinewallace/2024-04-invoice-amt-msats-overflow
Fix overflow in invoice amount setter.
2024-05-06 12:20:37 -07:00
Matt Corallo
b8d4ac1371
Merge pull request #2957 from G8XSU/pause-events
Don't pause events for chainsync persistence
2024-05-06 12:08:10 -07:00
Valentine Wallace
0ea58d0713
Fix overflow in invoice amount setter. 2024-05-06 11:20:04 -04:00
Matt Corallo
57644f6a81 Provide more color in filter registration methods
A few years ago we had repeated user confusion dealing with the
`Filter` methods and exactly how they differ. Here we try to add a
bit more color in several ways as suggested by users in a few
places - listing examples of why the methods are used as well as
ensuring its clearly communicated that not all parameters need be
used.

Fixes #1069
2024-05-05 19:52:58 +00:00
Matt Corallo
37c431ad68
Merge pull request #3035 from TheBlueMatt/2024-04-upstream-123-bindings 2024-05-03 17:55:25 -07:00
Matt Corallo
0cc7be0317 Keep newlines between releases in CHANGELOG consistent 2024-05-03 20:14:26 +00:00
Matt Corallo
f7e6235cb6 Add release note for 0.0.122 with just three PRs. 2024-05-03 20:14:26 +00:00
Matt Corallo
a27088d6aa
Merge pull request #3018 from jkczyz/2024-04-optional-description
Optional description for `Offer` and `Refund`
2024-05-03 12:55:17 -07:00
Matt Corallo
3d5a6913b5
Merge pull request #3029 from TheBlueMatt/2024-04-fix-batch-funding-failures
Add error handling for channels which fail to be created in `funding_transaction_generated_intern`
2024-05-03 12:17:58 -07:00
shaavan
e640951f95 Introduce ResponseInstructions for OnionMessage Handling
- Currently, handle_message (or handle_custom_message) only exposes
  the generated response for an OnionMessage, lacking the necessary
  reply_path for asynchronous responses.

- This commit introduces a new flow for OnionMessage handling.

- Instead of solely taking the message as input, handle_message now accepts
  an Optional `responder`, returning a `ResponseInstruction` containing both
  the response and the reply_path.

- `ResponseInstruction` utilizes different enum variants to indicate how
  `handle_onion_message_response` should handle the response.

- This enhancement enables exposing the reply_path alongside the response
  and allows for more complex response mechanisms, such as responding with
  an added reply_path.

- The commit introduces the foundational framework (structs & enums) for this new flow.
2024-05-03 17:26:19 +05:30
Jeffrey Czyz
e61001f60d
Only require description when offer has an amount
The spec was changed to allow excluding an offer description if the
offer doesn't have an amount. However, it is still required when the
amount is set.
2024-05-02 16:42:27 -05:00
Matt Corallo
11c3d7001b Swap UserConfig::default() for test_default_channel_config
As LDK changes, `UserConfig::default()` may imply marginally
different behavior, whereas `test_default_channel_config` is
intended to tweak defaults to provide a stable behavior for test
contexts.

This commit changes a few uses of `UserConfig::default()` to
`test_default_channel_config` in cases that will fail over the
coming commits due to dust changes.
2024-05-02 15:39:03 +00:00
Matt Corallo
0e831b4bd0 Correct indentation in get_pending_htlc_stats
The previous commit left indentation in `get_pending_htlc_stats`
deliberately wrong, to ease reviewability. This commit fixes the
indentation.
2024-05-02 15:39:03 +00:00
Matt Corallo
2937000051 Unify get_{inbound,outbound}_pending_htlc_stats
In most cases we already call both in a pair, and in fact always
consolidate some of the returned values across both accessors, so
there's not much reason to have them be separate methods.

Here we merge them.
2024-05-02 15:39:03 +00:00
Matt Corallo
bd3cc003bb
Merge pull request #3033 from TheBlueMatt/2024-04-notify-bp-on-blocks
Wake `background-processor` from `ChainMonitor` on new blocks
2024-05-01 14:21:28 -07:00
Matt Corallo
021979b5dd Wake background-processor from ChainMonitor on new blocks
When we receive a new block we may generate
`Event::SpendableOutputs` in `ChannelMonitor`s which then need to
be processed by the background processor. While it will do so
eventually when its normal loop goes around, this may cause user
tests to be delayed in finding events, so we should notify the BP
immediately to wake it on new blocks.

We implement that here, unconditionally notifying the
`background-processor` whenever we receive a new block or confirmed
transactions.
2024-05-01 19:42:24 +00:00
Matt Corallo
376df8770b Update documentation on [u8; 32] wrappers for clarity 2024-05-01 19:01:40 +00:00
Matt Corallo
e818c4b13f Move [u8; 32] wrapper types to a common module
The `PaymentHash`, `PaymentSecret`, `PaymentPreimage`, and
`ChannelId` types are all small wrappers around `[u8; 32]` and are
used throughout the codebase but were defined in the top-level
`ln/mod.rs` file and the relatively sparsely-populated
`ln/channel_id.rs` file.

Here we move them to a common `types` module and go ahead and
update all our in-crate `use` statements to refer to the new
module for bindings. We do, however, leave a `pub use` alias for
the old paths to avoid upgrade hassle for users.
2024-05-01 19:01:40 +00:00
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