Commit graph

417 commits

Author SHA1 Message Date
Elias Rohrer
7ed62510fa
rustfmt: Run on lightning-invoice/src/lib.rs 2024-11-14 11:53:11 +01:00
Elias Rohrer
f121508f3b
rustfmt: Prepare lightning-invoice/src/lib.rs 2024-11-14 11:52:44 +01:00
Elias Rohrer
8397671e70
rustfmt: Run on lightning-invoice/src/tb.rs 2024-11-14 11:46:25 +01:00
Elias Rohrer
1fcd36385f
rustfmt: Run on lightning-invoice/src/ser.rs 2024-11-14 11:46:25 +01:00
Elias Rohrer
97537c5ac9
rustfmt: Run on lightning-invoice/src/de.rs 2024-11-14 11:46:24 +01:00
Elias Rohrer
f4d0584a36
rustfmt: Prepare lightning-invoice/src/de.rs 2024-11-14 11:45:45 +01:00
Jeffrey Czyz
65790b6718
Add Description::empty constructor
When creating a default Bolt11InvoiceParameters, having an infallible
constructor avoids an unwrap.
2024-11-06 11:53:46 -06:00
Jeffrey Czyz
0e1723dc74
Owned and ref versions of Bolt11InvoiceDescription
Split Bolt11InvoiceDescription into a version used with references to
the description or description hash in the invoice and an owned version
of these for when constructing an invoice. The latter is useful as it
removes an unnecessary clone and can be used in a future change
specifying either a description or description hash in larger set of
invoice parameters. Since it doesn't use a reference, it can be exposed
in bindings as well.
2024-10-28 14:49:21 -05:00
Matt Corallo
5c1440afec Hold a reference to byte arrays when serializing to bech32
When we serialize from a byte array to bech32 in
`lightning-invoice`, we can either copy the array itself into the
iterator or hold a reference to the array and iterate through that.

In aa2f6b47df we opted to copy the
array into the iterator, which is fine for the current array sizes
we're working with, but does result in additional memory on the
stack if, in the future, we end up writing large arrays.

Instead, here, we switch to using the slice serialization code when
writing arrays, (very marginally) reducing code size and reducing
stack usage.
2024-10-03 22:21:55 +00:00
Matt Corallo
052e7c3df0 Marginally reduce allocations in lightning-invoice
In aa2f6b47df we refactored
`lightning-invoice` de/serialization to use the new version of
`bech32`, but in order to keep the public API the same we
introduced one allocation we could have skipped.

Instead, here, we replace the public `Utf8Error` with
`FromUtf8Error` which contains the original data which failed
conversion, removing an allocation in the process.
2024-10-03 17:26:01 +00:00
Matt Corallo
c5658f6cc2 Check that the HRPs generated in BOLT 11 RawHrp are always valid
...in `debug_assertions`.
2024-10-03 17:24:59 +00:00
Matt Corallo
cc72f032dc Marginally reduce allocations in lightning-invoice
In aa2f6b47df we refactored
`lightning-invoice` de/serialization to use the new version of
`bech32`, also reducing some trivial unnecessary allocations when
we did so.

Here we drop a few additional allocations which came up in review.
2024-10-03 17:20:07 +00:00
optout
aa2f6b47df
Upgrade bech32 dependency, bech32 serialization improvements 2024-10-02 21:21:07 +02:00
optout
ad80e919ec Add Bolt11InvoiceFeatures serialization tests 2024-10-02 15:28:29 +02:00
Matt Corallo
c9de257498 Update versions to 0.0.124 and invoice 0.32 types 0.1 release 2024-09-03 18:18:52 +00:00
Matt Corallo
856c980594 Bump versions to rc1 2024-08-29 19:40:09 +00:00
optout
12481392cf
Add invoice serialization tests 2024-08-23 15:46:22 +02:00
Matt Corallo
cd0ca28945 Bump version numbers to 0.0.124-beta/invoice 0.32-beta 2024-08-20 00:29:12 +00:00
Matt Corallo
31a9cd2d3d Drop the no-std feature from lightning-invoice
Now that we don't have to have everything in our entire ecosystem
use the same `std`/`no-std` feature combinations we should start by
untangling our own features a bit.

