Commit graph

1416 commits

Author SHA1 Message Date
Matt Corallo
13e4fd586e Test fixed channel reserve checks on channel open 2021-11-23 01:20:43 +00: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
1d30e06893 Rewrite test_update_fee_that_funder_cannot_afford to avoid magic
Instead of magic hard-coded constants, its better for tests to
derive the values used so that they change if constants are changed
and so that it is easier to re-derive constants in the future as
needed.
2021-11-23 01:20:43 +00:00
Matt Corallo
a33d3b98d7 Make Channel::commit_tx_fee_msat static and take fee explicitly
This may avoid risk of bugs in the future as it requires the caller
to think about the fee being used, not just blindly use the current
(committed) channel feerate.
2021-11-22 23:27:25 +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
Matt Corallo
22398853c9
Merge pull request #1168 from TheBlueMatt/2021-11-mpp-routing-fixes
Fix MPP routefinding when we first collect 95% of payment value
2021-11-22 21:55:06 +00:00
Antoine Riard
c3c0e60226 Check outbound update_fee affordance incremented with holding cell HTLCs 2021-11-22 16:32:47 -05:00
Matt Corallo
1180b633b4 Fix MPP routefinding when we first collect 95% of payment value
See comment in new test for more details.
2021-11-22 19:01:17 +00:00
Matt Corallo
3cb3d18e1d
Merge pull request #1145 from tnull/add_gossip_log_level
Introduce GOSSIP log level to PeerHandler
2021-11-22 18:58:56 +00:00
Elias Rohrer
3b4b74bc66 Add a new log-level for gossip messages. 2021-11-22 18:19:08 +01:00
Matt Corallo
58539b8440
Merge pull request #1180 from valentinewallace/2021-11-remove-user-pmt-id
Remove user_payment_id
2021-11-22 16:40:37 +00:00
Antoine Riard
efd9ad22fc Introduce CommitmentStats 2021-11-21 21:28:22 -05:00
Antoine Riard
40f48def10 Re-add test_max_dust_htlc_exposure 2021-11-21 21:28:20 -05:00
Matt Corallo
dea1310c55 Ensure current channel state is logged for all channels on startup 2021-11-20 23:16:28 +00:00
Matt Corallo
0b072834ab Correct txid logging to reverse bytes.
We also take this opportunity to log the channel being closed when
one is closed by an on-chain spend of the funding output.
2021-11-20 23:04:55 +00:00
Matt Corallo
293e5f21ff
Merge pull request #1027 from TheBlueMatt/2021-07-check-dust
Check all outputs meet the dust threshold in `check_spends!()`
2021-11-20 03:26:24 +00:00
Antoine Riard
ab11f450b6 Check we won't overflow max_dust_htlc_exposure_msat at outbound feerate update 2021-11-19 21:15:14 -05: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
Matt Corallo
e81ec4a5ad Check all outputs meet the dust threshold in check_spends!() 2021-11-19 22:52:26 +00:00
Matt Corallo
9c1c7c496c Limit minimum output size to the dust limit when RBF-bumping 2021-11-19 22:52:26 +00:00
Antoine Riard
31975c5994 Cancel the outbound feerate update if above what we can afford 2021-11-19 16:16:24 -05:00
Antoine Riard
ee7c5b572b Introduce new helper commit_tx_fee_sat 2021-11-17 17:49:36 -05:00
Elias Rohrer
e7b2bca1d6 Add 'accept_inbound_channels' config option. 2021-11-17 18:54:47 +01:00
Matt Corallo
2b4ca9e9c5
Merge pull request #1083 from TheBlueMatt/2021-09-funding-timeout
Automatically close channels that go unfunded for 2016 blocks
2021-11-17 17:28:36 +00:00
Matt Corallo
358292141a Automatically close channels that go unfunded for 2016 blocks
As recommended by BOLT 2 added in
https://github.com/lightningnetwork/lightning-rfc/pull/839
2021-11-16 21:44:35 +00:00
Matt Corallo
b288a2739a Return ClosureReason from Channel chain update methods
This fixes a few `ClosureReason`s and allows us to have
finer-grained user-visible errors when a channel closes due to an
on-chain event.
2021-11-16 21:44:35 +00: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
9bec35ddde Penalize large HTLCs relative to channels in default Scorer
Sending HTLCs which are any greater than a very small fraction of the
channel size tend to fail at a much higher rate. Thus, by default
we start applying a penalty at only 1/8th the channel size and
increase it linearly as the amount reaches the channel's capacity,
20 msat per 1024th of the channel capacity.
2021-11-16 20:58:04 +00:00
Matt Corallo
8dc7cfab3a Provide Score the HTLC amount and channel capacity
This should allow `Score` implementations to make substantially
better decisions, including of the form "willing to pay X to avoid
routing over this channel which may have a high failure rate".
2021-11-16 20:58:04 +00:00
Matt Corallo
4a3139d24d
Merge pull request #1161 from TheBlueMatt/2021-11-fix-chan-type-ser
Correct Channel type serialization logic
2021-11-16 18:18:01 +00:00
Matt Corallo
a44587d9aa Correct Channel type serialization logic
Currently, we write out the Channel's `ChannelTypeFeatures` as an
odd type, implying clients which don't understand the
`ChannelTypeFeatures` field can simply ignore it. This is obviously
nonsense if the channel type is some future version - the client
needs to fail to deserialize as it doesn't understand the channel's
type.

