]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
2 years agoMerge pull request #1203 from lightning-signer/2021-12-value-to-self
Matt Corallo [Wed, 8 Dec 2021 02:24:32 +0000 (02:24 +0000)]
Merge pull request #1203 from lightning-signer/2021-12-value-to-self

Getter for the total channel balance

2 years agoMerge pull request #1210 from TheBlueMatt/2021-12-new-codecod-upload
Matt Corallo [Wed, 8 Dec 2021 01:01:34 +0000 (01:01 +0000)]
Merge pull request #1210 from TheBlueMatt/2021-12-new-codecod-upload

Upgrade to codecov uploader v2

2 years agoUpgrade to codecov uploader v2 2021-12-new-codecod-upload
Matt Corallo [Tue, 7 Dec 2021 19:17:57 +0000 (19:17 +0000)]
Upgrade to codecov uploader v2

Some time ago codecov stopped supporting their old v1 uploader, and
it seems they've now finally turned it off, so we aren't getting
any coverage reports anymore. Hopefully upgrading is pretty trivial.

2 years agoMerge pull request #1208 from TheBlueMatt/2021-12-less-force-close
Matt Corallo [Tue, 7 Dec 2021 20:11:47 +0000 (20:11 +0000)]
Merge pull request #1208 from TheBlueMatt/2021-12-less-force-close

Reduce force-closures with user fee estimators which round poorly

2 years agoMerge pull request #1205 from TheBlueMatt/2021-12-new-feature-bit
Matt Corallo [Tue, 7 Dec 2021 19:28:29 +0000 (19:28 +0000)]
Merge pull request #1205 from TheBlueMatt/2021-12-new-feature-bit

Support the channel_type feature bit.

2 years agoReduce force-closures with user fee estimators which round poorly 2021-12-less-force-close
Matt Corallo [Tue, 7 Dec 2021 17:23:42 +0000 (17:23 +0000)]
Reduce force-closures with user fee estimators which round poorly

See comment for more

2 years agoSupport the `channel_type` feature bit. 2021-12-new-feature-bit
Matt Corallo [Mon, 6 Dec 2021 00:18:59 +0000 (00:18 +0000)]
Support the `channel_type` feature bit.

Note that this feature bit does absolutely nothing. We signal it
(as we already support channel type negotiation), but do not bother
to look to see if peers support it, as we don't care - we simply
look for the TLV entry and deduce if a peer supports channel type
negotiation from that.

The only behavioral change at all here is that we don't barf if a
peer sets channel type negotiation to required via the feature bit
(instead of failing the channel at open-time), but of course no
implementations do this, and likely won't for some time (if ever -
you can simply fail channels with unknown types later, and there's
no reason to refuse connections, really).

As defined in https://github.com/lightning/bolts/pull/906

2 years agoGetter for the total channel balance
Devrandom [Sun, 5 Dec 2021 11:42:25 +0000 (12:42 +0100)]
Getter for the total channel balance

The existing balance getters subtract reserve, this one does not.

2 years agoMerge pull request #1201 from jkczyz/2021-12-idempotent-channelmanager
Matt Corallo [Tue, 7 Dec 2021 00:42:02 +0000 (00:42 +0000)]
Merge pull request #1201 from jkczyz/2021-12-idempotent-channelmanager

Ensure ChannelManager methods are idempotent

2 years agoEnsure ChannelManager methods are idempotent
Jeffrey Czyz [Fri, 3 Dec 2021 19:04:58 +0000 (13:04 -0600)]
Ensure ChannelManager methods are idempotent

During event handling, ChannelManager methods may need to be called as
indicated in the Event documentation. Ensure that these calls are
idempotent for the same event rather than panicking. This allows users
to persist events for later handling without needing to worry about
processing the same event twice (e.g., if ChannelManager is not
persisted but the events were, the restarted ChannelManager would return
some of the same events).

2 years agoMerge pull request #1204 from TheBlueMatt/2021-12-no-torv2
Matt Corallo [Mon, 6 Dec 2021 22:49:18 +0000 (22:49 +0000)]
Merge pull request #1204 from TheBlueMatt/2021-12-no-torv2

