Commit graph

7897 commits

Author SHA1 Message Date
Matt Corallo
aadf233d6c Fix bug in BufReader::fill_buf when reaching EOF
When we reach EOF we may return a full buffer when we should return
an empty one.
2024-08-19 14:55:28 +00:00
Matt Corallo
dd37077c35
Merge pull request #3240 from tnull/2024-08-add-ci-flag-for-bitcoind
Disallow skipping tx-sync tests in CI
2024-08-19 14:53:36 +00:00
Matt Corallo
1e1b8ecbb0 Re-export lightning_types in top-level lightning modules
Since we now have many types in one place, it makes sense to export
them in that place. Further, doing so finally somewhat starts to
reduce our `lightning::ln` module size, which historically is the
dumping ground for everything when most things really should be
top-level modules in `lightning`.

Here we take a step in the right direction by exporting
`lightning_types` as `lightning::types` and encouraging users to
use those paths directly rather than the ones in `lightning::ln`.
2024-08-19 14:50:30 +00:00
Matt Corallo
4fd07ecada Tweak alignment and memory order in the ProbabilisticScorer
During routing, the majority of our time is spent in the scorer.
Given the scorer isn't actually doing all that much computation,
this means we're quite sensitive to memory latency. Thus, the cache
lines our data sits on is incredibly important.

Here, we manually lay out the `ChannelLiquidity` and
`HistoricalLiquidityTracker` structs to ensure that we can do the
non-historical scoring and skip historical scoring for channels
with insufficient data by just looking at the same cache line the
channel's SCID is on.

Sadly, to do the full historical scoring we need to load a second
128-byte cache line pair, but we have some time to get there. We
might consider issuing a preload instruction in the future.

This improves performance a few percent.
2024-08-19 14:25:58 +00:00
Matt Corallo
8904073a15 Cache the total points tracked in our historical liquidity data
When we go to score a channel using the historical liquidity data,
the first thing we do is step through all the valid bucket
combinations, multiply the min and max bucket, and then add them
together to calculate the total number of points tracked. This
isn't a free operation, and for scorers without much data it
represents a large part of the total time spent scoring during
routefinding.

Thus, here we cache this value, updating it every time the buckets
are updated.
2024-08-19 14:25:58 +00:00
Matt Corallo
c0cc30e874 Change the directed history tracker's storage of its direction
Rather than storing the two direction's buckets in
`HistoricalMinMaxBuckets` (renamed
`DirectedHistoricalLiquidityTracker`), we store a single reference
to the `HistoricalLiquidityTracker` as well as the direction bool.

