Commit graph

3545 commits

Author SHA1 Message Date
Matt Corallo
5626e21bea
Merge pull request #2536 from waterson/test-channel-signer
Rename EnforcingSigner to TestChannelSigner
2023-08-28 20:43:08 +00:00
Matt Corallo
2c4f82478e
Merge pull request #2528 from arik-so/arik/2023-08-2470-shorter-term-monitor-locks
Release monitor write lock in between update iterations
2023-08-28 17:07:03 +00:00
Chris Waterson
e38916d838 Rename EnforcingSigner to TestChannelSigner
Since the advent of VLS, EnforcingSigner is only used now for testing.
2023-08-28 09:48:35 -07:00
Arik Sosman
f80284cc88
Fix flaky aggregated HTLC revocation test.
Releasing write locks in between monitor updates
requires storing a set of cloned keys to iterate
over. For efficiency purposes, that set of keys
is an actual set, as opposed to array, which means
that the iteration order may not be consistent.

The test was relying on an event array index to
access the revocation transaction. We change that
to accessing a hash map keyed by the txid, fixing
the test.
2023-08-27 10:24:38 -07:00
Arik Sosman
c7a4949a25
Release write lock between monitor update iterations.
Previously, updating block data on a chain monitor
would acquire a write lock on all of its associated
channel monitors and not release it until the loop
completed.

Now, we instead acquire it on each iteration,
fixing #2470.
2023-08-27 10:24:37 -07:00
Matt Corallo
61d896d519
Merge pull request #2485 from optout21/channel-id-4struct1
Introduce new ChannelId struct
2023-08-27 05:18:00 +00:00
optout
e99e6ab562
Use new ChannelId type 2023-08-26 01:30:40 +02:00
optout
7a992ba40f
Add new ChannelId type; unused 2023-08-26 01:15:46 +02:00
Matt Corallo
afdcd1c198
Merge pull request #2197 from jbesraa/feat/lockable_score_rw
add another lock to lockable_score
2023-08-25 18:48:49 +00:00
Elias Rohrer
3dffe54258
Merge pull request #2248 from TheBlueMatt/2023-04-gossip-check
Implement the UtxoSource interface for REST/RPC clients
2023-08-25 14:10:39 +02:00
Elias Rohrer
d9eb201bd8
Merge pull request #2503 from valentinewallace/2023-08-fix-router-debug-panic
Fix debug panic in the case where a first hop has a channel with an introduction node
2023-08-25 12:46:37 +02:00
Elias Rohrer
af3a369ef1
Merge pull request #2466 from TheBlueMatt/2023-07-expose-success-prob
Expose the historical success probability calculation itself
2023-08-25 12:40:36 +02:00
jbesraa
3695b2aa13 Split LockableScore responsibilities between read & write operations
- Split Score from LockableScore to ScoreLookUp to handle read
      operations and ScoreUpdate to handle write operations
    - Change all struct that implemented Score to implement ScoreLookUp
      and/or ScoreUpdate
    - Change Mutex's to RwLocks to allow multiple data readers
    - Change LockableScore to Deref in ScorerAccountingForInFlightHtlcs
      as we only need to read
    - Add ScoreLookUp and ScoreUpdate docs
    - Remove reference(&'a) and Sized from Score in ScorerAccountingForInFlightHtlcs
      as Score implements Deref
    - Split MultiThreadedScoreLock into MultiThreadedScoreLockWrite and MultiThreadedScoreLockRead.
      After splitting LockableScore, we split MultiThreadedScoreLock following
      the same way, splitting a single score into two srtucts, one for read and
      other for write.
      MultiThreadedScoreLock is used in c_bindings.
2023-08-25 04:35:11 +03:00
Valentine Wallace
c9f5a75c8e
Router: account for blinded path fee, etc on first_hop<>intro hop add
This previously led to a debug panic in the router because we wouldn't account
for the blinded path fee when calculating first_hop<>intro_node hop's available
liquidity and construct an invalid path that forwarded more over said hop than
was actually available.

This also led to us hitting unreachable code, see direct_to_matching_intro_nodes
test description.
2023-08-24 11:38:30 -04:00
Lalitmohansharma1
b1abf32937 improving message in log 2023-08-24 20:21:08 +05:30
Matt Corallo
b315856e68 Make the P2PGossipSync UtxoLookup exchangable without &mut self
Because a `UtxoLookup` implementation is likely to need a reference
to the `PeerManager` which contains a reference to the
`P2PGossipSync`, it is likely to be impossible to get a mutable
reference to the `P2PGossipSync` by the time we want to add a
`UtxoLookup` without a ton of boilerplate and trait wrapping.

Instead, we simply place the `UtxoLookup` in a `RwLock`, allowing
us to modify it without a mutable self reference.

The lifetime bounds updates in tests required in this commit are
entirely unclear to me, but do allow tests to continue building, so
somehow make rustc happier.
2023-08-23 21:48:03 +00:00
Matt Corallo
bbe20c3327
Merge pull request #2515 from TheBlueMatt/2023-08-earlier-payment-hash-log
Include payment hash in more early payment logs
2023-08-23 21:46:23 +00:00
Matt Corallo
2bd2637b7e Store a HistoricalMinMaxBuckets in DirectedChannelLiquidity
This removes the need to reconstruct the struct in a number of
places by simply creating it up front.
2023-08-23 21:15:11 +00:00
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