Remove OnionV2 parsing support

2 years agoMerge pull request #1130 from TheBlueMatt/2021-10-mon-fail-after-conf
Matt Corallo [Mon, 6 Dec 2021 19:35:58 +0000 (19:35 +0000)]
Merge pull request #1130 from TheBlueMatt/2021-10-mon-fail-after-conf

Always return failure in update_monitor after funding spend

2 years agoAdd trivial test of monitor update failure during block connection 2021-10-mon-fail-after-conf
Matt Corallo [Sun, 28 Nov 2021 17:13:38 +0000 (17:13 +0000)]
Add trivial test of monitor update failure during block connection

2 years agoAdd a test for MonitorEvent holding when they complete out-of-order
Matt Corallo [Tue, 19 Oct 2021 23:44:29 +0000 (23:44 +0000)]
Add a test for MonitorEvent holding when they complete out-of-order

2 years agoAdd a simple test for ChainMonitor MonitorUpdate-holding behavior
Matt Corallo [Sun, 17 Oct 2021 21:24:39 +0000 (21:24 +0000)]
Add a simple test for ChainMonitor MonitorUpdate-holding behavior

2 years agoMake APIError debug output more clear by including the variant
Matt Corallo [Sun, 17 Oct 2021 21:24:53 +0000 (21:24 +0000)]
Make APIError debug output more clear by including the variant

2 years agoDrop `MonitorUpdateErr` in favor of opaque errors.
Matt Corallo [Mon, 29 Nov 2021 21:36:12 +0000 (21:36 +0000)]
Drop `MonitorUpdateErr` in favor of opaque errors.

We don't expect users to ever change behavior based on the string
contained in a `MonitorUpdateErr`, except log it, so there's little
reason to not just log it ourselves and return a `()` for errors.

We do so here, simplifying the callsite in `ChainMonitor` as well.

2 years agoAlways return failure in `update_monitor` after funding spend
Matt Corallo [Sun, 17 Oct 2021 21:28:50 +0000 (21:28 +0000)]
Always return failure in `update_monitor` after funding spend

Previously, monitor updates were allowed freely even after a
funding-spend transaction confirmed. This would allow a race
condition where we could receive a payment (including the
counterparty revoking their broadcasted state!) and accept it
without recourse as long as the ChannelMonitor receives the block
first, the full commitment update dance occurs after the block is
connected, and before the ChannelManager receives the block.

Obviously this is an incredibly contrived race given the
counterparty would be risking their full channel balance for it,
but its worth fixing nonetheless as it makes the potential
ChannelMonitor states simpler to reason about.

The test in this commit also tests the behavior changed in the
previous commit.

2 years agoDefine public getters for all feature flags
Matt Corallo [Fri, 23 Jul 2021 15:49:24 +0000 (15:49 +0000)]
Define public getters for all feature flags

There's not a ton of reason not to do this, and moving it to the
macro removes some code.

2 years agoRemove OnionV2 parsing support 2021-12-no-torv2
Matt Corallo [Mon, 6 Dec 2021 00:12:35 +0000 (00:12 +0000)]
Remove OnionV2 parsing support

OnionV2s don't (really) work on Tor anymore anyway, and the field
is set for removal in the BOLTs [1]. Sadly because of the way
addresses are parsed we have to continue to understand that type 3
addresses are 12 bytes long. Thus, for simplicity we keep the
`OnionV2` enum variant around and just make it an opaque 12 bytes,
with the documentation updated to note the deprecation.

[1] https://github.com/lightning/bolts/pull/940

2 years agoMerge pull request #1197 from jkczyz/2021-11-score-successful-payment-path
Matt Corallo [Fri, 3 Dec 2021 21:04:41 +0000 (21:04 +0000)]
Merge pull request #1197 from jkczyz/2021-11-score-successful-payment-path

Score successful payment paths

2 years agoFix shift overflow in Scorer::channel_penalty_msat
Jeffrey Czyz [Wed, 1 Dec 2021 04:57:32 +0000 (22:57 -0600)]
Fix shift overflow in Scorer::channel_penalty_msat

