Commit graph

5756 commits

Author SHA1 Message Date
jbesraa
4f45cdcad6 Implement from_str trait for NetAddress
- Add fuzz test for `NetAddress` `from_str` function
2023-09-06 19:25:30 +03:00
jbesraa
32a0113fda Fix indent in message_signing.rs 2023-09-06 15:07:25 +03:00
jbesraa
b2d3b94b17 Move zbase32 implementation to base32 file 2023-09-06 15:07:25 +03:00
jbesraa
d736ca8595 Add RFC4648 base32 encode and decode functions 2023-09-06 15:07:25 +03:00
Matt Corallo
e9d9711de4
Merge pull request #2522 from sr-gi/202308-set-feature
Adds a set of convenience methods to set non-custom features
2023-09-01 18:25:53 +00:00
Matt Corallo
ef8945e339
Merge pull request #2543 from optout21/txabort-typo
[minor] Fix wrong msg type in SendTxAbort, typo
2023-09-01 15:13:54 +00:00
Sergi Delgado Segura
992f1029ac Adds a set of convenience methods to set non-custom features
Currently only custom features can be set by specifying the feature bit. Add also the
ability to do so for regular features.
2023-09-01 11:30:21 +02:00
optout
8952446684
Fix wrong msg type in SendTxAbort, typo 2023-09-01 00:00:13 +02:00
Matt Corallo
073f0780f6
Merge pull request #2468 from jkczyz/2023-08-offer-payment-id
Offer outbound payments
2023-08-29 19:29:21 +00:00
Jeffrey Czyz
7a3e06b1e7
Include PaymentId in payer metadata
When receiving a BOLT 12 invoice originating from either an invoice
request or a refund, the invoice should only be paid once. To accomplish
this, require that the invoice includes an encrypted payment id in the
payer metadata. This allows ChannelManager to track a payment when
requesting but prior to receiving the invoice. Thus, it can determine if
the invoice has already been paid.
2023-08-29 11:08:11 -05:00
Jeffrey Czyz
861e0eee9e
Add a ChaCha20 utility for encrypting in place
Similar to ChaCha20::encrypt_single_block only encrypts in-place.
2023-08-29 11:08:11 -05:00
Jeffrey Czyz
4732484520
Add a ChaCha20 utility for encrypting a block
This hides an encryption implementation detail from callers.
2023-08-29 11:08:11 -05:00
Jeffrey Czyz
4fafae0733
Add an encryption key to ExpandedKey for Offers
Metadata such as the PaymentId should be encrypted when included in an
InvoiceRequest or a Refund, as it is user data and is exposed to the
payment recipient. Add an encryption key to ExpandedKey for this purpose
instead of reusing offers_base_key.
2023-08-29 11:08:11 -05:00
Jeffrey Czyz
971cb20d2e
Remove unnecessary #[allow(unused)] 2023-08-29 11:08:11 -05:00
Jeffrey Czyz
21fa551825
Split InvoiceRequest::verify_and_respond_using_derived_keys
InvoiceRequest::verify_and_respond_using_derived_keys takes a payment
hash. To avoid generating one for invoice requests that ultimately
cannot be verified, split the method into one for verifying and another
for responding.
2023-08-29 11:08:04 -05:00
Elias Rohrer
1f2ee2170f
Merge pull request #2531 from optout21/channel-id-breaking
Add ChannelId pending change note; formatting
2023-08-29 13:30:46 +02:00
Matt Corallo
e57fbba754
Merge pull request #2537 from TheBlueMatt/2023-08-one-less-feature-dep
Drop dep `tokio`'s `io-util` feat as it broke MSRV and isn't useful
2023-08-29 00:20:44 +00:00
Matt Corallo
afc5a02fc6 Pin the memchr test-only transitive dependency of regex 2023-08-28 21:16:54 +00:00
Matt Corallo
eb882a69b6 Drop dep tokio's io-util feat as it broke MSRV and isn't useful
We use `tokio`'s `io-util` feature to provide the
`Async{Read,Write}Ext` traits, which allow us to simply launch a
read future or `poll_write` directly as well as `split` the
`TcpStream` into a read/write half. However, these traits aren't
actually doing much for us - they are really just wrapping the
`readable` future (which we can trivially use ourselves) and
`poll_write` isn't doing anything for us that `poll_write_ready`
can't.

Similarly, the split logic is actually just `Arc`ing the
`TcpStream` and busy-waiting when an operation is busy to prevent
concurrent reads/writes. However, there's no reason to prevent
concurrent access at the stream level - we aren't ever concurrently
writing or reading (though we may concurrently read and write,
which is fine).

Worse, the `io-util` feature broke MSRV (though they're likely to
fix this upstream) and carries two additional dependencies (only
one on the latest upstream tokio).

Thus, we simply drop the dependency here.

Fixes #2527.
2023-08-28 21:16:54 +00:00
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
optout
d5d336f215
Add ChannelId pending change note; formatting 2023-08-28 07:20:23 +02: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
Matt Corallo
753f95870a
Merge pull request #2519 from Sharmalm/main
Print contents of our own channel updates for broadcast in non-gossip logs
2023-08-24 23:28:52 +00: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
189c1fbe2c Fail UTXO lookups if the block doesn't have five confirmations
The BOLT spec mandates that channels not be announced until they
have at least six confirmations. This is important to enforce not
because we particularly care about any specific DoS concerns, but
because if we do not we may have to handle reorgs of channel
funding transactions which change their SCID or have conflicting
SCIDs.
2023-08-23 21:48:03 +00:00
Matt Corallo
3482fceeab Add a simple naive block cache in gossip sync lookups 2023-08-23 21:48:03 +00:00
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
01857b51a1 Implement the UtxoSource interface for REST/RPC clients
In LDK, we expect users operating nodes on the public network to
implement the `UtxoSource` interface in order to validate the
gossip they receive from the network.

Sadly, because the DoS attack of flooding a node's gossip store
isn't a common issue, and because we do not provide an
implementation off-the-shelf to make doing so easily, many of our
downstream users do not have a `UtxoSource` implementation.

In order to change that, here we implement an async `UtxoSource`
in the `lightning-block-sync` crate, providing one for users who
sync the chain from Bitcoin Core's RPC or REST interfaces.
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