Commit graph

393 commits

Author SHA1 Message Date
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
Matt Corallo
eecd2cdf4f Drop lightning-invoice dependency on hashbrown` 2024-02-16 20:34:41 +00:00
benthecarman
0769b22f5c
Worlds smallest optimization
Preallocate for 8 items in the vec. I chose this value for

1. features
2. description
3. payment hash
4. expire time
5. min_final_cltv
6. payment secret
7. route hint
8. for the memes
2024-02-08 22:40:48 +00:00
Matt Corallo
dedc8306f6 Bump hashbrown dependency to 0.13
While this isn't expected to materially improve performance, it
does get us ahash 0.8, which allows us to reduce fuzzing
randomness, making our fuzzers much happier.

Sadly, by default `ahash` no longer tries to autodetect a
randomness source, so we cannot simply rely on `hashbrown` to do
randomization for us, but rather have to also explicitly depend on
`ahash`.
2024-02-02 18:05:08 +00:00
Matt Corallo
7b31b303c6 Bump versions to LDK 0.0.121/invoice 0.29 2024-01-22 22:32:30 +00:00
Matt Corallo
37017ec39f Bump crate versions to 0.0.120/invoice 0.28 2024-01-17 21:34:29 +00:00
shuoer86
8cd48060d7
Fix typo lightning-invoice/src/ser.rs 2024-01-12 20:46:26 +08:00
Elias Rohrer
15e14166da
Allow unused imports in lightning-invoice prelude 2023-12-18 08:53:28 +01:00
Elias Rohrer
be574f5c27
Fix unused imports in lightning-invoice no-std tests 2023-12-18 08:53:27 +01:00
Elias Rohrer
d8eababd8b
Drop unused sync module from lightning-invoice 2023-12-18 08:53:27 +01:00
Matt Corallo
c6e4debee9 Bump versions to 0.0.119/lightning-invoice 0.27 2023-12-15 23:53:40 +00:00
Matt Corallo
83e76d78b7 Drop explicit bitcoin_hashes dependency in lightning-invoice
Since `lightning-invoice` now depends on the `bitcoin` crate
directly, also depending on the `bitcoin_hashes` crate is redundant
and just means we confuse users by setting the `std` flag only on
`bitcoin`. Thus, we drop the explicit dependency here and replace
it with `bitcoin::hashes`.
2023-12-15 22:31:51 +00:00
Matt Corallo
90cc9930b7 Un-export the PrivateRoute inner field as there are invariants
When we make the `PrivateRoute` inner `RouteHint` `pub`, we failed
to note that the `PrivateRoute::new` constructor actually verifies
a length invariant. Thus, we un-export the inner field and force
users to go back through the `new` fn.
2023-12-15 22:31:51 +00:00
Elias Rohrer
ddf2509227
Bump MSRV to rustc 1.63.0 and edition to 2021
.. which is a reasonable common ground, also supported by Debian stable.
2023-12-08 14:03:45 +01:00
henghonglee
fa7f2f4986
Add WithChannelDetails 2023-12-01 11:30:19 -06:00
Arik Sosman
27b9794bed
Rename SignerProvider's Signer to EcdsaSigner. 2023-11-27 16:27:20 -08:00
Matt Corallo
b28068cc42 Drop panic if rust-bitcoin adds a new Network
`rust-bitcoin` 0.30 added `#[non_exhaustive]` to the `Network`
enum, allowing them to "add support" for a new network type without
a major version change in the future. When upgrading, we added a
simple `unreachable` for the general match arm, which would break
in a minor version change of `rust-bitcoin`.

While it seems [possible rust-bitcoin will change
this](https://github.com/rust-bitcoin/rust-bitcoin/issues/2225),
we still shouldn't ba panicking, which we drop here in favor of a
`debug_assert`ion, and a default value.
2023-11-26 19:07:10 +00:00
Wilmer Paulino
ad56847a6b
Remove nightly warnings 2023-11-22 15:58:01 -08:00
Wilmer Paulino
ec928d55b4
Bump rust-bitcoin to v0.30.2 2023-11-22 15:58:01 -08:00
Matt Corallo
9c9e5f896c
Merge pull request #2730 from benthecarman/invoice-utils
Add some public utilities to `lightning_invoice`
2023-11-15 22:01:33 +00:00
benthecarman
e80e8c8062
Have Invoice Description use UntrustedString 2023-11-15 12:35:35 -06:00
benthecarman
3def30721f
Make invoice fields public 2023-11-15 12:35:21 -06:00
Matt Corallo
22305a9bff Drop old expiry_time_from_unix_epoch helper in expiry time lookup
Since there's a much simpler way to go about it with
`Bolt11Invoice::expires_at`.
2023-11-12 17:18:00 +00:00
benthecarman
3fbfde360f
Impl display for invoice fields 2023-11-10 20:41:53 -06:00
Matt Corallo
a6039b9af2 Replace maze of BOLT11 payment utilities with parameter generators
`lightning-invoice` was historically responsible for actually
paying invoices, handling retries and everything. However, that
turned out to be buggy and hard to maintain, so the payment logic
was eventually moved into `ChannelManager`. However, the old
utilites remain.

Because our payment logic has a number of tunable parameters and
there are different ways to pay a BOLT11 invoice, we ended up with
six different methods to pay or probe a BOLT11 invoice, with more
requested as various options still were not exposed.

Instead, here, we replace all six methods with two simple ones
which return the arguments which need to be passed to
`ChannelManager`. Those arguments can be further tweaked before
passing them on, allowing more flexibility.
2023-11-10 19:23:21 +00:00