An unchecked shift of more than 64 bits on u64 values causes a shift
overflow panic. This may happen if a channel is penalized only once and
(1) is not successfully routed through and (2) after 64 or more half
life decays. Use a checked shift to prevent this from happening.

2 years agoDecay channel failure penalty upon success
Jeffrey Czyz [Wed, 1 Dec 2021 00:27:08 +0000 (18:27 -0600)]
Decay channel failure penalty upon success

If a payment failed to route through a channel, a penalty is applied to
the channel in the future when finding a route. This penalty decays over
time. Immediately decay the penalty by one half life when a payment is
successfully routed through the channel.

2 years agoScore successful payment paths
Jeffrey Czyz [Tue, 30 Nov 2021 23:16:05 +0000 (17:16 -0600)]
Score successful payment paths

Expand the Score trait with a payment_path_successful function for
scoring successful payment paths. Called by InvoicePayer's EventHandler
implementation when processing PaymentPathSuccessful events. May be used
by Score implementations to revert any channel penalties that were
applied by calls to payment_path_failed.

2 years agoMerge pull request #1196 from TheBlueMatt/2021-11-bad-rustdoc
Matt Corallo [Wed, 1 Dec 2021 20:14:14 +0000 (20:14 +0000)]
Merge pull request #1196 from TheBlueMatt/2021-11-bad-rustdoc

Fix compilation in `payment` rustdoc examples

2 years agoFix compilation in `payment` rustdoc examples 2021-11-bad-rustdoc
Matt Corallo [Tue, 30 Nov 2021 21:01:39 +0000 (21:01 +0000)]
Fix compilation in `payment` rustdoc examples

The samples were not valid rust, but previous versions of rustc had
a bug where they were accepted anyway. Latest rustc beta no longer
accepts these.

2 years agoMerge pull request #1195 from TheBlueMatt/2021-11-chanman-read-regression
Matt Corallo [Tue, 30 Nov 2021 15:35:27 +0000 (15:35 +0000)]
Merge pull request #1195 from TheBlueMatt/2021-11-chanman-read-regression

Fix regression when reading `Event::PaymentReceived` in some cases

2 years agoFix regression when reading `Event::PaymentReceived` in some cases 2021-11-chanman-read-regression
Matt Corallo [Mon, 29 Nov 2021 20:05:35 +0000 (20:05 +0000)]
Fix regression when reading `Event::PaymentReceived` in some cases

For some reason rustc was deciding on a type for the `Option` being
deserialized for us as `_user_payment_id`. This really, really,
absolutely should have been a compile failure - the type (with
methods called on it!) was ambiguous! Instead, rustc seems to have
been defaulting to `Option<()>`, causing us to read zero of the
eight bytes in the `user_payment_id` field, which returns an
`Err(InvalidValue)` error as TLVs must always be read fully.

This should likely be reported to rustc as its definitely a bug,
but I cannot seem to cause the same error on any kinda of
vaguely-minimized version of the same code.

Found by `chanmon_consistency` fuzz target.

2 years agoMerge pull request #1163 from TheBlueMatt/2021-11-support-insecure-counterparty
Matt Corallo [Mon, 29 Nov 2021 21:02:36 +0000 (21:02 +0000)]
Merge pull request #1163 from TheBlueMatt/2021-11-support-insecure-counterparty

Explicitly support counterparty setting 0 channel reserve

2 years agoExplicitly support counterparty setting 0 channel reserve 2021-11-support-insecure-counterparty
Matt Corallo [Tue, 9 Nov 2021 21:25:33 +0000 (21:25 +0000)]
Explicitly support counterparty setting 0 channel reserve

A peer providing a channel_reserve_satoshis of 0 (or less than our
dust limit) is insecure, but only for them. Because some LSPs do it
with some level of trust of the clients (for a substantial UX
improvement), we explicitly allow it. Because its unlikely to
happen often in normal testing, we test it explicitly here.

2 years agoMerge pull request #1189 from TheBlueMatt/2021-11-trivial-impls
Matt Corallo [Mon, 29 Nov 2021 16:56:23 +0000 (16:56 +0000)]
Merge pull request #1189 from TheBlueMatt/2021-11-trivial-impls

