Commit Graph

585 Commits

Author SHA1 Message Date
Valentine Wallace
efed905a4f
Move blinded_path and its utils into a new module 2023-04-20 10:14:15 -04:00
Matt Corallo
dddb2e28c1 Replace PaymentSecret with RecipientOnionFields in the pub API
This moves the public payment sending API from passing an explicit
`PaymentSecret` to a new `RecipientOnionFields` struct (which
currently only contains the `PaymentSecret`). This gives us
substantial additional flexibility as we look at add both
`PaymentMetadata`, a new (well, year-or-two-old) BOLT11 invoice
extension to provide additional data sent to the recipient.

In the future, we should also add the ability to add custom TLV
entries in the `RecipientOnionFields` struct.
2023-04-05 16:28:14 +00:00
Elias Rohrer
9873c7dad8
Add ChannelPending event emitted upon funding_signed
Currently, users don't have good way of being notified when channel open
negotiations have succeeded and new channels are pending confirmation on
chain. To this end, we add a new `ChannelPending` event that is emitted
when send or receive a `funding_signed` message, i.e., at the last
moment before waiting for the confirmation period.

We track whether the event had previously been emitted in `Channel` and
remove it from `internal_funding_created` entirely. Hence, we now
only emit the event after ChannelMonitorUpdate completion, or upon
channel reestablish. This mitigates a race condition where where we
wouldn't persist the event *and* wouldn't regenerate it on restart,
therefore potentially losing it, if async CMU wouldn't complete before
ChannelManager persistence.
2023-04-03 19:04:32 +02:00
Wilmer Paulino
ca9ca75f08
Move events.rs into its own top-level module
This is largely motivated by some follow-up work for anchors that will
introduce an event handler for `BumpTransaction` events, which we can
now include in this new top-level `events` module.
2023-03-22 11:49:33 -07:00
Matt Corallo
ea15f0f448
Merge pull request #2100 from douglaz/docs_fixes
Docs improvements
2023-03-21 18:44:23 +00:00
Allan Douglas R. de Oliveira
963d6c4a51 Docs improvements 2023-03-21 14:11:13 +00:00
John Cantrell
d76b43fe44 expose feerate_sat_per_1000_weight in ChannelDetails
renames Channel::get_feerate to get_feerate_sat_per_1000_weight
2023-03-15 13:36:14 -04:00
Matt Corallo
4d2679fac6
Merge pull request #2072 from jkczyz/2023-01-fix-scoring-div-by-zero
Fix division by zero in `ProbabilisticScorer`
2023-03-04 00:06:29 +00:00
Matt Corallo
dfe9ea3762
Use ProbabilisticScorer in router fuzzing, to cover overflows there 2023-03-03 16:25:57 -06:00
Jeffrey Czyz
1d1323a3d0
Fix build warnings 2023-03-03 14:23:18 -06:00
Wilmer Paulino
0b1a64f12d
Merge pull request #2046 from TheBlueMatt/2023-02-rgs-robust-and-log
Do not fail to apply RGS updates for removed channels
2023-02-28 11:36:04 -08:00
Matt Corallo
d2f5dc01d1 Add some basic logging to Rapid Gossip Sync processing 2023-02-28 17:56:16 +00:00
Matt Corallo
f03b7cd448 Remove the final_cltv_expiry_delta in RouteParameters entirely
fbc08477e8 purported to "move" the
`final_cltv_expiry_delta` field to `PaymentParamters` from
`RouteParameters`. However, for naive backwards-compatibility
reasons it left the existing on in place and only added a new,
redundant field in `PaymentParameters`.

It turns out there's really no reason for this - if we take a more
critical eye towards backwards compatibility we can figure out the
correct value in every `PaymentParameters` while deserializing.

