Commit graph

602 commits

Author SHA1 Message Date
Viktor Tigerström
14e52cd7a6 Pass counterparty_node_id to force_close_channel 2022-05-14 20:32:44 +02:00
Viktor Tigerström
84a6e7bc51 Pass counterparty_node_id to close_channel functions 2022-05-14 20:32:44 +02:00
Viktor Tigerström
7893ddc721 Add counterparty_node_id to FundingGenerationReady 2022-05-14 02:15:32 +02:00
Matt Corallo
e6aaf7c72d Pull secp256k1 contexts from per-peer to per-PeerManager
Instead of including a `Secp256k1` context per
`PeerChannelEncryptor`, which is relatively expensive memory-wise
and nontrivial CPU-wise to construct, we should keep one for all
peers and simply reuse it.

This is relatively trivial so we do so in this commit.

Since its trivial to do so, we also take this opportunity to
randomize the new PeerManager context.
2022-05-11 20:02:29 +00:00
valentinewallace
6587607c51
Merge pull request #1467 from arik-so/fuzz_new_target_docs
Add documentation for creating new fuzz test targets.
2022-05-09 12:09:52 -04:00
Arik Sosman
5c64eec703
Add documentation for creating new fuzz test targets. 2022-05-05 09:58:26 -07:00
Devrandom
28d33ff9e0 bitcoin crate 0.28.1 2022-05-05 18:04:42 +02:00
Matt Corallo
1af705579b Separate ChannelDetails' outbound capacity from the next HTLC max
`ChannelDetails::outbound_capacity_msat` describes the total amount
available for sending across several HTLCs, basically just our
balance minus the reserve value maintained by our counterparty.
However, when routing we use it to guess the maximum amount we can
send in a single additional HTLC, which it is not.

There are numerous reasons why our balance may not match the amount
we can send in a single HTLC, whether the HTLC in-flight limit, the
channe's HTLC maximum, or our feerate buffer.

This commit splits the `outbound_capacity_msat` field into two -
`outbound_capacity_msat` and `outbound_htlc_limit_msat`, setting us
up for correctly handling our next-HTLC-limit in the future.

This also addresses the first of the reasons why the values may
not match - the max-in-flight limit. The inaccuracy is ultimately
tracked as #1126.
2022-04-25 15:04:21 +00:00
Viktor Tigerström
63f0a31b59 Add outbound min/max to ChannelCounterparty 2022-04-21 12:27:51 +02:00
Viktor Tigerström
6644ef138d Add inbound htlc min/max to ChannelDetails 2022-04-19 23:54:55 +02:00
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