Derive `Clone` and friends on additional public structs

2 years agoImplement Clone for InvalidShutdownScript 2021-11-trivial-impls
Matt Corallo [Tue, 19 Oct 2021 06:20:12 +0000 (06:20 +0000)]
Implement Clone for InvalidShutdownScript

Users hopefully shouldn't have much of a reason to use this, but
the bindings may need it to ensure no leaking pointers over an ffi.

2 years agoImplement Clone, Hash, PartialEq for ClosingTransaction
Matt Corallo [Tue, 19 Oct 2021 06:19:28 +0000 (06:19 +0000)]
Implement Clone, Hash, PartialEq for ClosingTransaction

This is a public struct intended to be used as an object by users,
so it should likely have common implementations, given they're
trivial.

2 years agoContinue after a single failure in `ChannelMonitor::update_monitor`
Matt Corallo [Sun, 17 Oct 2021 21:26:04 +0000 (21:26 +0000)]
Continue after a single failure in `ChannelMonitor::update_monitor`

`ChannelMonitorUpdate`s may contain multiple updates, including, eg
a payment preimage after a commitment transaction update. While
such updates are generally not generated today, we shouldn't return
early out of the update loop, causing us to miss any updates after
an earlier update fails.

2 years agoPrefer fully-specified paths in test macros
Matt Corallo [Sun, 17 Oct 2021 21:23:51 +0000 (21:23 +0000)]
Prefer fully-specified paths in test macros

This avoids macros being context-specific use-dependent.

2 years agoAllow missing-docs on test-only macros
Matt Corallo [Wed, 20 Oct 2021 01:35:01 +0000 (01:35 +0000)]
Allow missing-docs on test-only macros

2 years agoMerge pull request #1184 from TheBlueMatt/2021-11-c-bindings-tweaks
Matt Corallo [Wed, 24 Nov 2021 20:03:14 +0000 (20:03 +0000)]
Merge pull request #1184 from TheBlueMatt/2021-11-c-bindings-tweaks

C Bindings Compatibility Tweaks

2 years agoSeal `scoring::Time` and only use `Instant` or `Eternity` publicly 2021-11-c-bindings-tweaks
Matt Corallo [Mon, 22 Nov 2021 18:00:08 +0000 (18:00 +0000)]
Seal `scoring::Time` and only use `Instant` or `Eternity` publicly

`scoring::Time` exists in part to make testing the passage of time
in `Scorer` practical. To allow no-std users to provide a time
source it was exposed as a trait as well. However, it seems
somewhat unlikely that a no-std user is going to have a use for
providing their own time source (otherwise they wouldn't be a
no-std user), and likely they won't have a graph in memory either.

`scoring::Time` as currently written is also exceptionally hard to
write C bindings for - the C bindings trait mappings relies on the
ability to construct trait implementations at runtime with function
pointers (i.e. `dyn Trait`s). `scoring::Time`, on the other hand,
is a supertrait of `core::ops::Sub` which requires a `sub` method
which takes a type parameter and returns a type parameter. Both of
which aren't practical in bindings, especially given the
`Sub::Output` associated type is not bound by any trait bounds at
all (implying we cannot simply map the `sub` function to return an
opaque trait object).

Thus, for simplicity, we here simply seal `scoring::Time` and make
it effectively-private, ensuring the bindings don't need to bother
with it.

2 years agoMake `Score : Writeable` in c_bindings and impl on `LockedScore`
Matt Corallo [Mon, 22 Nov 2021 03:27:17 +0000 (03:27 +0000)]
Make `Score : Writeable` in c_bindings and impl on `LockedScore`

Ultimately we likely need to wrap the locked `Score` in a struct
that exposes writeable somehow, but because all traits have to be
fully concretized for C bindings we'll still need `Writeable` on
all `Score` in order to expose `Writeable` on the locked score.
Otherwise, we'll only have a `LockedScore` with a `Score` visible
that only has the `Score` methods, never the original type.

2 years agoMerge pull request #1186 from TheBlueMatt/2021-11-fix-log-select
Matt Corallo [Wed, 24 Nov 2021 16:31:32 +0000 (16:31 +0000)]
Merge pull request #1186 from TheBlueMatt/2021-11-fix-log-select