This takes another step by removing the `no-std` feature entirely
from the `lightning-invoice` crate and removing all feature
implications on dependencies from the remaining `std` feature.
2024-08-19 15:09:40 +00:00
Arik Sosman
0cc9378afc
Remove secp256k1 dependency. 2024-08-16 10:31:45 -07:00
Arik Sosman
176d2ad599
Upgrade rust-bitcoin to 0.32.2. 2024-08-16 10:31:45 -07:00
Matt Corallo
a741a57249 Swap the dep order between lightning and lightning-invoice
`lightning-invoice` previously had a dependency on the entire
`lightning` crate just because it wants to use some of the useful
types from it. This is obviously backwards and leads to some
awkwardness like the BOLT 11 invoice signing API in the `lightning`
crate taking a `[u5]` rather than a `Bolt11Invoice`.

Here we finally rectify this issue, swapping the dependency order
and making `lightning` depend on `lightning-invoice` rather than
the other way around.

This moves various utilities which were in `lightning-invoice` but
relied on `lightning` payment types to make payments to where they
belong (the `lightning` crate), but doesn't bother with integrating
them well in their new home.
2024-08-13 12:55:18 +00:00
Matt Corallo
1eba737f44 Add a lightning-types dependency to lightning-invoice
`lightning-invoice` currently has a dependency on the entire
`lightning` crate just because it wants to use some of the useful
types from it. This is obviously backwards and leads to some
awkwardness like the BOLT 11 invoice signing API in the `lightning`
crate taking a `[u5]` rather than a `Bolt11Invoice`.

This takes tees us up for the final step, adding a
`lightning-types` dependency to `lightning-invoice` and using it
for imports rather than the `lightning` crate.
2024-08-13 12:54:59 +00:00
Matt Corallo
1f01f2ef67 Use check_added_monitors test utility in invoice utils tests
In a coming commit, the `lightning-invoice::utils` module will move
to the `lightning` crate, causing its tests to be included in the
global lockorder tests done in that crate. This should be fine,
except that the `lightning-invoice::utils` module currently holds
the `added_monitors` lock too long causing lockorder violations.

Instead, this commit replaces the legacy monitors-added test with
the `check_added_monitors` test utility.
2024-08-13 12:54:59 +00:00
Tobin C. Harding
eac1b87e65
Use bitcoin::hex instead of bitcoin::hashes::hex
Use the `hex-conservative` crate directly from `bitcoin` instead of from
`hashes`. Although it makes no real difference it is slightly more clear
and more terse.
2024-08-09 08:20:15 +10:00
Tobin C. Harding
aeee8fe31e
Remove explicit dependency on hex-conservative
The `hex` crate is re-exported by `rust-bitcoin` so we can get it from
there instead of explicitly depending on it. Doing so reduces the
maintenance burden and helps reduce the likelyhood of getting two
versions in the dependency graph.
2024-08-09 08:20:09 +10:00
Tobin C. Harding
e9b20cee43
Do not use bitcoin::blockdata
The `rust-bitcoin` project is working towards making the public API
separate from the directory structure; eventually the
`bitcoin::blockdata` will go away, to make maintenance easier here stop
using the `blockdata` module.

Do not run the formatter, so as to make review easier. This patch was
created mechanically using:

search-and-replace bitcoin::blockdata bitcoin

and having defined

```bash
search-and-replace () {
        if (($# != 2))
        then
                echo "Usage: $0 <this> <that>"
                return
        fi
        local this="$1"
        local that="$2"
        for file in $(git grep -l "$this")
        do
                perl -pi -e "s/$this/$that/g" "$file"
        done
}
```
2024-08-08 07:13:26 +10:00
Max Fang
2a8ab6fc28 lightning-invoice: Add Description::as_inner 2024-07-23 17:16:12 -07:00
Elias Rohrer
018908fe9e
Make event handling fallible
Previously, we would require our users to handle all events
successfully inline or panic will trying to do so. If they would exit
the `EventHandler` any other way we'd forget about the event and
wouldn't replay them after restart.