This will allow us in the next commit to reference fields in the
`HistoricalLiquidityTracker` aside from the two directions.
2024-08-19 14:25:58 +00:00
Matt Corallo
3bd8140301 Make the historical bucket data private to bucketed_history
In a comming commit we'll cache some additional data in the
historical bucket tracker. In order to do so, here we isolate the
buckets themselves into the `bucketed_history` module, reducing
the possibility of accidentally updating them directly without
updating caches.
2024-08-19 14:25:58 +00:00
Matt Corallo
c62e346b5d Store both min and max historical buckets in one, new, struct
In the coming commits we'll isolate historical bucket logic slightly
further, allowing us to cache some state. This is the first step
towards that, storing the historical liquidity information in a new
`HistoricalLiquidityTracker` rather than in the general
`ChannelLiquidity`.
2024-08-19 14:25:48 +00:00
Matt Corallo
dcc84dee4d Format log_approx.rs per rustfmt 2024-08-19 14:24:18 +00:00
Matt Corallo
1c84d3b14c Move log approximation from scoring.rs to its own file 2024-08-19 14:24:18 +00:00
valentinewallace
ccce9d9602
Merge pull request #3242 from jkczyz/2024-08-payment-id-auth-api
Add `PaymentId` authentication to public API
2024-08-19 10:14:37 -04:00
Elias Rohrer
e393893a34
rustfmt: Drop lightning-persister from exclusion list 2024-08-17 09:23:37 +02:00
Elias Rohrer
f87eaccae8
rustfmt: Run on lightning-persister 2024-08-17 09:23:36 +02:00
Jeffrey Czyz
5bee20e237
Add PaymentId authentication to public API
When receiving an InvoiceError message, it should be authenticated
before using it to abandon the payment. Add methods to PaymentId's
public API for constructing and verifying an HMAC for use in
OffersContext::OutboundPayment. This allows other implementations of
OffersMessageHandler to construct the HMAC and authenticate the message.
2024-08-16 15:43:43 -05:00
Matt Corallo
43dcf2f3d8
Merge pull request #3239 from arik-so/bitcoin-0.32.2-upgrade
Bitcoin 0.32.2 upgrade
2024-08-16 20:13:26 +00:00
Arik Sosman
36b484a720
Fix fuzz warnings.
Version 0.32.2 of `rust-bitcoin` deprecates a number of methods that
are commonly used in this project, most visibly `txid()`, which is
now called `compute_txid()`. This resulted in a lot of warnings, and
this commit is part of a series that seeks to address that.
2024-08-16 10:31:45 -07:00
Arik Sosman
9914fd4f8d
Fix lightning-transaction sync warnings.
Version 0.32.2 of `rust-bitcoin` deprecates a number of methods that
are commonly used in this project, most visibly `txid()`, which is
now called `compute_txid()`. This resulted in a lot of warnings, and
this commit is part of a series that seeks to address that.
2024-08-16 10:31:45 -07:00
Arik Sosman
92aac2a2ae
Fix lightning-block-sync warnings.
Version 0.32.2 of `rust-bitcoin` deprecates a number of methods that
are commonly used in this project, most visibly `txid()`, which is
now called `compute_txid()`. This resulted in a lot of warnings, and
this commit is part of a series that seeks to address that.
2024-08-16 10:31:45 -07:00
Arik Sosman
813202f554
Fix lightning-background-processor warnings.
Version 0.32.2 of `rust-bitcoin` deprecates a number of methods that
are commonly used in this project, most visibly `txid()`, which is
now called `compute_txid()`. This resulted in a lot of warnings, and
this commit is part of a series that seeks to address that.
2024-08-16 10:31:45 -07:00
Arik Sosman
d85a1a9a8d
Fix lightning warnings.
Version 0.32.2 of `rust-bitcoin` deprecates a number of methods that
are commonly used in this project, most visibly `txid()`, which is
now called `compute_txid()`. This resulted in a lot of warnings, and
this commit is part of a series that seeks to address that.
2024-08-16 10:31:45 -07:00
Arik Sosman
60ca255e5e
Suppress Taproot warnings.
Taproot is not yet being actively used, and this commit suppresses
the noisy warning generation.
2024-08-16 10:31:45 -07: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
8fe3a56d4b
Merge pull request #3182 from valentinewallace/2024-07-expose-advance-bp
Expose blinded paths' `advance_path_by_one`
2024-08-16 17:11:21 +00:00
Jeffrey Czyz
fa6c0587e7
Return a Result from verify_payment_id 2024-08-16 11:31:31 -05:00
Arik Sosman
40b04000aa
Reimplement io::Cursor.
The `bitcoin::io` Cursor will miss a bunch of functionality that we were
using that we will reimplement here, most critically `set_position`.
2024-08-16 09:23:09 -07:00
Arik Sosman
b05113ab72
Introduce io module.
The rust-bitcoin upgrade will introduce `bitcoin::io` module, which
will be missing a necessary subset of traits.

To accommodate those traits' future implementations, we move the
`lightning::io` module to its own file, where we will be able to
implement the missing trait subset in the next commit.
2024-08-16 09:23:09 -07:00
Arik Sosman
fb818e09a0
Drop Seek and SeekFrom usage.
In lieu of using `Seek` and `SeekFrom`, we will instead rely
exclusively on the `io::Cursor` type.
2024-08-16 09:23:09 -07:00
Arik Sosman
d1767cdedf
Simplify Readable mutability.
In anticipation of the rust-bitcoin upgrade, which incorporates its
own `io::Read` implementation, we need to make our usage compatible
with dropping `std::io` and `core2::io`.

Notably, in version 0.32.2, `bitcoin::io`'s `Read` is no longer
implemented for `&mut R where R: Read + ?Sized`, which results in
errors anytime `&mut &mut Readable` is passed instead of
`&mut Readable`.