Fix the `max_level_trace` feature

2 years agoTest all log-limiting features in CI 2021-11-fix-log-select
Matt Corallo [Tue, 23 Nov 2021 23:03:34 +0000 (23:03 +0000)]
Test all log-limiting features in CI

2 years agoFix compilation with the max_level_trace feature
Matt Corallo [Tue, 23 Nov 2021 23:03:13 +0000 (23:03 +0000)]
Fix compilation with the max_level_trace feature

2 years agoStore holder channel reserve and max-htlc-in-flight explicitly
Matt Corallo [Tue, 9 Nov 2021 21:12:30 +0000 (21:12 +0000)]
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.

2 years agoMerge pull request #1162 from TheBlueMatt/2021-11-fix-accept-chan-checks
Matt Corallo [Tue, 23 Nov 2021 20:46:38 +0000 (20:46 +0000)]
Merge pull request #1162 from TheBlueMatt/2021-11-fix-accept-chan-checks

Correct initial commitment tx fee affordability checks on open

2 years agoMerge pull request #1178 from jkczyz/2021-11-payment-path-successful
Matt Corallo [Tue, 23 Nov 2021 20:39:28 +0000 (20:39 +0000)]
Merge pull request #1178 from jkczyz/2021-11-payment-path-successful

Generate PaymentPathSuccessful event for each path

2 years agoMerge pull request #1176 from lightning-signer/2021-11-htlc-anchors
Matt Corallo [Tue, 23 Nov 2021 19:37:09 +0000 (19:37 +0000)]
Merge pull request #1176 from lightning-signer/2021-11-htlc-anchors

Add anchors support for HTLCs

2 years agoGenerate PaymentPathSuccessful event for each path
Jeffrey Czyz [Thu, 18 Nov 2021 22:24:14 +0000 (16:24 -0600)]
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.

2 years agoAdd test vectors for get_htlc_redeemscript wrt anchors
Ken Sedgwick [Tue, 16 Nov 2021 19:40:27 +0000 (11:40 -0800)]
Add test vectors for get_htlc_redeemscript wrt anchors

2 years agoAdjust HTLC_{SUCCESS,TIMEOUT}_TX_WEIGHT when anchors used
Ken Sedgwick [Tue, 16 Nov 2021 17:27:33 +0000 (09:27 -0800)]
Adjust HTLC_{SUCCESS,TIMEOUT}_TX_WEIGHT when anchors used

2 years agoAdd anchor support to build_htlc_transaction
Ken Sedgwick [Tue, 16 Nov 2021 03:39:39 +0000 (19:39 -0800)]
Add anchor support to build_htlc_transaction

2 years agoIncrease visibility of anchor related methods
Ken Sedgwick [Tue, 16 Nov 2021 02:50:57 +0000 (18:50 -0800)]
Increase visibility of anchor related methods

2 years agoAdd anchor support to commitment HTLC outputs
Ken Sedgwick [Tue, 16 Nov 2021 02:03:46 +0000 (18:03 -0800)]
Add anchor support to commitment HTLC outputs

2 years agoSupport `logger::Record` in C by String-ing the fmt::Arguments
Matt Corallo [Sun, 21 Nov 2021 22:29:48 +0000 (22:29 +0000)]
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.

2 years agoTest fixed channel reserve checks on channel open 2021-11-fix-accept-chan-checks
Matt Corallo [Wed, 10 Nov 2021 04:40:33 +0000 (04:40 +0000)]
Test fixed channel reserve checks on channel open

2 years agoCorrect initial commitment tx fee affordability checks on open
Matt Corallo [Wed, 10 Nov 2021 01:36:26 +0000 (01:36 +0000)]
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.

2 years agoRewrite test_update_fee_that_funder_cannot_afford to avoid magic
Matt Corallo [Wed, 10 Nov 2021 03:44:04 +0000 (03:44 +0000)]
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.

2 years agoMake Channel::commit_tx_fee_msat static and take fee explicitly
Matt Corallo [Mon, 15 Nov 2021 23:22:08 +0000 (23:22 +0000)]
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.