Here, we implement fallible event handling, allowing the user to return
`Err(())` which signals to our event providers they should abort event
processing and replay any unhandled events later (i.e., in the next
invocation).
2024-07-18 15:54:21 +02:00
Matt Corallo
dee3ba7d6a
Merge pull request #3185 from tnull/2024-07-clarify-max-description-length
Clarify maximum length of an invoice description
2024-07-16 08:24:45 -07:00
Elias Rohrer
fa7ecc56d7
Clarify maximum length of an invoice description
We previously stated in the docs that the invoice description can be at most `1023`
bytes long, which is wrong. According to BOLT 11 it's at most 1023*5 bits (639 bytes) long.
2024-07-16 10:28:58 +02:00
Matt Corallo
e0f797460e Drop unnecessary strict feature from lightning-invoice
99aa6e27f6 detected that we had an
undefined feature in `lightning-invoice` called `strict`, which was
used to turn on `deny(warnings)`. It resolved that by adding the
feature to the `Cargo.toml`, but we actually don't need it - our CI
already builds with `-Dwarnings`, so any warnings should be
rejected during CI and there's not a lot of value in having a
(public) feature to do the same.
2024-07-15 18:34:31 +00:00
Duncan Dean
99aa6e27f6
Use native check-cfg lint in cargo beta
This uses the newly introduced conditional configuration checks that are
now configurable withint Cargo (beta).

This allows us to get rid of our custom python script that checks for
expected features and cfgs.

This does introduce a warning regarding the unknown lint in Cargo
versions prior to the current beta, but since these are not rustc errors,
they won't break any builds with the "-D warnings" RUSTFLAG.

Moving to this lint actually exposed the "strict" feature not being
present in the lightning-invoice crate, as our python script didnt
correctly parse the cfg_attr where it appeared.
2024-07-12 11:48:15 +02:00
Matt Corallo
2d6d5cc86f Move the public path for channel_state types to their new path 2024-06-04 14:21:08 +00:00
Matt Corallo
bfda1b683b
Merge pull request #3063 from jirijakes/upgrade-bitcoin-031
Upgrade rust-bitcoin dependency to 0.31
2024-05-31 14:18:23 -07:00
Jiri Jakes
a8bd4c097f
Upgrade rust-bitcoin to 0.31 2024-05-30 18:35:29 +08:00
Jeffrey Czyz
b6ff46daab
Pass ClaimAlongRouteArgs to do_claim_payment_along_route 2024-05-24 16:52:08 -05:00
Matt Corallo
806b7f0e31
Merge pull request #3054 from TheBlueMatt/2024-04-fuzz-bolt11
Add fuzzing coverage for BOLT11 invoice deserialization
2024-05-08 13:24:31 -07: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
d14ea82b5d Move existing BOLT11 fuzz test to the fuzz crate 2024-05-08 19:36:15 +00:00
Valentine Wallace
0ea58d0713
Fix overflow in invoice amount setter. 2024-05-06 11:20:04 -04: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
Valentine Wallace
c6ae9288b9
Fix overflow in lightning-invoice amount_pico_btc. 2024-04-30 10:05:35 -04:00
Matt Corallo
49b375311b Bump crate versions to 0.0.123-beta/invoice 0.31-beta 2024-04-19 01:03:03 +00:00
Matt Corallo
ef2e739295 Remove a handful of redundant imports
... that newer rustc now warns about.
2024-04-05 09:05:56 +00:00
Matt Corallo
ae0d825d89 Use crate::prelude::* rather than specific imports
New rustc beta now warns on duplicate imports when one of the
imports is from a wildcard import or the default prelude. Thus, to
avoid this here we prefer to always use `crate::prelude::*` and let
it decide if we actually need to import anything.
2024-04-05 09:05:54 +00:00
Matt Corallo
39c1d6b2af Replace the generic parse_int_be with a macro called twice
`parse_int_be` is generic across integer types and also input
types, but to do so it relies on the `num-traits` crate. There's
not a lot of reason for this now that std has `from_be_bytes`, so
we drop the generic now and replace it with a macro which is called
twice to create two functions, both only supporting conversion from
`u5` arrays.
2024-03-13 19:18:20 +00:00
Matt Corallo
c89b96a4b9 Use std's from_be_bytes rather than our to_int_be for int conv
`lightning-invoice` was mostly written before std's `from_be_bytes`
was stabilized, so used its own `to_int_be` utility to do int
conversions from `u8` arrays. Now that the std option has been
stable for quite some time, we should juse use it instead.
2024-03-13 19:16:20 +00:00
Matt Corallo
36e434d8ce
Merge pull request #2909 from benthecarman/inv-pk-helper
Add helper function to properly get invoice pubkey
2024-02-22 19:32:02 +00:00
benthecarman
53fc986378
Add helper function to properly get invoice pubkey 2024-02-22 18:05:37 +00:00