Commit graph

592 commits

Author SHA1 Message Date
Matt Corallo
7671ae5452
Merge pull request #1351 from TheBlueMatt/2022-03-scid-privacy
Implement the SCIDAlias Channel Type and provide SCID Privacy
2022-03-28 20:33:55 +00:00
Matt Corallo
b42ebd892b Expose chan type in Event::OpenChannelRequest & ChannelDetails
As we add new supported channel types, inbound channels which use
new features may cause backwards-compatibility issues for clients.
If a new channel is opened using new features while a client still
wishes to ensure support for downgrading to a previous version of
LDK, that new channel may cause the `ChannelManager` to fail
deserialization due to unsupported feature flags.

By exposing the channel type flags to the user in channel requests,
users wishing to support downgrading to previous versions of LDK
can reject channels which use channel features which previous
versions of LDK do not understand.
2022-03-27 17:12:17 +00:00
psycho-pirate
20a81e5c14 added network address in methods, filter_address function with tests and updated documentation 2022-03-23 04:44:28 +05:30
Matt Corallo
b1cd5a7434
Merge pull request #1311 from TheBlueMatt/2022-02-0conf-part-1
Support for SCID Aliases
2022-03-10 00:47:23 +00:00
Matt Corallo
b2629afd88 Track SCID aliases from our counterparty and use them in invoices
New `funding_locked` messages can include SCID aliases which our
counterparty will recognize as "ours" for the purposes of relaying
transactions to us. This avoids telling the world about our
on-chain transactions every time we want to receive a payment, and
will allow for receiving payments before the funding transaction
appears on-chain.

Here we store the new SCID aliases and use them in invoices instead
of he "standard" SCIDs.
2022-03-09 19:14:38 +00:00
Elias Rohrer
e92b5a7ebd Add a random per-path CLTV offset for privacy. 2022-03-09 11:13:47 -06:00
Matt Corallo
99073c74dd
Merge pull request #1324 from valentinewallace/2022-02-phantom-followup
#1199 Followup
2022-02-28 18:16:21 +00:00
Valentine Wallace
1f6700c72d
Follow-up nits from #1199 (phantom node support) 2022-02-22 11:54:35 -05:00
Matt Corallo
b0cb5583b1 Add explicit compile errors when cfg=fuzzing is mis-set 2022-02-18 17:03:04 +00:00
Matt Corallo
acb4c539f7 Drop fuzztarget feature entirely
Some time ago we started transitioning to `cfg(fuzzing)` instead of
exposing a full feature. Here we complete the transition.
2022-02-18 17:03:04 +00:00
Valentine Wallace
410eb05365
Add get_phantom_scid and get_phantom_route_hints + scid_utils::fake_scid module
See method and module docs for more details
2022-02-14 14:22:38 -05:00
Valentine Wallace
adeec71ed8
keysinterface: adapt get_node_secret for phantom payments
We want LDK to be able to retrieve the phantom secret key when we see that a payment
is destined for a phantom node.
2022-02-14 14:22:38 -05:00
Valentine Wallace
f6c75d8ec3
KeysInterface::sign_invoice: indicate whether invoice is a phantom 2022-02-14 14:22:38 -05:00
Jeffrey Czyz
28faf89df3
Deprecate Scorer in favor of ProbabilisticScorer 2022-02-02 20:22:27 -06:00
Matt Corallo
d62edd58ab Move node_id signing of ChannelAnnouncement into Signer
This removes one more place where we directly access the node_id
secret key in `ChannelManager`, slowly marching towards allowing
the node_id secret key to be offline in the signer.

More importantly, it allows more ChannelAnnouncement logic to move
into the `Channel` without having to pass the node secret key
around, avoiding the announcement logic being split across two
files.
2022-01-25 18:25:56 +00:00
valentinewallace
35d4ebb208
Merge pull request #1272 from lightning-signer/2022-01-sign-invoice-api
Improve KeysInterface::sign_invoice API
2022-01-24 11:39:58 -05:00
Devrandom
803d6b6e2f Improve KeysInterface::sign_invoice API
split hrp from invoice data, to allow parsing, since there is no delimiter between the two parts
2022-01-24 09:48:56 +01:00
Elias Rohrer
808477a5ce Rename Payee to PaymentParameters 2022-01-21 10:39:01 +01:00
Matt Corallo
f676f5585f Add a new WarningMessage message to send and receive warnings 2022-01-11 19:48:20 +00:00
Valentine Wallace
6dd1ec1fed
Add get_inbound_payment_key_material to KeysInterface
This will allow us to retrieve key material for encrypting/decrypting inbound
payment info, in upcoming commits
2021-12-16 15:30:52 -08:00
Devrandom
02a9f92ea4 Getter for the total channel balance
The existing balance getters subtract reserve, this one does not.
2021-12-07 15:06:22 +01:00
Matt Corallo
ef86a3e209
Merge pull request #1162 from TheBlueMatt/2021-11-fix-accept-chan-checks
Correct initial commitment tx fee affordability checks on open
2021-11-23 20:46:38 +00:00
Matt Corallo
19191b450c
Merge pull request #1178 from jkczyz/2021-11-payment-path-successful
Generate PaymentPathSuccessful event for each path
2021-11-23 20:39:28 +00:00
Jeffrey Czyz
2c4f16d5e3
Generate PaymentPathSuccessful event for each path
A single PaymentSent event is generated when a payment is fulfilled.
This is occurs when the preimage is revealed on the first claimed HTLC.
For subsequent HTLCs, the event is not generated.

