Commit graph

5764 commits

Author SHA1 Message Date
Matt Corallo
2a1dff4c10 Move the bucketed history tracking logic into a scoring submodule 2023-08-23 21:15:11 +00:00
Matt Corallo
534d7317cf Expose the historical success probability calculation itself
In 3f32f60ae7 we exposed the
historical success probability buckets directly, with a long method
doc explaining how to use it. While this is great for logging
exactly what the internal model thinks, its also helpful to let
users know what the internal model thinks the success probability
is directly, allowing them to compare route success probabilities.

Here we do so but only for the historical tracking buckets.
2023-08-23 21:15:11 +00:00
Matt Corallo
568731008e Find payment bucket in calculate_success_probability_times_billion
This simply moves code which will simplify the next commit
somewhat.
2023-08-23 21:15:11 +00:00
Matt Corallo
c4947acaec Correctly apply penalty bounds on the per-amount penalties
When we attempt to score a channel which has a success probability
very low, we may have a log well above our cut-off of two. For the
liquidity penalties this works great, we bound it by
`NEGATIVE_LOG10_UPPER_BOUND` and `min` the two scores. For the
amount liquidity penalty we didn't do any `min`ing at all.

This fix is to min the log itself first and then reuse the min'd
log in both calculations.
2023-08-23 21:15:11 +00:00
Matt Corallo
86976e0003 Don't rely on calculate_success_probability* to handle amt > cap
Currently we let an `htlc_amount >= channel_capacity` pass through
from `penalty_msat` to
`calculate_success_probability_times_billion`, but only if its only
marginally bigger (less than 65/64ths). This is fine as
`calculate_success_probability_times_billion` handles bogus values
just fine (it will always return a zero probability in such cases).

However, this is risky, and in fact breaks in the coming commits,
so instead check it before ever calling through to the historical
bucket probability calculations.
2023-08-23 21:15:11 +00:00
Matt Corallo
32d6e91fd6
Merge pull request #2337 from alecchendev/2023-06-watchtower-support
Support third-party watchtowers in persistence pipeline
2023-08-23 20:05:40 +00:00
Matt Corallo
0211daa48b
Merge pull request #2412 from valentinewallace/2023-07-construct-blinded-paths
Add API for constructing blinded payment paths
2023-08-23 17:35:06 +00:00
Alec Chen
b20b1dbe67
Test justice tx formation from persistence
Here we implement `WatchtowerPersister`, which provides a test-only
sample implementation of `Persist` similar to how we might imagine a
user to build watchtower-like functionality in the persistence pipeline.

We test that the `WatchtowerPersister` is able to successfully build and
sign a valid justice transaction that sweeps a counterparty's funds if
they broadcast an old commitment.
2023-08-23 12:33:16 -05:00
Alec Chen
2cb2557669
Enable signing a justice tx using the channel monitor 2023-08-23 12:33:11 -05:00
Alec Chen
04475c809e
Expose revokeable output index and building a justice tx from commitment
For watchtowers to be able to build justice transactions for our
counterparty's revoked commitments, they need to be able to find the
revokeable output for them to sweep. Here we cache `to_self_delay` in
`CommitmentTransaction` to allow for finding this output on the struct
directly. We also add a simple helper method to aid in building the
initial spending transaction.

This also adds a unit test for both of these helpers, and
refactors a bit of a previous `CommitmentTransaction` unit test to make
adding these easier.
2023-08-23 12:33:08 -05:00
Alec Chen
75c058670c
Enable monitor to rebuild initial counterparty commitment tx
Upon creating a channel monitor, it is provided with the initial
counterparty commitment transaction info directly before the very first
time it is persisted. Because of this, the very first counterparty
commitment is not seen as an update in the persistence pipeline, and so
our previous changes to the monitor and updates cannot be used to
reconstruct this commitment.

To be able to expose the counterparty's transaction for the very first
commitment, we add a thin wrapper around
`provide_latest_counterparty_commitment_tx`, that stores the necessary
data needed to reconstruct the initial commitment transaction in the
monitor.
2023-08-23 12:33:07 -05:00
Alec Chen
966465a282
Build and expose counterparty commitments from monitor update 2023-08-23 12:33:00 -05:00
Matt Corallo
5a1f212d03 Remove redundant payment preimag hashing in HTLC claim pipeline
Currently, when we receive an HTLC claim from a peer, we first hash
the preimage they gave us before removing the HTLC, then
immediately pass the preimage to the inbound channel and hash the
preimage again before removing the HTLC and sending our peer an
`update_fulfill_htlc`. This second hash is actually only asserted
on, never used in any meaningful way as we have the htlc data
present in the same code.