We do this here - making `PaymentParameters` a `ReadableArgs`
taking a "default" `cltv_expiry_delta` when it goes to read. This
allows existing `RouteParameters` objects to pass the read
`final_cltv_expiry_delta` field in to be used if the new field
wasn't present.
2023-02-27 22:33:21 +00:00
Matt Corallo
16b3c720a6
Merge pull request #2025 from TheBlueMatt/2023-02-no-pub-genesis-hashes
Remove genesis block hash from public API
2023-02-27 17:50:22 +00:00
Matt Corallo
f71daed02d
Merge pull request #1977 from jkczyz/2023-01-offers-fuzz
BOLT 12 deserialization fuzzers
2023-02-25 18:03:51 +00:00
Jeffrey Czyz
3d41df025d
Fuzz test for bech32 decoding
Fuzz testing bech32 decoding along with deserializing the underlying
message can result in overly exhaustive searches. Instead, the message
deserializations are now fuzzed separately. Add fuzzing for bech32
decoding.
2023-02-23 18:25:49 -06:00
Jeffrey Czyz
16168d4c07
Fuzz test for parsing Invoice
An invoice is serialized as a TLV stream and encoded as bytes. Add a
fuzz test that parses the TLV stream and deserializes the underlying
Invoice. Then compare the original bytes with those obtained by
re-serializing the Invoice.
2023-02-23 18:25:49 -06:00
Jeffrey Czyz
e049e97993
Fuzz test for parsing InvoiceRequest
An invoice request is serialized as a TLV stream and encoded as bytes.
Add a fuzz test that parses the TLV stream and deserializes the
underlying InvoiceRequest. Then compare the original bytes with those
obtained by re-serializing the InvoiceRequest.
2023-02-23 18:24:41 -06:00
Matt Corallo
d7c818a3ad Rename BestBlock::from_genesis to from_network for clarity 2023-02-24 00:22:58 +00:00
Matt Corallo
2c3e12e309 Remove genesis block hash from public API
Forcing users to pass a genesis block hash has ended up being
error-prone largely due to byte-swapping questions for bindings
users. Further, our API is currently inconsistent - in
`ChannelManager` we take a `Bitcoin::Network` but in `NetworkGraph`
we take the genesis block hash.

Luckily `NetworkGraph` is the only remaining place where we require
users pass the genesis block hash, so swapping it for a `Network`
is a simple change.
2023-02-24 00:22:58 +00:00
Matt Corallo
96c8507fbf
Merge pull request #1897 from TheBlueMatt/2022-11-monitor-updates-always-async
Always process `ChannelMonitorUpdate`s asynchronously
2023-02-22 19:12:31 +00:00
Matt Corallo
4155f54716 Add an inbound flag to the peer_connected message handlers
Its useful for the message handlers to know if a peer is inbound
for DoS decision-making reasons.
2023-02-21 22:00:42 +00:00
Matt Corallo
e954ee8256
Merge pull request #2035 from TheBlueMatt/2023-02-fix-no-con-discon
Fix (and DRY) the conditionals before calling peer_disconnected
2023-02-21 21:28:05 +00:00
Matt Corallo
be6f263825 Remove the peer_disconnected no_connection_possible flag
Long ago, we used the `no_connection_possible` to signal that a
peer has some unknown feature set or some other condition prevents
us from ever connecting to the given peer. In that case we'd
automatically force-close all channels with the given peer. This
was somewhat surprising to users so we removed the automatic
force-close, leaving the flag serving no LDK-internal purpose.

Distilling the concept of "can we connect to this peer again in the
future" to a simple flag turns out to be ripe with edge cases, so
users actually using the flag to force-close channels would likely
cause surprising behavior.

