Commit graph

3200 commits

Author SHA1 Message Date
Matt Corallo
31e592bedf Fix compilation with the max_level_trace feature 2021-11-23 23:03:13 +00:00
Matt Corallo
d2ac683f4e Add a comment describing update_time_counter and when its updated 2021-11-23 22:18:00 +00:00
Matt Corallo
391fbfbe1a Re-broadcast our own gossip even if its same as the last broadcast
Even if our gossip hasn't changed, we should be willing to
re-broadcast it to our peers. All our peers may have been
disconnected the last time we broadcasted it.
2021-11-23 22:18:00 +00:00
Matt Corallo
8f89371bae Update ChannelUpdate::timestamp when channels are dis-/en-abled
We update the `Channel::update_time_counter` field (which is copied
into `ChannelUpdate::timestamp`) only when the channel is
initialized or closes, and when a new block is connected. However,
if a peer disconnects or reconnects, we may wish to generate
`ChannelUpdate` updates in between new blocks. In such a case, we
need to make sure the `timestamp` field is newer than any previous
updates' `timestamp` fields, which we do here by simply
incrementing it when the channel status is changed.

As a side effect of this we have to update
`test_background_processor` to ensure it eventually succeeds even
if the serialization of the `ChannelManager` changes after the test
begins.
2021-11-23 22:17:18 +00:00
Matt Corallo
74828d2435 Separate ChannelAnnouncement and ChannelUpdate broadcast conditions
When a `ChannelUpdate` message is generated for broadcast as a part
of a `BroadcastChannelAnnouncement` event, it may be newer than our
previous `ChannelUpdate` and need to be broadcast. However, if the
`ChannelAnnouncement` had already been seen we wouldn't
re-broadcast either message as the `handle_channel_announcement`
call would fail, short-circuiting the condition to broadcast both.

Instead, we split the broadcast of each message as well as the
conditional so that we always attempt to handle each message and
update our local graph state, then broadcast the message if its
update was processed successfully.
2021-11-23 22:17:18 +00:00
Matt Corallo
f69311ccff Store holder channel reserve and max-htlc-in-flight explicitly
Previously, `holder_selected_channel_reserve_satoshis` and
`holder_max_htlc_value_in_flight_msat` were constant functions
of the channel value satoshis. However, in the future we may allow
allow users to specify it. In order to do so, we'll need to track
them explicitly, including serializing them as appropriate.

We go ahead and do so here, in part as it will make testing
different counterparty-selected channel reserve values easier.
2021-11-23 21:05:07 +00: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
Matt Corallo
2b78957888
Merge pull request #1176 from lightning-signer/2021-11-htlc-anchors
Add anchors support for HTLCs
2021-11-23 19:37:09 +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
Ken Sedgwick
530abc5efd
Add test vectors for get_htlc_redeemscript wrt anchors 2021-11-23 08:05:23 -08:00
Ken Sedgwick
50d81220df
Adjust HTLC_{SUCCESS,TIMEOUT}_TX_WEIGHT when anchors used 2021-11-23 08:05:22 -08:00
Ken Sedgwick
6c36e011a8
Add anchor support to build_htlc_transaction 2021-11-23 08:05:16 -08:00
Ken Sedgwick
c077f36b4b
Increase visibility of anchor related methods 2021-11-23 08:01:34 -08:00
Ken Sedgwick
3efcbab5d4
Add anchor support to commitment HTLC outputs 2021-11-23 08:00:42 -08:00
Matt Corallo
016eb96fc7 Support logger::Record in C by String-ing the fmt::Arguments
This adds a new (non-feature) cfg argument `c_bindings` which will
be set when building C bindings. With this, we can (slightly) tweak
behavior and API based on whether we are being built for Rust or C
users.

Ideally we'd never need this, but as long as we can keep the API
consistent-enough to avoid material code drift, this gives us a
cheap way of doing the "right" thing for both C and Rust when the
two are in tension.

We also move lightning-background-processor to support the same
MSRV as the main lightning crate, instead of only
lightning-net-tokio's MSRV.
2021-11-23 03:30:48 +00:00
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
Matt Corallo
1f170dba02
Merge pull request #1182 from TheBlueMatt/2021-11-fix-txid-log
Trivial Logging Fixes
2021-11-22 15:41:19 +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
Matt Corallo
8d886ee924
Merge pull request #1173 from tnull/add_accept_inbound_channels_option
Add 'accept_inbound_channels' config option.
2021-11-17 19:06:19 +00: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
77948dbcd7
Merge pull request #1166 from TheBlueMatt/2021-11-chan-size-scoring 2021-11-16 22:10:42 +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
e1ad422c1b
Merge pull request #1160 from jkczyz/2011-11-spontaneous-invoice-payer
Retries for spontaneous payments
2021-11-16 20:56:40 +00:00
Jeffrey Czyz
592bfd7c58
Add PaymentHash parameter to Router::find_route
Implementations of Router may need the payment hash in order to look up
pre-computed routes from a probe for a given payment. Add a PaymentHash
parameter to Router::find_route to allow for this.
2021-11-16 13:57:58 -06:00