Commit graph

5564 commits

Author SHA1 Message Date
Matt Corallo
d557334e31 Rename soonest_conf_deadline to counterparty_spendable_height
This renames the field in `PackageTemplate` which describes the
height at which a counterparty can make a claim to an output to
match its actual use.

Previously it had been set based on when a counterparty can claim
an output but also used for other purposes. In the previous commit
we cleaned up its use for fee-bumping-rate, so here we can rename
it as it is now only used as the `counteraprty_spendable_height`.
2024-10-17 18:34:33 +00:00
Matt Corallo
be915872c5 Clean up PackageTemplate::get_height_timer to consider type
`PackageTemplate::get_height_timer` is used to decide when to next
bump our feerate on claims which need to make it on chain within
some window. It does so by comparing the current height with some
deadline and increasing the bump rate as the deadline approaches.

However, the deadline used is the `counterparty_spendable_height`,
which is the height at which the counterparty might be able to
spend the same output, irrespective of why. This doesn't make sense
for all output types, for example outbound HTLCs are spendable by
our counteraprty immediately (by revealing the preimage), but we
don't need to get our HTLC timeout claims confirmed immedaitely,
as we actually have `MIN_CLTV_EXPIRY` blocks before the inbound
edge of a forwarded HTLC becomes claimable by our (other)
counterparty.

Thus, here, we adapt `get_height_timer` to look at the type of
output being claimed, and adjust the rate at which we bump the fee
according to the real deadline.
2024-10-17 18:34:33 +00:00
Matt Corallo
303a0c9a4e Stop passing current height to PackageTemplate::build_package
Now that we don't store the confirmation height of the inputs
being spent, passing the current height to
`PackageTemplate::build_package` is useless - we only use it to set
the height at which we should next bump the fee, but we just want
it to be "next block", so we might as well use `0` and avoid the
extra argument. Further, in one case we were already passing `0`,
so passing the argument is just confusing as we can't rely on it
being set.