Thus, there's really not a lot of reason to keep the flag,
especially given its untested and likely to be broken in subtle
ways anyway.
2023-02-21 19:17:06 +00:00
Matt Corallo
10e06331f3 Correct funding_transaction_generated err msg and fix fuzz check
This fixes new errors in `full_stack_target` pointed out by
Chaincode's generous fuzzing infrastructure. Specifically, there's
no reason to check the error message in the
`funding_transaction_generated` return value - it can only return
a failure if the channel has closed since the funding transaction
was generated (which is fine) or if the signer refuses to sign
(which can't happen in fuzzing).
2023-02-21 18:54:52 +00:00
Alec Chen
62a88f97de Replace BTreeSet in IndexedMap with sorted Vec
The `Vec` is sorted not on `IndexedMap::insert`, but on
`IndexedMap::range` to avoid unnecessary work while reading a network
graph.
2023-02-19 22:22:11 -06:00
Matt Corallo
5be29c6add Fix the err msg provided when a send fails due to peer disconnected
We haven't had a `MonitorUpdateInProgress` check in
`Channel::is_live` for some time.
2023-02-17 19:09:28 +00:00
Valentine Wallace
82e0880442
Abandon payment on behalf of the user on payment path failure
Removed retry_single_path_payment, it's replaced by automatic_retries with
AutoRetry::Success
2023-02-15 17:46:30 -05:00
Valentine Wallace
2b2965f1fe
Remove unnecessary scoring methods from Router trait 2023-02-14 14:20:49 -05:00
Matt Corallo
0da7bbd5ec Forward gossip messages which were verified asynchronously
Gossip messages which were verified against the chain
asynchronously should still be forwarded to peers, but must now go
out via a new `P2PGossipSync` parameter in the
`AccessResolver::resolve` method, allowing us to wire them up to
the `P2PGossipSync`'s `MessageSendEventsProvider` implementation.
2023-02-09 15:40:43 +00:00
Jeffrey Czyz
0001260f74
Fuzz test for parsing Refund
A refund is serialized as a TLV stream and encoded in bech32 without a
checksum. Add a fuzz test that parses the unencoded TLV stream and
deserializes the underlying Refund. Then compare the original bytes with
those obtained by re-serializing the Refund.
2023-02-08 19:02:17 -06:00
Jeffrey Czyz
53d2d47360
Fuzz test for parsing Offer
An offer is serialized as a TLV stream and encoded in bech32 without a
checksum. Add a fuzz test that parses the unencoded TLV stream and
deserializes the underlying Offer. Then compare the original bytes with
those obtained by re-serializing the Offer.
2023-02-08 18:47:48 -06:00
Matt Corallo
2cca65058e Add an async resolution option to ChainAccess::get_utxo
For those operating in an async environment, requiring
`ChainAccess::get_utxo` return information about the requested UTXO
synchronously is incredibly painful. Requesting information about a
random UTXO is likely to go over the network, and likely to be a
rather slow request.

Thus, here, we change the return type of `get_utxo` to have both a
synchronous and asynchronous form. The asynchronous form requires
the user construct a `AccessFuture` which they `clone` and pass
back to us. Internally, an `AccessFuture` has an `Arc` to the
`channel_announcement` message which we need to process. When the
user completes their lookup, they call `resolve` on their
`AccessFuture` which we pull the `channel_announcement` from and
then apply to the network graph.
2023-02-08 23:54:30 +00:00
Matt Corallo
51a3353740 Move chain::Access to routing and rename it UtxoLookup
The `chain::Access` trait (and the `chain::AccessError` enum) is a
bit strange - it only really makes sense if users import it via the
`chain` module, otherwise they're left with a trait just called
`Access`. Worse, for bindings users its always just called
`Access`, in part because many downstream languages don't have a
mechanism to import a module and then refer to it.

Further, its stuck dangling in the `chain` top-level mod.rs file,
sitting in a module that doesn't use it at all (it's only used in
`routing::gossip`).

Instead, we give it its full name - `UtxoLookup` (and rename the
error enum `UtxoLookupError`) and put it in the a new
`routing::utxo` module, next to `routing::gossip`.
2023-02-08 23:54:00 +00:00
Alec Chen
b156371d45 Swap PublicKey for NodeId in UnsignedNodeAnnouncement
Also swaps `PublicKey` for `NodeId` in `get_next_node_announcement`
and `InitSyncTracker` to avoid unnecessary deserialization that came
from changing `UnsignedNodeAnnouncement`.
2023-02-07 10:52:20 -06:00
Alec Chen
1fd95496d1 Swap PublicKey for NodeId in UnsignedChannelAnnouncement
Adds the macro `get_pubkey_from_node_id`
to parse `PublicKey`s back from `NodeId`s for signature
verification, as well as `make_funding_redeemscript_from_slices`
to avoid parsing back and forth between types.
2023-02-07 10:51:54 -06:00
Matt Corallo
fbc08477e8 Move the final CLTV delta to PaymentParameters from RouteParams
`PaymentParams` is all about the parameters for a payment, i.e. the
parameters which are static across all the paths of a paymet.
`RouteParameters` is about the information specific to a given
`Route` (i.e. a set of paths, among multiple potential sets of
paths for a payment). The CLTV delta thus doesn't belong in
`RouterParameters` but instead in `PaymentParameters`.

