Commit graph

8002 commits

Author SHA1 Message Date
Matt Corallo
1059f5ffc5
Merge pull request #3010 from shaavan/issue2836
Introduce Retry InvoiceRequest Flow
2024-09-12 15:12:39 +00:00
Matt Corallo
1c2bd097a8 Rename AtomicCounter::get_increment to simply next
Its a counter, `next` is super clear, `get_increment` is a bit
less so.
2024-09-12 14:32:43 +00:00
Matt Corallo
2ab133d432 Simplify and fix AtomicCounter
`AtomicCounter` was slightly race-y on 32-bit platforms because it
increments the high `AtomicUsize` independently from the low
`AtomicUsize`, leading to a potential race where another thread
could observe the low increment but not the high increment and see
a value of 0 twice.

This isn't a big deal because (a) most platforms are 64-bit these
days, (b) 32-bit platforms aren't super likely to have their
counter overflow 32 bits anyway, and (c) the two writes are
back-to-back so having another thread read during that window is
very unlikely.

However, we can also optimize the counter somewhat by using the
`target_has_atomic = "64"` cfg flag, which we do here, allowing us
to use `AtomicU64` even on 32-bit platforms where 64-bit atomics
are available.

This changes some test behavior slightly, which requires
adaptation.

Fixes #3000
2024-09-12 14:32:43 +00:00
shaavan
b1cd8874cf Introduce handle_message_received test
- Add a test to verify the functionality of the handle_message_received
  function.
- Ensure the test covers scenarios where InvoiceRequest messages are retried
  for PendingOutboundPayments after a simulated connection loss.
2024-09-12 18:56:48 +05:30
shaavan
5cccee565f Introduce message_received in ChannelMessageHandler
- Introduce the `message_received` function to manage the
  behavior when a message is received from any peer.
- This function is used within `ChannelManager` to retry `InvoiceRequest`
  messages if we haven't received the corresponding invoice yet.
- This change makes the offer communication robust against sudden
  connection drops where the initial attempt to send the message
  might have failed.
2024-09-12 18:52:48 +05:30
shaavan
1881f35235 Introduce enqueue_invoice_request Function
1. Separate the logic of forming `invoice_request` messages from
   `invoice_request` and `reply_paths` and enqueueing them into a
   separate function.
2. This logic will be reused in the following commit when reforming
   `invoice_request` messages for retrying.
2024-09-12 18:47:44 +05:30
shaavan
17d80f970f Introduce RetryableInvoiceRequest in AwaitingInvoice
1. To enable the retry of the Invoice Request message, it's necessary
   to store the essential data required to recreate the message.
2. A new struct is introduced to manage this data, ensuring the
   InvoiceRequest message can be reliably recreated for retries.
3. The addition of an `awaiting_invoice` flag allows tracking of
   retryable invoice requests, preventing the need to lock the
   `pending_outbound_payment` mutex.
2024-09-12 18:47:33 +05:30
Matt Corallo
0b7838b59d Refactor channel_update processing logic into local fns
In the next commit we'll move to checking `channel_update`s in
three steps - first we check if the `channel_update` is new and the
latest for a channel, then we check the signature, and finally we
update our local state. This allows us to avoid holding a lock on
`NetworkGraph::channels` while validating the message signature.