We adapt the serialization logic here to only write out the
`ChannelTypeFeatures` field if it is something other than
only-static-remote-key, and simply consider that "default" (as it
is the only supported type today). Then, we write out the channel
type as an even TLV, implying clients which do not understand it
must fail to read the `Channel`.

Note that we do not need to bother reserving the TLV type no longer
written as it never appeared in a release (merged post-0.0.103).
2021-11-16 17:12:35 +00:00
Matt Corallo
4d6c26248d
Merge pull request #1119 from TheBlueMatt/2021-10-less-aggressive-htlc-timeouts
Be less aggressive in outbound HTLC CLTV timeout checks
2021-11-16 16:18:20 +00:00
Matt Corallo
5e998cce6b Be less aggressive in outbound HTLC CLTV timeout checks
We currently assume our counterparty is naive and misconfigured and
may force-close a channel to get an HTLC we just forwarded them.

There shouldn't be any reason to do this - we don't have any such
bug, and we shouldn't start by assuming our counterparties are
buggy. Worse, this results in refusing to forward payments today,
failing HTLCs for largely no reason.

Instead, we keep a fairly conservative check, but not one which
will fail HTLC forwarding spuriously - testing only that the HTLC
doesn't expire for a few blocks from now.

Fixes #1114.
2021-11-16 15:22:42 +00:00
Matt Corallo
4bb81ff594
Merge pull request #1131 from TheBlueMatt/2021-10-upstream-dust
Use upstream rust-bitcoin's dust calculation instead of our own
2021-11-13 00:23:28 +00:00
Matt Corallo
119841a243 Use upstream rust-bitcoin's dust calculation instead of our own
Not only does this move to common code, but it fixes handling of
all output types except for a few trivial cases.
2021-11-12 23:30:21 +00:00
Matt Corallo
1beccf188d
Merge pull request #1143 from TheBlueMatt/2021-10-no-payment-id-leaks
Fix a minor memory leak on PermanentFailure mon errs when sending
2021-11-12 17:59:18 +00:00
Matt Corallo
081ce7c843
Merge pull request #1165 from lightning-signer/2021-11-fix-anchors
Fix countersignatory (to_remote) output redeemscript when anchors enabled
2021-11-12 15:22:41 +00:00
Ken Sedgwick
7dd8bd7068
Renamed script_for_p2wpkh to get_p2wpkh_redeemscript to match convention 2021-11-11 15:08:26 -08:00
Ken Sedgwick
1366d30531
Fix to_remote output redeemscript when anchors enabled 2021-11-11 15:08:15 -08:00
Matt Corallo
0ec13f611b Fix a minor memory leak on PermanentFailure mon errs when sending
If we send a payment and fail to update the first-hop channel state
with a `PermanentFailure` ChannelMonitorUpdateErr, we would have an
entry in our pending payments map, but possibly not return the
PaymentId back to the user to retry the payment, leading to a (rare
and relatively minor) memory leak.
2021-11-11 20:38:58 +00:00
Matt Corallo
8e96f6b92e Log before+after ChannelMonitor/Manager updates for visibility
I realized on my own node that I don't have any visibility into how
long a monitor or manager persistence call takes, potentially
blocking other operations. This makes it much more clear by adding
a relevant log_trace!() print immediately before and immediately
after persistence.
2021-11-10 22:02:38 +00:00
Jeffrey Czyz
b57ed7982f
Add unit tests for Scorer
Test basic and channel failure penalties, including after a
(de-)serialization round trip.
2021-11-08 15:31:42 -06:00
Jeffrey Czyz
2a7d9c8ddd
Add SinceEpoch time to test Scorer hermetically
In order to test Scorer hermetically, sleeps must be avoided. Add a
SinceEpoch abstraction for manually advancing time. Implement the Time
trait for SinceEpoch so that it can be used with ScorerUsingTime in
tests.
2021-11-08 15:31:42 -06:00
Matt Corallo
c0bbd4d918
Merge pull request #1078 from TheBlueMatt/2021-09-chan-types
Implement channel_type negotiation
2021-11-03 16:58:33 +00:00
Matt Corallo
2b837bb272 Bump crate versions to 0.0.103/invoice 0.11 2021-11-03 02:20:51 +00:00
Matt Corallo
d25f332592 Tweak serialization of ScorerUsingTime for better forward compat 2021-11-03 01:30:03 +00:00
Matt Corallo
0c1b70c161 Add (C-not exported) tags as required in tuple types
This prepares us for C bindings auto-exporting tuple type fields.
2021-11-02 20:50:42 +00:00
Matt Corallo
80802006ab Add (C-not exported) tag to a Payee modifier with move semantics
This matches the other `Payee` move-modifier functions.
2021-11-02 20:50:42 +00:00
Matt Corallo
0f0530a67a Remove now-unused import in routing/mod.rs 2021-11-02 20:50:42 +00:00
Matt Corallo
51d146c566 Make payment_path_failed path type bindings-mappable
The bindings don't currently support passing `Vec`s of objects
which it mappes as "opaque types". This is because it will require
clones to convert its own list of references to Rust's list of
objects.

In the near future we should resolve this limitation, allowing us
to revert this (and make `find_route`'s method signature similarly
cleaner), but for now we must avoid `Vec<OpaqueType>`.
2021-11-02 20:50:42 +00:00