2 years agoMerge pull request #1054 from ariard/2021-08-check-outbound-feerate
Matt Corallo [Mon, 22 Nov 2021 22:45:51 +0000 (22:45 +0000)]
Merge pull request #1054 from ariard/2021-08-check-outbound-feerate

Check for outbound feerate update affordability before sending

2 years agoMerge pull request #1168 from TheBlueMatt/2021-11-mpp-routing-fixes
Matt Corallo [Mon, 22 Nov 2021 21:55:06 +0000 (21:55 +0000)]
Merge pull request #1168 from TheBlueMatt/2021-11-mpp-routing-fixes

Fix MPP routefinding when we first collect 95% of payment value

2 years agoCheck outbound update_fee affordance incremented with holding cell HTLCs
Antoine Riard [Mon, 22 Nov 2021 02:42:58 +0000 (21:42 -0500)]
Check outbound update_fee affordance incremented with holding cell HTLCs

2 years agoFix MPP routefinding when we first collect 95% of payment value 2021-11-mpp-routing-fixes
Matt Corallo [Mon, 8 Nov 2021 03:17:34 +0000 (03:17 +0000)]
Fix MPP routefinding when we first collect 95% of payment value

See comment in new test for more details.

2 years agoMerge pull request #1145 from tnull/add_gossip_log_level
Matt Corallo [Mon, 22 Nov 2021 18:58:56 +0000 (18:58 +0000)]
Merge pull request #1145 from tnull/add_gossip_log_level

Introduce GOSSIP log level to PeerHandler

2 years agoAdd a new log-level for gossip messages.
Elias Rohrer [Mon, 22 Nov 2021 17:19:08 +0000 (18:19 +0100)]
Add a new log-level for gossip messages.

2 years agoMerge pull request #1180 from valentinewallace/2021-11-remove-user-pmt-id
Matt Corallo [Mon, 22 Nov 2021 16:40:37 +0000 (16:40 +0000)]
Merge pull request #1180 from valentinewallace/2021-11-remove-user-pmt-id

Remove user_payment_id

2 years agoMerge pull request #1182 from TheBlueMatt/2021-11-fix-txid-log
Matt Corallo [Mon, 22 Nov 2021 15:41:19 +0000 (15:41 +0000)]
Merge pull request #1182 from TheBlueMatt/2021-11-fix-txid-log

Trivial Logging Fixes

2 years agoIntroduce CommitmentStats
Antoine Riard [Fri, 19 Nov 2021 02:23:41 +0000 (21:23 -0500)]
Introduce CommitmentStats

2 years agoRe-add `test_max_dust_htlc_exposure`
Antoine Riard [Tue, 28 Sep 2021 00:14:06 +0000 (20:14 -0400)]
Re-add `test_max_dust_htlc_exposure`

2 years agoEnsure current channel state is logged for all channels on startup 2021-11-fix-txid-log
Matt Corallo [Sat, 20 Nov 2021 22:49:11 +0000 (22:49 +0000)]
Ensure current channel state is logged for all channels on startup

2 years agoCorrect txid logging to reverse bytes.
Matt Corallo [Sat, 20 Nov 2021 22:27:10 +0000 (22:27 +0000)]
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.

2 years agoMerge pull request #1027 from TheBlueMatt/2021-07-check-dust
Matt Corallo [Sat, 20 Nov 2021 03:26:24 +0000 (03:26 +0000)]
Merge pull request #1027 from TheBlueMatt/2021-07-check-dust

Check all outputs meet the dust threshold in `check_spends!()`

2 years agoCheck we won't overflow `max_dust_htlc_exposure_msat` at outbound feerate update
Antoine Riard [Sat, 21 Aug 2021 22:52:05 +0000 (18:52 -0400)]
Check we won't overflow `max_dust_htlc_exposure_msat` at outbound feerate update

2 years agoRemove user_payment_id
Valentine Wallace [Fri, 12 Nov 2021 19:48:39 +0000 (14:48 -0500)]
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.