Here we do a quick prefactor to make that simpler - moving the
validation logic of `channel_update` that we'll do in step one (and
repeat in step three) into a local function. We also take this
opportunity to do one static check unlocked which we had been doing
while holding a `channel` lock.
2024-09-11 23:37:40 +00:00
Matt Corallo
db905e8a8d
Merge pull request #3291 from tnull/2024-09-add-their-node-id-routing-msg-handler
Add node id to remaining `RoutingMessageHandler::handle_` methods
2024-09-11 22:25:41 +00:00
Matt Corallo
4178dd770a
Merge pull request #3163 from shaavan/invoice_reply_path
Introduce Reply Paths for BOLT12 Invoice in Offers Flow.
2024-09-11 20:17:54 +00:00
Matt Corallo
6e340c43de Don't rely on route-fetching rand in blinded_path_with_custom_tlv
`blinded_path_with_custom_tlv` indirectly relied on route CLTV
randomization when sending because nodes were at substantially
different block heights after setup. Instead we make sure all nodes
are at the same height which makes the test more robust.
2024-09-11 20:01:43 +00:00
Matt Corallo
758747ac9f Drop Debug on InMemorySigner (and EntropySource)
`InMemorySigner` has various private keys in it which makes
`Debug` either useless or dangerous (because most keys won't log
anything, but if they did we'd risk logging private key material).
2024-09-11 20:01:43 +00:00
Elias Rohrer
b172942a75
Refactor: Take their_node_id by value across all handler interfaces
In order to maintain interface consistency, we refactor all message
handler interfaces to take `PublicKey` rather than `&PublicKey`, as the
difference in efficiency should be negigible and the former is easier to
handle in binding languages.

Over time, we also want to move (no pun intended) towards all messaging
interfaces using move semantics, so dropping the reference for
`PublicKey` is the first step in this direction.
2024-09-11 19:19:38 +02:00
Elias Rohrer
f68b8b6834
Add node id to remaining RoutingMessageHandler::handle_ methods
Previously, some `RoutingMessageHandler::handle_` methods (in particular
the ones handling node and channel announcements, as well as channel
updates, omitted the `their_node_id` argument. This didn't allow
implementors to discern *who* sent a particular method.

Here, we add `their_node_id: Option<&PublicKey>` to have them learn who
sent a message, and set `None` if our own node it the originator of a
broadcast operation.
2024-09-11 18:01:33 +02:00
shaavan
7b49993101 Update Offers Test to Verify BOLT12 Invoice Reply Paths
1. Updated the Offers Test to check the reply paths in BOLT12 Invoices.
2. Changed the `extract_invoice` return type from `Option<BlindedMessagePath>`
   to `BlindedMessagePath` since all BOLT12Invoices now have a corresponding
   reply path by default.
2024-09-11 18:54:49 +05:30
shaavan
a4bf936101 Add reply_path to BOLT12Invoices in Offers Flow
1. Introduced reply_path in BOLT12Invoices to address a gap in error handling.
   Previously, if a BOLT12Invoice sent in the offers flow generated an Invoice Error,
   the payer had no way to send this error back to the payee.
2. By adding a reply_path to the Invoice Message, the payer can now communicate
   any errors back to the payee, ensuring better error handling and communication
   within the offers flow.
2024-09-11 18:54:49 +05:30
shaavan
8b479ac587 Add HMAC, and nonce to OffersContext::InboundPayment
Introduce HMAC and nonce calculation when sending Invoice with
reply path, so that if we receive InvoiceError back for the
corresponding Invoice we can verify the payment hash before logging it.
2024-09-11 18:54:49 +05:30
Matt Corallo
82b3f620f5
Merge pull request #3309 from TheBlueMatt/2024-09-always-print-why
Always print why we disconnect explicitly
2024-09-10 19:47:15 +00:00
valentinewallace
a6dea2f154
Merge pull request #3305 from TheBlueMatt/2024-09-no-redundant-gossip-validation
Avoid redundant `{channel,node}_announcement` signature checks
2024-09-10 12:49:06 -04:00
Matt Corallo
7efefd7e2a Always print why we disconnect explicitly
...and drop the old, confusing, "protocol error" message when we
get a duplicate connection from a peer.

This should slightly further disambiguate disconnection reasons,
which are a key debugging tool for assigning blame.
2024-09-10 14:26:57 +00:00
Elias Rohrer
479654b0a8
Merge pull request #3306 from TheBlueMatt/2024-09-chan-id-hex
Write ChannelIds out as hex in Debug output
2024-09-10 12:33:38 +02:00
shaavan
6500277ba8 Introduce Verification trait.
- The trait defines the public method one may define for creating and
  verifying the HMAC.
- Using a pub trait to define these method allows the flexibility for
  other `OffersMessageHandler` construct to construct the HMAC and
authenticate the message.
2024-09-10 15:57:24 +05:30
Matt Corallo
d65dc9c7ae
Merge pull request #3296 from alecchendev/2024-09-async-close-sign-followup
Finish closing channel after async closing signed
2024-09-09 23:59:25 +00:00
Matt Corallo
56cb6a10f1 Avoid redundant {channel,node}_announcement signature checks
If we receive `{channel,node}_announcement` messages which we
already have, we first validate their signatures and then look in
our graph and discover that we should discard the messages. This
avoids a second lock in `node_announcement` handling but does not
impact our locking in `channel_announcement` handling. It also
avoids lock contention in cases where the signatures are invalid,
but that should be exceedingly rare.

For nodes with relatively few peers, this is a fine state to be in,
however for nodes with many peers, we may see the same messages
hundreds of times. This causes a rather substantial waste of CPU
resources validating gossip messages.

Instead, here, we change to checking our network graph first and
then validate the signatures only if we don't already have the
message.
2024-09-09 18:14:19 +00:00
Duncan Dean
59f16896d6
Remove AvailableBalances::balance_msat
The ChannelMonitor::get_claimable_balances and ChainMonitor::get_claimable_balances
methods provide a more straightforward approach to the balance of a channel, which
satisfies most use cases. The computation of AvailableBalances::balance_msat is
complex and originally had a different purpose that is not applicable
anymore.

Co-authored-by: Willem Van Lint <noreply@wvanlint.dev>
2024-09-09 19:37:03 +02:00
Alec Chen
1fa7bf9391 Finish closing channel after async closing signed
In addressing a followup to test reconnection during closing negotation
with async signing, we change things to only return a `ShutdownResult`
when we actually finish shutting down the channel, i.e. we have the
signature ready to send the final closing signed. This slightly
simplifies the logic where we would shutdown our channel
prematurely before we got the final signature. This also means
that we don't push multiple `ChannelClosed` events if we receive closing
signed, reconnect, and receive closing signed again.
2024-09-09 09:46:44 -07:00
Matt Corallo
98d15f2c99 Clean up imports in lightning-types
To remove the now-redundant `hex_conservative` explicit dependency.
2024-09-09 15:32:12 +00:00
Matt Corallo
cc6e2a0f7a Write ChannelIds out as hex in Debug output
`ChannelId`s are almost always referenced as hex, so having debug
output print the raw bytes is somewhat annoying. Instead, we should
dump them as hex the same way we do for `Display`.

This uses the `hex_conservative` `impl_fmt_macros` which does all
the work for us, like we use for `lightning_types`.
2024-09-09 15:32:08 +00:00
Matt Corallo
91a60c8256 impl Borrow<[u8]> for ChannelId
We do this for `Payment*` in `lightning-types` and its needed for
the `hex_conservaitve` `impl_fmt_traits` macro which we'll use in
the next commit.
2024-09-09 15:30:09 +00:00
Matt Corallo
eba329cfaf
Merge pull request #3304 from TheBlueMatt/2024-09-tokio-util-msrv
Fix MSRV builds of `lightning-transaction-sync` in CI
2024-09-09 13:38:44 +00:00
Matt Corallo
35bc575cd8 Reduce features on lightning-transaction-sync's tokio dev-dep
This should marginally reduce the chance of MSRV or other issues in
the future, and is just good practice.
2024-09-08 21:42:36 +00:00
Matt Corallo
7e22b78af9 Test lightning-transaction-sync in our no-dev-deps MSRV test
Now that `lightning-transaction-sync` is in the workspace and
covered by our MSRV we should be testing it in our
`msrv-no-dev-deps-check` test crate.
2024-09-08 21:21:35 +00:00
Matt Corallo
868a5956a4 Fix MSRV test of lightning-transaction-sync with esplora-async
`lightning-transaction-sync`'s `esplora-async` dependency
indirectly depends on `tokio-util`, which, like tokio, recently
bumped its MSRV.

Here we update `ci/ci-tests.sh` to pin `tokio-util` to make MSRV
builds pass.
2024-09-08 21:21:35 +00:00
shaavan
e2ee325101 HMAC Construction and Verification for PaymentHash
When a InvoiceError is received for a sent BOLT12Invoice, the
corresponding PaymentHash is to be logged. Introduce hmac construction
and verification function for PaymentHash for this purpose.
2024-09-06 17:57:35 +05:30
Matt Corallo
d35239ca62
Merge pull request #3290 from tnull/2024-09-add-tx-sync-copyright
Add copyright notices to `lightning-transaction-sync` modules
2024-09-04 14:13:37 +00:00
Elias Rohrer
c15968c5f4
Add copyright notices to lightning-transaction-sync modules 2024-09-04 13:02:45 +02:00
Matt Corallo
b023eed99c
Merge pull request #3278 from TheBlueMatt/2024-08-124-relnotes
Add an 0.0.124 CHANGELOG entry
2024-09-03 18:35:17 +00: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
f52148f4c2 Add an 0.0.124 CHANGELOG entry 2024-09-03 18:18:52 +00:00
Matt Corallo
187a2cb45e
Merge pull request #3285 from TheBlueMatt/2024-08-tx-too-small
Correct handling of added `OP_RETURN` outputs
2024-09-03 17:53:08 +00:00
Matt Corallo
660f5c2af7
Merge pull request #3284 from TheBlueMatt/2024-08-bindings-imports-suck 2024-09-03 15:20:16 +00:00
Matt Corallo
5f5c275ea3 Correct ANCHOR_INPUT_WITNESS_WEIGHT constant
`ANCHOR_INPUT_WITNESS_WEIGHT` is too high by two weight units,
likely it was calculated to include the SegWit marker bytes, but
it is used to describe an `Input::satisfaction_weight`, which does
not expect the marker bytes.

This corrects that oversight, reducing the constant by two and
adding the marker bytes back in our own internal weight
calculations. It also fixes a second issue where the constant was
too low by one when `grind_signatures` is not set, as that may
result in a signature being one byte longer than we expect.
2024-09-03 15:09:32 +00:00
Matt Corallo
5a2372ce8e Add a test for the past few commits
This adds a single test for coin selection which exercises the
issues fixed in the past three commits.
2024-09-03 14:15:28 +00:00
Matt Corallo
b3644dcdb5 Drop bogus debug assertion that we don't overpay on fees
We should always select at least as many coins as is required to
meet the feerate target, but its perfectly fine if we overshoot.
Specifically, we may overshoot deliberately if we choose to burn
change to fee instead.
2024-09-03 14:15:28 +00:00
Matt Corallo
d383ac49a2 Handle under-coin-selecting due to an added OP_RETURN output
When we do coin selection for channel close anchor spends, we may
do coin selection targeting exactly the input values we need.
However, if coin selection does not include a change output, we may
add an OP_RETURN output, which may cause us to end up with less
fee than we wanted on the resulting package.

Here we address this issue by running coin selection twice - first
without seeking the extra weight of the OP_RETURN output, and again
if we find that we under-selected.
2024-09-03 14:15:28 +00:00
Matt Corallo
ff00c63171 Ensure we never try to broadcast a transaction <= 64 bytes
While these are consensus-valid, they have been nonstandard for
quite some time and will not relay nor confirm.
2024-09-03 14:13:43 +00:00
Matt Corallo
704078ac87 Specify imports manually in types::features::sealed
There's not a lot of reason to do this, but sadly the bindings
don't currently resolve wildcard imports at all, and I don't want
to deal with implementing it right now.
2024-09-01 01:08:38 +00:00
Matt Corallo
74ae8e9ef2
Merge pull request #3282 from TheBlueMatt/2024-08-fix-bench-logging
Dont output logs when benchmarking
2024-08-30 21:24:51 +00:00
Matt Corallo
ac4815abb6 Dont output logs when benchmarking
In 11ab302087 we accidentally removed
the `not(ldk_bench)` bound before outputting logs to stderr, which
we restore here. Instead of simply ignoring logs in benchmarks,
which we did previously, we instead format logs (in a way that LLVM
will not optimize out).
2024-08-30 18:42:04 +00:00
Matt Corallo
cdcab1ce1b Remove log level filtering in tests
There's no reason why we should be filtering our logs during tests.
It seems mostly like the `TestLogger` was written more as a sample
logger than a test logger, but these days we have samples, so we
should just drop the filtering and show everything.
2024-08-30 17:37:59 +00:00