Commit graph

602 commits

Author SHA1 Message Date
henghonglee
21b0818be7 Score's FeeParams as passed-in params on Routefinding functions
This PR aims to create a "stateless" scorer. Instead of passing
in fee params at construction-time, we want to parametrize the
scorer with an associated "parameter" type, which is then
passed to the router function itself, and allows passing
different parameters per route-finding call.
2023-05-10 12:53:42 -07:00
Matt Corallo
0ecb4b093a
Merge pull request #2258 from valentinewallace/2023-04-blinded-pathfinding-groundwork-2
Prefactor `PaymentParameters` for blinded recipients
2023-05-08 23:17:42 +00:00
Duncan Dean
2ace882d39
Add & generate dual-funding message fuzzing 2023-05-05 11:40:53 +02:00
Duncan Dean
adc1b55a6f
Add message structs required for dual-funded channels
This is the first of a set of PRs to enable the experimental dual-funded
channels feature using interactive transaction construction. This allows
both the channel initiator and channel acceptor to contribute funds
towards the channel.
2023-05-05 11:40:49 +02:00
Valentine Wallace
cea78f585a
Error if clear hints are provided for blinded PaymentParams 2023-05-04 10:50:53 -04:00
Arik Sosman
6cb9919f0c
Move keysinterface.rs to a directory-level module called sign. 2023-05-02 21:48:08 -07:00
Matt Corallo
ec3de62bc7
Merge pull request #2249 from TheBlueMatt/2023-04-less-pm-bounds
Trivial PeerManager cleanups
2023-05-03 01:41:17 +00:00
Matt Corallo
101c09f9bf
Merge pull request #2213 from benthecarman/error-sign-provider-addrs
Allow get_shutdown_scriptpubkey and get_destination_script to return an Error
2023-05-02 17:48:05 +00:00
benthecarman
0b8bdbf968
Allow get_shutdown_scriptpubkey and get_destination_script to return an error 2023-05-02 02:39:54 -05:00
Matt Corallo
524981ddf4 Move the CustomMessageHandler into the MessageHandler struct
`PeerManager` takes a `MessageHandler` struct which contains all
the known message handlers for it to pass messages to. It then,
separately, takes a `CustomMessageHandler`. This makes no sense, we
should simply include the `CustomMessageHandler` in the
`MessageHandler` struct for consistency.
2023-04-30 04:03:55 +00:00
Matt Corallo
c89fd38f2a
Merge pull request #2220 from TheBlueMatt/2023-04-dont-ban-cln
Don't remove nodes if there's no channel_update for a temp failure
2023-04-24 21:15:08 +00:00
Matt Corallo
67ad6c40f0 Don't remove nodes if there's no channel_update for a temp failure
Previously, we were requiring any `UPDATE` onion errors to include
a `channel_update`, as the spec mandates[1]. If we see an onion
error which is missing one we treat it as a misbehaving node that
isn't behaving according to the spec and simply remove the node.

Sadly, it appears at least some versions of CLN are such nodes, and
opt to not include `channel_update` at all if they're returning a
`temporary_channel_failure`. This causes us to completely remove
CLN nodes from our graph after they fail to forward our HTLC.

While CLN is violating the spec here, there's not a lot of reason
to not allow it, so we go ahead and do so here, treating it simply
as any other failure by letting the scorer handle it.

[1] The spec says `Please note that the channel_update field is
mandatory in messages whose failure_code includes the UPDATE flag`
however doesn't repeat it in the requirements section so its not
crazy that someone missed it when implementing.
2023-04-24 18:52:05 +00:00
Matt Corallo
607727fae7
Merge pull request #2146 from valentinewallace/2023-03-blinded-pathfinding-groundwork
Blinded pathfinding groundwork
2023-04-24 16:46:15 +00:00
Valentine Wallace
64c26c8a79
Add blinded path {metadata} fields to Path, but disallow paying blinded paths for now 2023-04-21 15:35:04 -04:00
Valentine Wallace
d5b05e54c3
Replace Vec<RouteHop> with new Path struct
This lays groundwork for adding blinded path info to Path
2023-04-21 11:48:27 -04:00
Wilmer Paulino
2c5bd1c56f
Implement EntropySource for InMemorySigner
This allows the `InMemorySigner` to produce its own randomness, which we
plan to use when generating signatures in future work.

We can no longer derive `Clone` due to the `AtomicCounter`, so we opt to
implement it manually.
2023-04-20 12:14:19 -07:00
Valentine Wallace
e691e5077d
Update docs and method names for blinded payment paths 2023-04-20 10:14:17 -04:00
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