Here we simply drop this second hash and move it into a
`debug_assert`.
2023-08-23 16:45:15 +00:00
Matt Corallo
9e69922729 Include payment hash in more early payment logs
If a user has issues with a payment, the most obvious thing they'll
do is check logs for the payment hash. Thus, we should ensure our
logs that show a payment's lifecycle include the payment hash and
are emitted (a) as soon as LDK learns of the payment, (b) once the
payment goes out to the peer (which is already reasonably covered
in the commitment transaction building logs) and (c) when the
payment ultimately is fulfilled or fails.

Here we improve our logs for both (a) and (c).
2023-08-23 16:45:15 +00:00
Alec Chen
543ad4fd23
Add feerate and balances to LatestCounterpartyCommitmentTXInfo
This adds the feerate and local and remote output values to this channel
monitor update step so that a monitor can reconstruct the counterparty's
commitment transaction from an update. These commitment transactions
will be exposed to users in the following commits to support third-party
watchtowers in the persistence pipeline.

With only the HTLC outputs currently available in the monitor update, we
can tell how much of the channel balance is in-flight and towards which
side, however it doesn't tell us the amount that resides on either side.
Because of dust, we can't reliably derive the remote value from the
local value and visa versa. Thus, it seems these are the minimum fields
that need to be added.
2023-08-23 10:48:19 -05:00
valentinewallace
0c250468d6
Merge pull request #2492 from optout21/payment-hash-display
[minor] Add Display to Payment ID types
2023-08-23 11:32:46 -04:00
Valentine Wallace
ea84f2ac73
Document _init_and_read_* ser macro requirements 2023-08-23 11:28:42 -04:00
Valentine Wallace
ebb0676e85
Fix documentation on onion message packet ControlTlvs 2023-08-23 11:28:42 -04:00
Valentine Wallace
0ddd3cb684
Blinded paths: rename encrypted_tlvs_ss to *_rho for precision
The previous name can be confused for the shared secret that the rho is derived
from.
2023-08-23 11:28:42 -04:00
Valentine Wallace
76f8cc1cc6
Support constructing BlindedPaths for payments. 2023-08-23 11:28:41 -04:00
Valentine Wallace
d224f980ed
Simplify onion message blinded hop construction
Also adds a util for general blinded hop creation to be reused for blinded
payment paths.
2023-08-23 11:26:45 -04:00
Valentine Wallace
cf64e3fba5
Add new _init_and_read_tlv_stream ser macro
Useful for when you want to use _init_and_read_len_prefixed_tlv_fields but there is no
length byte at the start of the TLV stream.
2023-08-23 11:24:54 -04:00
optout
4146264b16
Use Display of PaymentId&PaymentPreimage; avoid log_bytes macro 2023-08-23 06:03:15 +02:00
Arik
8866ed3533
Merge pull request #2441 from arik-so/2023-07-taproot-signer-wrapped
Wrapped Channel Signer Type
2023-08-22 17:49:24 -07:00
Arik Sosman
6a2f43d2ca
Remove unused imports.
Remove a bunch of unnecessary ChannelManager
imports.
2023-08-22 14:28:40 -07:00
Arik Sosman
b609bd9249
Introduce ChannelSignerType.
Rather than using a holder_signer of a specific
signer type in Channel and ChannelContext, this
allows us to hold an enum such that depending on
the type of channel, the appropriate signer could
be held in its respective variant.

Doing so required the reparametrization of Channel
from using a Signer to using the SignerProvider
trait. This percolated down to the ChannelManager
and multiple tests.

Now, when accessign various signer methods, there
is a distinction between accessing methods defined
for all signers on ChannelSigner, and accessing
type-specific methods using accessors such as
`as_ecdsa`.
2023-08-22 14:28:40 -07:00
Arik Sosman
d256a2b329
Fix bench lifetimes.
Benchmarks were failing because node config and
channel monitor configs were tied to the same
lifetime.