2 years agoCheck all outputs meet the dust threshold in check_spends!() 2021-07-check-dust
Matt Corallo [Sat, 31 Jul 2021 18:33:57 +0000 (18:33 +0000)]
Check all outputs meet the dust threshold in check_spends!()

2 years agoLimit minimum output size to the dust limit when RBF-bumping
Matt Corallo [Sat, 31 Jul 2021 22:19:45 +0000 (22:19 +0000)]
Limit minimum output size to the dust limit when RBF-bumping

2 years agoCancel the outbound feerate update if above what we can afford
Antoine Riard [Sat, 21 Aug 2021 22:05:51 +0000 (18:05 -0400)]
Cancel the outbound feerate update if above what we can afford

2 years agoIntroduce new helper commit_tx_fee_sat
Antoine Riard [Tue, 19 Oct 2021 17:29:50 +0000 (13:29 -0400)]
Introduce new helper commit_tx_fee_sat

2 years agoMerge pull request #1173 from tnull/add_accept_inbound_channels_option
Matt Corallo [Wed, 17 Nov 2021 19:06:19 +0000 (19:06 +0000)]
Merge pull request #1173 from tnull/add_accept_inbound_channels_option

Add 'accept_inbound_channels' config option.

2 years agoAdd 'accept_inbound_channels' config option.
Elias Rohrer [Wed, 17 Nov 2021 17:54:47 +0000 (18:54 +0100)]
Add 'accept_inbound_channels' config option.

2 years agoMerge pull request #1083 from TheBlueMatt/2021-09-funding-timeout
Matt Corallo [Wed, 17 Nov 2021 17:28:36 +0000 (17:28 +0000)]
Merge pull request #1083 from TheBlueMatt/2021-09-funding-timeout

Automatically close channels that go unfunded for 2016 blocks

2 years agoMerge pull request #1166 from TheBlueMatt/2021-11-chan-size-scoring
Matt Corallo [Tue, 16 Nov 2021 22:10:42 +0000 (22:10 +0000)]
Merge pull request #1166 from TheBlueMatt/2021-11-chan-size-scoring

2 years agoAutomatically close channels that go unfunded for 2016 blocks 2021-09-funding-timeout
Matt Corallo [Sun, 19 Sep 2021 23:49:57 +0000 (23:49 +0000)]
Automatically close channels that go unfunded for 2016 blocks

As recommended by BOLT 2 added in
https://github.com/lightningnetwork/lightning-rfc/pull/839

2 years agoReturn `ClosureReason` from `Channel` chain update methods
Matt Corallo [Thu, 30 Sep 2021 21:35:40 +0000 (21:35 +0000)]
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.

2 years agoMove `Score` into a `scoring` module instead of a top-level module 2021-11-chan-size-scoring
Matt Corallo [Fri, 12 Nov 2021 15:52:59 +0000 (15:52 +0000)]
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.

2 years agoPenalize large HTLCs relative to channels in default `Scorer`
Matt Corallo [Fri, 12 Nov 2021 04:16:23 +0000 (04:16 +0000)]
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.

2 years agoProvide `Score` the HTLC amount and channel capacity
Matt Corallo [Fri, 12 Nov 2021 03:52:58 +0000 (03:52 +0000)]
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".

2 years agoMerge pull request #1160 from jkczyz/2011-11-spontaneous-invoice-payer
Matt Corallo [Tue, 16 Nov 2021 20:56:40 +0000 (20:56 +0000)]
Merge pull request #1160 from jkczyz/2011-11-spontaneous-invoice-payer

Retries for spontaneous payments

2 years agoAdd PaymentHash parameter to Router::find_route
Jeffrey Czyz [Fri, 12 Nov 2021 03:47:59 +0000 (21:47 -0600)]
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.

2 years agoTest retrying payment on partial send failure
Jeffrey Czyz [Tue, 16 Nov 2021 04:47:40 +0000 (22:47 -0600)]
Test retrying payment on partial send failure

Add some test coverage for when InvoicePayer retries within pay_invoice
because the Payer returned a partial failure.

2 years agoReplace expect_value_msat with expect_send
Jeffrey Czyz [Wed, 10 Nov 2021 00:07:23 +0000 (18:07 -0600)]
Replace expect_value_msat with expect_send