Note that this does remove an assertion that we never merge
packages that were crated at different heights, and in the future
we may wish to do that (as there's no specific reason not to), but
we do not currently change the behavior.
2024-10-17 18:34:33 +00:00
Matt Corallo
8c4794df87 Drop unused PackageTemplate::height_original
This has never been used, and its set to a fixed value of zero for
HTLCs on local commitment transactions making it impossible to rely
on so might as well remove it.
2024-10-17 18:34:33 +00:00
Matt Corallo
4a7b01aea7
Merge pull request #3371 from tnull/2024-10-allow-to-set-payment-and-description-hash
Invoice utils: allow to set both description hash and payment hash
2024-10-17 15:33:22 +00:00
Matt Corallo
0c0cb6fccb Don't bump the next_node_counter when using a removed counter
If we manage to pull a `node_counter` from `removed_node_counters`
for reuse, `add_channel_between_nodes` would `unwrap_or` with the
`next_node_counter`-incremented value. This visually looks right,
except `unwrap_or` is always called, causing us to always increment
`next_node_counter` even if we don't use it.

This will result in the `node_counter`s always growing any time we
add a new node to our graph, leading to somewhat larger memory
usage when routing and a debug assertion failure in
`test_node_counter_consistency`.

The fix is trivial, this is what `unwrap_or_else` is for.
2024-10-16 22:45:10 +00:00
Matt Corallo
a19edbc32d Rename PackageTemplate::timelock counteraprty_spendable_height
This function was very confusing - its used to determine by when
we have to stop aggregating this claim with others as it starts to
be at risk of pinning due to the counterparty's ability to spend
the output.

It is not ever used as a timelock for a transaction, and thus its
name is very confusing.

Instead we rename it `counterparty_spendable_height`.
2024-10-16 21:04:48 +00:00
Matt Corallo
2f549eeb80 Rename claim cleaning match bool for accuracy
We don't actually care if a confirmed transaction claimed other
outputs, only that it claimed a superset of the outputs in the
pending claim we're looking at. Thus, the variable to detect that
is renamed `is_claim_subset_of_tx` instead of `are_sets_equal`.
2024-10-16 21:04:48 +00:00
Elias Rohrer
43fd78b0b9
Invoice utils: allow to set both description hash and payment hash 2024-10-16 17:04:38 +02:00
optout
f22b011f93 Signer extended with method to sign prev funding transaction input 2024-10-15 23:13:14 +02:00
Gursharan Singh
0db051b75a
Merge pull request #3329 from arik-so/monitor_archive_docs_followup
Document monitor archival idempotency requirement (#3276 followup)
2024-10-15 13:54:46 -07:00
Matt Corallo
57dcc7d762 Deprecate the lightning::util::string re-export from types
Like we've done for `features` and `payment`, here we mark the
`lightning::util::string` re-export as deprecated.
2024-10-15 14:33:03 +00:00
Matt Corallo
50b5a6efa7 Drop the Payment{Hash,Preimage,Secret} re-exports in lightning
These re-exports were deprecated in 0.0.124 in favor of the
`lightning::types::payment::*` paths, which we use here.
2024-10-15 14:33:03 +00:00
Matt Corallo
41a91a395a Don't interpret decayed data as we've failed to send tiny values
When we're calculating the success probability for min-/max-bucket
pairs and are looking at the 0th' min-bucket, we only look at the
highest max-bucket to decide the success probability. We ignore
max-buckets which have a value below `BUCKET_FIXED_POINT_ONE` to
only consider values which aren't substantially decayed.

However, if all of our data is substantially decayed, this filter
causes us to conclude that the highest max-bucket is bucket zero
even though we really should then be looking at any bucket.

We make this change here, looking at the highest non-zero
max-bucket if no max-buckets have a value above
`BUCKET_FIXED_POINT_ONE`.
2024-10-14 19:38:16 +00:00
Matt Corallo
1486b1bde2 Set holder_commitment_point to Available on upgrade
When we upgrade from LDK 0.0.123 or prior, we need to intialize
`holder_commitment_point` with commitment point(s). In
1f7f3a366c we changed the point(s)
which we fetch from both the current and next per-commitment-point
(setting the value to `HolderCommitmentPoint::Available` on
upgrade) to only fetching the current per-commitment-point (setting
the value to `HolderCommitmentPoint::PendingNext` on upgrade).

In `commitment_signed` handling, we expect the next
per-commitment-point to be available (allowing us to `advance()`
the `holder_commitment_point`), as it was included in the
`revoke_and_ack` we most recently sent to our peer, so must've been
available at that time.

Sadly, these two interact negatively with each other - on upgrade,
assuming the channel is at a steady state and there are no pending
updates, we'll not make the next per-commitment-point available but
if we receive a `commitment_signed` from our peer we'll assume it
is. As a result, in debug mode, we'll hit an assertion failure, and
in production mode we'll force-close the channel.

Instead, here, we fix the upgrade logic to always upgrade directly
to `HolderCommitmentPoint::Available`, making the next
per-commitment-point available immediately.

We also attempt to resolve the next per-commitment-point in
`get_channel_reestablish`, allowing any channels which were
upgraded to LDK 0.0.124 and are in this broken state to avoid the
force-closure, as long as they don't receive a `commitment_signed`
in the interim.
2024-10-14 19:36:23 +00:00
Matt Corallo
64c12431b7 Drop lightning::ln::features::* type aliases
These were deprecated in 0.0.124, and we drop them here in favor of
`lightning::types::features::*`.
2024-10-13 13:52:56 +00:00
Arik Sosman
268675a743
Document monitor archival idempotency requirement. 2024-10-11 09:44:38 -07:00
Matt Corallo
ad19d93180
Merge pull request #3349 from TheBlueMatt/2024-10-3270-followups
Minor #3270 Followups
2024-10-11 13:47:39 +00:00
Matt Corallo
a952d2d3d3
Merge pull request #3346 from TheBlueMatt/2024-10-dns-feature-flag
Add support for parsing the dns_resolver feature bit
2024-10-08 19:46:11 +00:00
Matt Corallo
f94bf98612
Merge pull request #3235 from Mirebella/add-local-balance-msats
Add `last_local_balance_msats` field
2024-10-08 17:56:46 +00:00
Mirebella
5d48d588ef Add Event::ChannelClosed::last_local_balance_msats
Users commonly want to know what their balance was when a channel
was closed, which this provides in a somewhat simplified manner.

It does not consider pending HTLCs and will always overstate our
balance by transaction fees.
2024-10-08 15:28:58 +00:00
Leo Nash
9e30f2560d Stop sending channel_update in onion failures
Per <https://github.com/lightning/bolts/pull/1173>.

Fixes #3277
2024-10-05 03:39:06 +00:00
Matt Corallo
0abf068ad1 Drop one unnecessary allocation added in aa2f6b47df
In aa2f6b47df we refactored
`lightning-invoice` de/serialization to use the new version of
`bech32`, but ended up adding one unnecessary allocation in our
offers logic, which we drop here.
2024-10-03 17:23:32 +00:00
Matt Corallo
bc1931bd0b
Merge pull request #3270 from optout21/bech32-iterser
Upgrade bech32 dependency (iterative)
2024-10-03 17:02:55 +00:00
optout
aa2f6b47df
Upgrade bech32 dependency, bech32 serialization improvements 2024-10-02 21:21:07 +02:00
Matt Corallo
457b634d09 Allow a DNSResolverMessageHandler to set dns_resolver feature
A `DNSResolverMessageHandler` which handles resolution requests
should want the `NodeFeatures` included in the node's
`node_announcement` to include `dns_resolver` to indicate to the
world that it provides that service. Here we enable this by
requesting extra feature flags from the `DNSResolverMessageHandler`
in the features `OnionMessenger`, in turn, provides to
`PeerManager` (which builds the `node_announcement`).
2024-10-02 18:24:40 +00:00
Arik
d49a08a824
Merge pull request #3179 from TheBlueMatt/2024-07-human-readable-names-resolution-1
Add the core functionality required to resolve Human Readable Names
2024-10-02 10:00:13 -07:00
Matt Corallo
605952cefd
Merge pull request #3301 from dunxen/2024-9-fixnevertypefallback
Add an explicit_type TLV syntax for avoiding certain cases of type inference
2024-10-02 14:29:09 +00:00
Duncan Dean
c0d84e85c7
Add an explicit_type TLV syntax for avoiding certain cases of type inference
This new syntax is used to fix "dependency on fallback of ! -> ()".
This avoids cases where code compiles with a fallback of the
never type leading to the unit type. The behaviour in Rust edition 2024
would make this a compile error.

See: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/builtin/static.DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK.html#
2024-10-02 13:08:04 +02:00
Matt Corallo
d13f336d16 Use a MessageSendEvent-handling fn rather than a single lopp
Rather than building a single `Vec` of `MessageSendEvent`s to
handle then iterating over them, we move the body of the loop into
a lambda and run the loop twice. In some cases, this may save a
single allocation, but more importantly it sets us up for the next
commit, which needs to know from which handler the
`MessageSendEvent` it is processing came from.
2024-10-01 16:49:38 +00:00
Matt Corallo
4147de2cf0
Merge pull request #3324 from tnull/2024-09-rustfmt-util-1
`rustfmt`: Run on `util/*` (1/2)
2024-10-01 15:33:17 +00:00
Matt Corallo
c7627dfd61
Merge pull request #3311 from TheBlueMatt/2024-09-3010-followups
Quick #3010 followups
2024-09-30 21:21:20 +00:00
Matt Corallo
d156b2e30e Call ChannelMessageHandler::message_received without peer lock
While `message_received` purports to be called on every message,
prior to the message, doing so on `Init` messages means we have to
call `message_received` while holding the per-peer mutex, which
can cause some lock contention.

Instead, here, we call `message_received` after processing `Init`
messages (which is probably more useful anyway - the peer isn't
really "connected" until we've processed the `Init` messages),
allowing us to call it unlocked.
2024-09-30 18:57:52 +00:00
Matt Corallo
b8695b0c83 Check that we aren't reading a second message in BOLT 12 retry test
`creates_and_pays_for_offer_with_retry` intends to check that we
re-send a BOLT 12 `invoice_request` in response to a
`message_received` call, but doesn't actually test that there were
no messages in the outbound buffer after the initial send, which we
do here.
2024-09-30 18:57:52 +00:00
Matt Corallo
9335c9bbf7 Add the core functionality required to resolve Human Readable Names
This adds a new utility struct, `OMNameResolver`, which implements
the core functionality required to resolve Human Readable Names,
namely generating `DNSSECQuery` onion messages, tracking the state
of requests, and ultimately receiving and verifying `DNSSECProof`
onion messages.

It tracks pending requests with a `PaymentId`, allowing for easy
integration into `ChannelManager` in a coming commit - mapping
received proofs to `PaymentId`s which we can then complete by
handing them `Offer`s to pay.

It does not, directly, implement `DNSResolverMessageHandler`, but
an implementation of `DNSResolverMessageHandler` becomes trivial
with `OMNameResolver` handling the inbound messages and creating
the messages to send.
2024-09-30 18:04:01 +00:00
Matt Corallo
829dc34d10 Allow _ in Hostnames
These are perfectly fine and are relied on by BIP 353, so we need
to ensure we allow them.
2024-09-30 18:04:01 +00:00
Matt Corallo
75d20e5a5c Add a type to track HumanReadableNames
BIP 353 `HumanReadableName`s are represented as `â‚¿user@domain` and
can be resolved using DNS into a `bitcoin:` URI. In the next
commit, we will add such a resolver using onion messages to fetch
records from the DNS, which will rely on this new type to get name
information from outside LDK.
2024-09-30 16:19:33 +00:00
Matt Corallo
ebde296abd Parse and handle DNSResolverMessages in OnionMessenger
This adds the requisite message parsing and handling code for the
new DNSSEC messages to `OnionMessenger`.
2024-09-30 16:19:33 +00:00
Matt Corallo
1cf0393056 Add DNS(SEC) query and proof messages and onion message handler
This creates the initial DNSSEC proof and query messages in a new
module in `onion_message`, as well as a new message handler to
handle them.

In the coming commits, a default implementation will be added which
verifies DNSSEC proofs which can be used to resolve BIP 353 URIs
without relying on anything outside of the lightning network.
2024-09-30 16:19:31 +00:00
Matt Corallo
151a8a1aaf Add a MessageContext::DNSResolution to protect against probing
When we make a DNSSEC query with a reply path, we don't want to
allow the DNS resolver to attempt to respond to various nodes to
try to detect (through timining or other analysis) whether we were
the one who made the query. Thus, we need to include a nonce in the
context in our reply path, which we set up here by creating a new
context type for DNS resolutions.
2024-09-30 16:19:31 +00:00
Matt Corallo
bc5213dfef Minor gossip.rs rustfmt cleanups
Just a few minor updates to `gossip.rs` to reduce code verticality
and simplify things a bit.
2024-09-26 06:45:50 +00:00
Elias Rohrer
22b82d36e2
rustfmt: Run on routing/gossip.rs 2024-09-24 13:51:52 +09:00
Elias Rohrer
a0d0f02ed0
Merge pull request #3303 from TheBlueMatt/2024-09-inbound-payment-id
Add a `PaymentId` for inbound payments
2024-09-24 13:38:16 +09:00
Matt Corallo
23109b66e9
Merge pull request #3310 from TheBlueMatt/2024-09-unlocked-checksig
Validate `channel_update` signatures without holding a graph lock
2024-09-24 03:13:51 +00:00
Matt Corallo
131849f383 Validate channel_update signatures without holding a graph lock
We often process many gossip messages in parallel across different
peer connections, making the `NetworkGraph` mutexes fairly
contention-sensitive (not to mention the potential that we want to
send a payment and need to find a path to do so).

Because we need to look up a node's public key to validate a
signature on `channel_update` messages, we always need to take a
`NetworkGraph::channels` lock before we can validate the message.

For simplicity, and to avoid taking a lock twice, we'd always
validated the `channel_update` signature while holding the same
lock, but here we address the contention issues by doing a
`channel_update` validation in three stages.

First we take a read lock on `NetworkGraph::channels` and check if
the `channel_update` is new, then release the lock and validate the
message signature, and finally take a write lock, (re-check if the
`channel_update` is new) and update the graph.
2024-09-23 03:48:29 +00:00
Jeffrey Czyz
cad09855bf
De-couple MessageRouter from Router
Now that ChannelManager is parameterized by both a MessageRouter and a
Router, Router implementations no longer need to implement
MessageRouter, too.
2024-09-23 12:22:01 +09:00
Jeffrey Czyz
bde331fe94
Expand DefaultRouter's privacy docs
DefaultRouter::create_blinded_payment_paths may creat a one-hop blinded
path with the recipient as the introduction node. Update the privacy
section of DefaultRouter's docs to indicate this as is done in the docs
for DefaultMessageRouter.
2024-09-23 12:22:00 +09:00
Jeffrey Czyz
04c51b380d
Parameterize ChannelManager with MessageRouter
ChannelManager is parameterized by a Router, which must also implement
MessageRouter. Instead, add a MessageRouter parameter such that the
Router and MessageRouter traits can be de-coupled. This simplifies using
something other than DefaultMessageRouter, which DefaultRouter currently
delegates to.
2024-09-23 12:21:35 +09:00
Matt Corallo
aaf529d193 Add a PaymentId for inbound payments
We expect our users to have fully idempotent `Event` handling as we
may replay events on restart for one of a number of reasons. This
isn't a big deal as long as all our events have some kind of
identifier users can use to check if the `Event` has already been
handled.

For outbound payments, this is the `PaymentId` they provide in the
send methods, however for inbound payments we don't have a great
option.

`PaymentHash` largely suffices - users can simply always claim in
response to a `PaymentClaimable` of sufficient value and treat a
`PaymentClaimed` event as duplicate any time they see a second one
for the same `PaymentHash`. This mostly works, but may result in
accepting duplicative payments if someone (incorrectly) pays twice
for the same `PaymentHash`.

Users could also fail for duplicative `PaymentClaimable` events of
the same `PaymentHash`, but doing so may result in spuriously
failing a payment if the `PaymentClaimable` event is a replay and
they never saw a corresponding `PaymentClaimed` event.

While none of this will result in spuriously thinking they've been
paid when they have not, it does result in some pretty awkward
semantics which we'd rather avoid our users having to deal with.

Instead, here, we add a new `PaymentId` which is simply an HMAC of
the HTLCs (as Channel ID, HTLC ID pairs) which were included in the
payment.
2024-09-23 01:24:28 +00:00
Matt Corallo
aa09c33a17 Add an inbound_payment_id_secret to ChannelManager
In the next commit we'll start generating `PaymentId`s for inbound
payments randomly by HMAC'ing the HTLC set of the payment. Here we
start by defining the HMAC secret for these HMACs.

This requires one small test adaptation and a full_stack_target
fuzz change because it changes the RNG consumption.
2024-09-23 01:24:28 +00:00