Introducing a separate lifetime allows to avoid
out-of-order deallocation errors.
2023-08-22 14:25:23 -07:00
Arik Sosman
5e6bc76191
Add Taproot feature support.
Introduce a Taproot feature on bits 30/31 for
initialization, node, and channel type contexts.
2023-08-22 14:25:09 -07:00
Arik Sosman
43a9215b79
Fix persister/chain_monitor lifetimes.
The persister and chain_monitor variables must
be declared before the node channel manager is
initialized to avoid out of order deallocation.
2023-08-22 14:23:55 -07:00
Matt Corallo
e9be7e272f
Merge pull request #2511 from jbesraa/add-channel-id-to-spendableoutputs-event
Add channel_id to SpendableOutputs event
2023-08-22 20:38:40 +00:00
valentinewallace
0b196ebae6
Merge pull request #2432 from jkczyz/2023-07-bolt12-node-signer
Support signing BOLT 12 messages in `NodeSigner`
2023-08-22 16:22:16 -04:00
Valentine Wallace
4a30d9e78a
Rename ser macro
We want a similar macro for reading TLV streams without a length prefix, so
rename this one to disambiguate.
2023-08-22 13:26:12 -04:00
Valentine Wallace
9777485ed7
Minor BlindedHop docs update 2023-08-22 13:26:12 -04:00
Valentine Wallace
7c1726b585
Update blinded path util to take iterator instead of slice
Useful for blinded payment path construction.
2023-08-22 13:26:12 -04:00
Valentine Wallace
1b356619b3
Move Padding into blinded_path module for use in blinded payments 2023-08-22 13:26:12 -04:00
Valentine Wallace
fe5a076aa6
Move blinded message path util into message submodule 2023-08-22 13:26:11 -04:00
Valentine Wallace
381cc646c6
Move some blinded path message code into message submodule.
We'll similarly separate blinded path payments code into its own module.
2023-08-22 13:18:42 -04:00
Valentine Wallace
a5b7cf2c69
Move blinded path util into blinded_path::utils
This way it can be more easily reused for blinded payment paths.
2023-08-22 13:18:42 -04:00
Matt Corallo
4fb5708eec
Merge pull request #2411 from valentinewallace/2023-07-blinded-onion-keys
Support constructing blinded path onion keys
2023-08-22 17:10:59 +00:00
optout
b35b8cfbf4 Add Display to PaymentId & PaymentPreimage 2023-08-22 18:16:55 +02:00
optout
513c2b4e4b Use Display of PaymentHash; avoid log_bytes macro 2023-08-22 18:16:50 +02:00
optout
a545683a63 Add Display to PaymentHash 2023-08-22 18:13:26 +02:00
jbesraa
14b761283b Add channel_id to SpendableOutputs event
This will make it possible to
    link between SpendableOuts and ChannelMonitor

    - change channel_id to option so we dont break upgrade
    - remove unused channel_id
    - document channel_id
    - extract channel id dynamically to pass test
    - use contains to check channel_id in test as the events are not ordered
    - update docs framing
    - specify ldk version channel_id will be introduced in

Co-authored-by: Elias Rohrer <dev@tnull.de>

Update lightning/src/events/mod.rs

Co-authored-by: Elias Rohrer <dev@tnull.de>
2023-08-22 17:07:13 +03:00
Elias Rohrer
8f024303e7
Merge pull request #2507 from TheBlueMatt/2023-08-lnd-6039
Work around LND bug 6039
2023-08-22 10:20:02 +02:00
Jeffrey Czyz
39012e3595
Support signing BOLT 12 invoices in NodeSigner
BOLT 12 messages need to be signed in the following scenarios:
- constructing an InvoiceRequest after scanning an Offer,
- constructing an Invoice after scanning a Refund, and
- constructing an Invoice when handling an InvoiceRequest.

Extend the NodeSigner trait to support signing BOLT 12 invoices such
that it can be used in the latter contexts. The method could be used
in an OffersMessageHandler.
2023-08-21 19:14:29 -05:00
Jeffrey Czyz
63d0d5583d
Use TaggedHash in merkle::verify_signature
An earlier commit introduced TaggedHash for use in sign_message. For
consistency, use it in verify_signature, too.
2023-08-21 19:14:29 -05:00
Jeffrey Czyz
7f641da655
Expose Offer/InvoiceRequest methods in Invoice
Bolt12Invoice can either be for an Offer (via an InvoiceRequest) or a
Refund. It wraps those types, so expose their methods on both
Bolt12Invoice and UnsignedBolt12Invoice.

Since Refund does not have all the Offer/InvoiceRequest methods, use an
Option return type such that None can returned for refund-based
invoices.

For methods that are duplicated between Offer/InvoiceRequest and
Bolt12Invoice, prefer the (non-Option, if applicable) method from
Bolt12Invoice (e.g., amount_msats, signing_pubkey).
2023-08-21 19:14:29 -05:00
Jeffrey Czyz
57e62da9f4
Expose invoice accessors in UnsignedBolt12Invoice 2023-08-21 19:14:29 -05:00
Jeffrey Czyz
bde982344a
Expose Offer accessor functions in InvoiceRequest
Also, expose both Offer and InvoiceRequest functions in
UnsignedInvoiceRequest.
2023-08-21 19:14:29 -05:00
Jeffrey Czyz
9d02d06e06
Macro-ize InvoiceRequest accessors for reuse
Various messages wrap InvoiceRequestContents, which shouldn't be exposed
as it is an implementation detail. Define a macro for InvoiceRequest
accessor methods so that these messages can also define them.
2023-08-21 19:14:28 -05:00