In order to score channels involved with a successful payments, the
scorer must be notified of each successful path involved in the payment.
Add a PaymentPathSuccessful event for this purpose. Generate it whenever
a part is removed from a pending outbound payment. This avoids duplicate
events when reconnecting to a peer.
2021-11-23 13:29:45 -06:00
Matt Corallo
940ef05371 Correct initial commitment tx fee affordability checks on open
Previously, we would reject inbound channels if the funder wasn't
able to meet our channel reserve on their first commitment
transaction only if they also failed to push enough to us for us
to not meet their initial channel reserve as well.

There's not a lot of reason to care about us meeting their reserve,
however - its largely expected that they may not push enough to us
in the initial open to meet it, and its not actually our problem if
they don't.

Further, we used our own fee, instead of the channel's actual fee,
to calculate fee affordability of the initial commitment
transaction.

We resolve both issues here, rewriting the combined affordability
check conditionals in inbound channel open handling and adding a
fee affordability check for outbound channels as well.

The prior code may have allowed a counterparty to start the channel
with "no punishment" states - violating the reason for the reserve
threshold.
2021-11-23 01:20:43 +00:00
Matt Corallo
ba50dd5786
Merge pull request #1054 from ariard/2021-08-check-outbound-feerate
Check for outbound feerate update affordability before sending
2021-11-22 22:45:51 +00:00
Valentine Wallace
a4822e5b27
Remove user_payment_id
In upcoming commits, we'll be making the payment secret and payment hash/preimage
derivable from info about the payment + a node secret. This means we don't
need to store any info about incoming payments and can eventually get rid of the
channelmanager::pending_inbound_payments map.
2021-11-19 17:59:09 -05:00
Antoine Riard
31975c5994 Cancel the outbound feerate update if above what we can afford 2021-11-19 16:16:24 -05:00
Matt Corallo
42ebf77415 Move Score into a scoring module instead of a top-level module
Traits in top-level modules is somewhat confusing - generally
top-level modules are just organizational modules and don't contain
things themselves, instead placing traits and structs in
sub-modules. Further, its incredibly awkward to have a `scorer`
sub-module, but only have a single struct in it, with the relevant
trait it is the only implementation of somewhere else. Not having
`Score` in the `scorer` sub-module is further confusing because
it's the only module anywhere that references scoring at all.
2021-11-16 20:58:37 +00:00
Matt Corallo
2ec427f148 Rename Payee::new to Payee::from_node_id to clarify it somewhat
This also differentiates it from the bindings default-constructed
`new` method which is constructed when all fields are exposed and
of mappable types.
2021-11-02 20:50:42 +00:00
Matt Corallo
6e86776a71
Merge pull request #1149 from jkczyz/2021-11-network-graph
Shared ownership of NetworkGraph
2021-11-01 22:19:08 +00:00
Jeffrey Czyz
c4d7b9d50f
Make NetGraphMsgHandler::network_graph private
Since NetworkGraph has shared ownership, NetGraphMsgHandler does not
need to expose its field.
2021-11-01 15:01:39 -05:00
Jeffrey Czyz
bcdd852279
Parameterize NetGraphMsgHandler with NetworkGraph
NetworkGraph is owned by NetGraphMsgHandler, but DefaultRouter requires
a reference to it. Introduce shared ownership to NetGraphMsgHandler so
that both can use the same NetworkGraph.
2021-11-01 13:14:14 -05:00
Matt Corallo
d73e434280 Provide payment retry data when an MPP payment failed partially
This will allow `InvoicePayer` to properly retry payments that only
partially failed to send.
2021-10-30 01:53:19 +00:00
Jeffrey Czyz
c34ab42961
Penalize failed channels in Scorer
As payments fail, the channel responsible for the failure may be
penalized. Implement Scorer::payment_path_failed to penalize the failed
channel using a configured penalty. As time passes, the penalty is
reduced using exponential decay, though penalties will accumulate if the
channel continues to fail. The decay interval is also configurable.
2021-10-29 14:26:58 -05:00
Jeffrey Czyz
2d102a3065
Unify route finding methods
An upcoming Router interface will be used for finding a Route both when
initially sending a payment and also when retrying failed payment paths.
Unify the three varieties of get_route so the interface can consist of a
single method implemented by the new `find_route` method. Give get_route
pub(crate) visibility so it can still be used in tests.
2021-10-26 20:15:19 -05:00
Matt Corallo
fe237f9280 Copy Payee into Routes to provide them to ChannelManager 2021-10-25 17:58:18 +00:00
Jeffrey Czyz
b5be4c210c
Define Payee abstraction for use in get_route
A payee can be identified by a pubkey and optionally have an associated
set of invoice features and route hints. Use this in get_route instead
of three separate parameters. This may be included in PaymentPathFailed
later to use when finding a new route.
2021-10-25 10:18:11 -05:00
Matt Corallo
107c6c7939
Merge pull request #1108 from TheBlueMatt/2021-10-persist-mon-blocks
Persist ChannelMonitors after new blocks are connected
2021-10-20 00:53:26 +00:00
Matt Corallo
5c2ff2cb30 Persist ChannelMonitors after new blocks are connected
This resolves several user complaints (and issues in the sample
node) where startup is substantially delayed as we're always
waiting for the chain data to sync.