This commit fixes those instances.
2024-08-16 09:23:09 -07:00
Elias Rohrer
43bc78ce3d
Disallow skipping tx-sync tests in CI
Previously, we'd always skip tx-sync tests if the
`BITCOIND_EXE`/`ELECTRS_EXE` environment variables would be unset. While
this is especially fine for local testing, we still want to enforce
tests failing if somehow the `bitcoind`/`electrs` downloading or caching
in CI stops working. Here, we therefore add a `CI_ENV` variable that
indicates we're indeed running in CI, and only skip if it's unset.
2024-08-16 17:41:16 +02:00
Valentine Wallace
b204a6a11d
Make advance_path_by_one an associated method. 2024-08-16 10:30:42 -04:00
Valentine Wallace
8eb3344216
Tweak phrasing in Blinded{Message,Payment}Path::advance_path_by_one docs. 2024-08-16 10:28:52 -04:00
Valentine Wallace
55de90af93
Move NextMessageHop into blinded_path::message
It's only used for onion messages, not payments.
2024-08-16 10:28:52 -04:00
Valentine Wallace
aa9b03a229
Make BlindedPath type private.
Users should use the Blinded{Message,Payment}Path types instead.
2024-08-16 10:28:52 -04:00
Valentine Wallace
5a8cf06390
Reduce visibility of BlindedMessagePath inner path.
Works towards making the inner BlindedPath struct private to the module.
2024-08-16 10:28:41 -04:00
valentinewallace
137cfea11d
Merge pull request #3241 from TheBlueMatt/2024-08-ret-slice-not-ref-vec
Return slices, rather than `Vec` references, in addresses
2024-08-15 13:38:58 -04:00
Valentine Wallace
6f0190d144
Reduce visibility of BlindedPaymentPath inner path.
Works towards making the inner BlindedPath struct private to the module.
2024-08-15 13:04:07 -04:00
Valentine Wallace
c563c150f0
Add accessor methods for inner blinded path fields. 2024-08-15 13:04:04 -04:00
Valentine Wallace
10449b96de
Move public_intro_node util into Blinded{Message,Payment}Path
Helps move towards making the BlindedPath struct private.
2024-08-15 13:04:04 -04:00
Valentine Wallace
cbc25fbcf0
Move compact blinded path util to message paths only.
It's only used for message paths, so let's move it there to help make the
BlindedPath struct private.
2024-08-15 13:04:04 -04:00
Valentine Wallace
4dba7a314c
Expose blinded paths' advance_path_by_one methods.
Useful for LDK users that are using the onion messages module, like LNDK.
2024-08-15 13:04:04 -04:00
Valentine Wallace
e741a9a8e7
Add BlindedMessagePath type to disambiguate from blinded payment paths. 2024-08-15 13:04:01 -04:00
Valentine Wallace
caa836e8e5
Add BlindedPaymentPath type, to disambiguate from message paths.
Next up, we'll add a BlindedMessagePath type so the API is clear which type of
path is expected in each context.
2024-08-15 13:03:56 -04:00
Matt Corallo
b3aed9a260 Return slices, rather than Vec references, in addresses
Its a bit strange to return a reference to a `Vec` in Rust, when a
slice is really intended as the way to do so. Worse, the bindings
don't know how to map a reference to a `Vec` (but do have code to
map a slice of `Clone`able objects).

Here, we move `NodeAnnouncementInfo::addresses` to return a slice,
though to do so we have to adapt the `WithoutLength` `Writeable`
impl to support slices as well.
2024-08-14 19:44:13 +00:00
Matt Corallo
33e69958e0
Merge pull request #3192 from jkczyz/2024-07-invoice-error-auth
Authenticate `InvoiceError` messages
2024-08-14 18:28:39 +00:00
Jeffrey Czyz
075a2e36b9
Make PaymentFailureReason downgradable
The PaymentFailureReason variants for invoice request failures will
cause downgrades to break. Instead, use a new TLV for the reason and
continue to write the old TLV, only use None for the new reasons.
2024-08-14 10:55:59 -05:00
Jeffrey Czyz
bb94320e40
Make PaymentFailureReason upgradable
This allows downgrading to version 0.0.124 or later and using None for a
PaymentFailureReason that was added after.
2024-08-14 10:55:59 -05:00
Jeffrey Czyz
1563186c2b
Add PaymentFailureReason::InvoiceRequestRejected
Instead of re-using PaymentFailureReason::RecipientRejected, define a
new InvoiceRequestRejected variant for when an InvoiceError is received
instead of a Bolt12Invoice. This allows user to differentiate the cause
of the failure.
2024-08-14 10:55:59 -05:00
Jeffrey Czyz
457ba24ee5
Add PaymentFailureReason::InvoiceRequestExpired
Now that Event::PaymentFailed is generated when an InvoiceRequest times
out, define a new PaymentFailureReason for this situation.
2024-08-14 10:55:59 -05:00
Jeffrey Czyz
f00b782a1c
Add pending changelog for Event::PaymentFailed 2024-08-14 10:55:59 -05:00