Modify all InvoicePayer unit tests to use expect_send instead of
expect_value_msat, since the former can discern whether the send was for
an invoice, spontaneous payment, or a retry. Updates tests to set payer
expectations if they weren't already and assert these before returning a
failure.

2 years agoSupport spontaneous payments in InvoicePayer
Jeffrey Czyz [Tue, 9 Nov 2021 23:32:37 +0000 (17:32 -0600)]
Support spontaneous payments in InvoicePayer

InvoicePayer handles retries not only when handling PaymentPathFailed
events but also for some types of PaymentSendFailure on the initial
send. Expand InvoicePayer's interface with a pay_pubkey function for
spontaneous (keysend) payments. Add a send_spontaneous_payment function
to the Payer trait to support this and implement it for ChannelManager.

2 years agoRefactor InvoicePayer for spontaneous payments
Jeffrey Czyz [Tue, 9 Nov 2021 15:37:34 +0000 (09:37 -0600)]
Refactor InvoicePayer for spontaneous payments

To support spontaneous payments, InvoicePayer's sending logic must be
invoice-agnostic. Refactor InvoicePayer::pay_invoice_internal such that
invoice-specific code is in pay_invoice_using_amount and the remaining
logic is in pay_internal.

Further refactor the code's payment_cache locking such that it is
accessed consistently when needed, and tidy up the code a bit.

2 years agoMerge pull request #1161 from TheBlueMatt/2021-11-fix-chan-type-ser
Matt Corallo [Tue, 16 Nov 2021 18:18:01 +0000 (18:18 +0000)]
Merge pull request #1161 from TheBlueMatt/2021-11-fix-chan-type-ser

Correct Channel type serialization logic

2 years agoCorrect Channel type serialization logic 2021-11-fix-chan-type-ser
Matt Corallo [Tue, 9 Nov 2021 21:22:47 +0000 (21:22 +0000)]
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).

2 years agoMerge pull request #1119 from TheBlueMatt/2021-10-less-aggressive-htlc-timeouts
Matt Corallo [Tue, 16 Nov 2021 16:18:20 +0000 (16:18 +0000)]
Merge pull request #1119 from TheBlueMatt/2021-10-less-aggressive-htlc-timeouts

Be less aggressive in outbound HTLC CLTV timeout checks

2 years agoBe less aggressive in outbound HTLC CLTV timeout checks 2021-10-less-aggressive-htlc-timeouts
Matt Corallo [Wed, 13 Oct 2021 04:19:13 +0000 (04:19 +0000)]
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.

3 years agoMerge pull request #1131 from TheBlueMatt/2021-10-upstream-dust
Matt Corallo [Sat, 13 Nov 2021 00:23:28 +0000 (00:23 +0000)]
Merge pull request #1131 from TheBlueMatt/2021-10-upstream-dust

Use upstream rust-bitcoin's dust calculation instead of our own

3 years agoUse upstream rust-bitcoin's dust calculation instead of our own 2021-10-upstream-dust
Matt Corallo [Mon, 11 Oct 2021 17:22:08 +0000 (17:22 +0000)]
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.

3 years agoMerge pull request #1143 from TheBlueMatt/2021-10-no-payment-id-leaks
Matt Corallo [Fri, 12 Nov 2021 17:59:18 +0000 (17:59 +0000)]
Merge pull request #1143 from TheBlueMatt/2021-10-no-payment-id-leaks

Fix a minor memory leak on PermanentFailure mon errs when sending

3 years agoMerge pull request #1165 from lightning-signer/2021-11-fix-anchors
Matt Corallo [Fri, 12 Nov 2021 15:22:41 +0000 (15:22 +0000)]
Merge pull request #1165 from lightning-signer/2021-11-fix-anchors

Fix countersignatory (to_remote) output redeemscript when anchors enabled

3 years agoRenamed script_for_p2wpkh to get_p2wpkh_redeemscript to match convention
Ken Sedgwick [Thu, 11 Nov 2021 20:01:44 +0000 (12:01 -0800)]
Renamed script_for_p2wpkh to get_p2wpkh_redeemscript to match convention