Worse, because `RouteParameters` is built from the information in
the last hops of a `Route`, when we deliberately inflate the CLTV
delta in path-finding, retries of the payment will have the final
CLTV delta double-inflated as it inflates starting from the final
CLTV delta used in the last attempt.

By moving the CLTV delta to `PaymentParameters` we avoid this
issue, leaving only the sought amount in the `RouteParameters`.
2023-02-01 17:50:24 +00:00
Matt Corallo
ca5b10884e
Merge pull request #1799 from TheBlueMatt/2022-10-heap-nerdsnipe
Router Optimizations
2023-01-25 23:19:13 +00:00
Matt Corallo
e64b5d9d2e Add a fuzzer to check that IndexedMap is equivalent to BTreeMap 2023-01-25 18:58:51 +00:00
Duncan Dean
5b53670172
Add new payment type and metadata bytes
Adds two new payment `Method`s for identifying payments with custom
`min_final_cltv_expiry_delta` as payments with LDK or user payment
hashes.

The `min_final_cltv_expiry_delta` value is packed into the first 2
bytes of the expiry timestamp in the payment secret metadata.
2023-01-24 21:01:27 +02:00
Wilmer Paulino
acd2ae606d
Remove NodeSigner::get_node_secret
Secrets should not be exposed in-memory at the interface level as it
would be impossible the implement it against a hardware security
module/secure element.
2023-01-18 17:23:25 -08:00
Wilmer Paulino
9133beaf75
Use NodeSigner::ecdh to compute SharedSecrets 2023-01-18 17:23:23 -08:00
Wilmer Paulino
19c4468bfc
Sign gossip messages with NodeSigner 2023-01-18 17:23:22 -08:00
Wilmer Paulino
db0d6ecdbb
Add NodeSigner::sign_gossip_message
Adds signing capability to NodeSigner for all gossip messages that
require a node signature.
2023-01-18 17:23:15 -08:00
Matt Corallo
f3a6ca4adc
Always set _test_utils when building lightning for some tests
This ensures that we hit additional assertions which are intended
to always be run in tests.
2023-01-18 16:57:50 -08:00
Matt Corallo
31b0a13158
Merge pull request #1957 from TheBlueMatt/2022-01-mon-ref-lockorder
Pass MonitorUpdates by ref and tweak manager lockorder
2023-01-17 23:09:05 +00:00
Matt Corallo
437fa4f807
Merge pull request #1959 from danielgranhao/stop-passing-init-features-in-msg-handlers
Stop passing `InitFeatures` in msg handlers
2023-01-17 01:26:31 +00:00
Daniel Granhão
bcf174034a
Stop passing InitFeatures in msg handlers 2023-01-16 21:18:53 +00:00
Matt Corallo
7e23afe1dc Pass monitor updates by reference, not owned
In the next commit(s) we'll start holding `ChannelMonitorUpdate`s
that are being persisted in `Channel`s until they're done
persisting. In order to do that, switch to applying the updates by
reference instead of value.
2023-01-15 23:53:21 +00:00
Matt Corallo
f9bafa6d0e Use ChannelUnavailable for a peer disconnecting not MisuseError
This fixes a crash in the `full_stack_target` fuzz test (found by
Chaincode's generous fuzzing infrastructure!) but ultimately is a
better error code - a peer disconnecting before we can fund a
channel isn't a "misuse error" its an unavailable channel.
2023-01-15 23:38:24 +00:00