Further, in an upcoming PR, we'll be reloading pending payments
from ChannelMonitors on restart, at which point we'll need the
change here which avoids handling events until after the user
has confirmed the `ChannelMonitor` has been persisted to disk.
It will avoid a race where we
 * send a payment/HTLC (persisting the monitor to disk with the
   HTLC pending),
 * force-close the channel, removing the channel entry from the
   ChannelManager entirely,
 * persist the ChannelManager,
 * connect a block which contains a fulfill of the HTLC, generating
   a claim event,
 * handle the claim event while the `ChannelMonitor` is being
   persisted,
 * persist the ChannelManager (before the CHannelMonitor is
   persisted fully),
 * restart, reloading the HTLC as a pending payment in the
   ChannelManager, which now has no references to it except from
   the ChannelMonitor which still has the pending HTLC,
 * replay the block connection, generating a duplicate PaymentSent
   event.
2021-10-20 00:06:17 +00:00
Matt Corallo
89ad059548 Use an opaque type to describe monitor updates in Persist
In the next commit, we'll be originating monitor updates both from
the ChainMonitor and from the ChannelManager, making simple
sequential update IDs impossible.

Further, the existing async monitor update API was somewhat hard to
work with - instead of being able to generate monitor_updated
callbacks whenever a persistence process finishes, you had to
ensure you only did so at least once all previous updates had also
been persisted.

Here we eat the complexity for the user by moving to an opaque
type for monitor updates, tracking which updates are in-flight for
the user and only generating monitor-persisted events once all
pending updates have been committed.
2021-10-19 23:49:04 +00:00
Matt Corallo
4500270488 Move ChannelManager::monitor_updated to a MonitorEvent
In the next commit we'll need ChainMonitor to "see" when a monitor
persistence completes, which means `monitor_updated` needs to move
to `ChainMonitor`. The simplest way to then communicate that
information to `ChannelManager` is via `MonitorEvet`s, which seems
to line up ok, even if they're now constructed by multiple
different places.
2021-10-19 23:49:04 +00:00
Matt Corallo
001bc7113a
Merge pull request #1121 from TheBlueMatt/2021-10-return-temp-id
Expose temporary channel ID and user channel ID pre-funding
2021-10-16 02:15:07 +00:00
Matt Corallo
2398f1746d
Merge pull request #1124 from jkczyz/2021-10-default-channel-scoring
Add channel scoring to get_route
2021-10-16 01:58:15 +00:00
Matt Corallo
bb7ef6c290 Rename create_channel param to user_channel_id to standardize it 2021-10-16 00:27:04 +00:00
Jeffrey Czyz
e15a18a503
Add channel scoring to get_route
Failed payments may be retried, but calling get_route may return a Route
with the same failing path. Add a routing::Score trait used to
parameterize get_route, which it calls to determine how much a channel
should be penalized in terms of msats willing to pay to avoid the
channel.

Also, add a Scorer struct that implements routing::Score with a constant
constant penalty. Subsequent changes will allow for more robust scoring
by feeding back payment path success and failure to the scorer via event
handling.
2021-10-15 15:29:49 -05:00
Matt Corallo
1464671ae8 Use Persister to return errors in fuzzers not chain::Watch 2021-10-14 00:19:43 +00:00
Matt Corallo
6a7c48b60d Move ChannelMonitorUpdateErr to chain as it is a chain::Watch val 2021-10-14 00:16:50 +00:00
Matt Corallo
0dfb24e661 Move Persist trait to chainmonitor as that's the only reference 2021-10-14 00:16:50 +00:00
Matt Corallo
ad819ea705
Merge pull request #1065 from TheBlueMatt/2021-08-bump-dust
Increase our default/minimum dust limit and decrease our max
2021-09-27 20:39:02 +00:00