rust-lightning
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 agoMerge pull request #1064 from lightning-signer/2021-08-closing-tx-phase2
Matt Corallo [Thu, 9 Sep 2021 19:31:47 +0000 (19:31 +0000)]
Merge pull request #1064 from lightning-signer/2021-08-closing-tx-phase2

2 years agoUse ClosingTransaction in BaseSign
Devrandom [Wed, 1 Sep 2021 12:56:50 +0000 (14:56 +0200)]
Use ClosingTransaction in BaseSign

2 years agoIntroduce ClosingTransaction
Devrandom [Wed, 1 Sep 2021 12:38:01 +0000 (14:38 +0200)]
Introduce ClosingTransaction

2 years agoMerge pull request #1047 from TheBlueMatt/2021-08-985-followups
Matt Corallo [Thu, 9 Sep 2021 09:23:08 +0000 (09:23 +0000)]
Merge pull request #1047 from TheBlueMatt/2021-08-985-followups

2 years agoAdd further comments around fee update handling in channel 2021-08-985-followups
Matt Corallo [Mon, 16 Aug 2021 18:02:59 +0000 (18:02 +0000)]
Add further comments around fee update handling in channel

These were suggested to clarify behavior in post-merge review of #985.

2 years agoUpdate docs for pending_update_fee and holding_cell_update_fee
Matt Corallo [Mon, 16 Aug 2021 17:47:36 +0000 (17:47 +0000)]
Update docs for pending_update_fee and holding_cell_update_fee

The docs were left stale after the logic was updated in #985 as
pointed out in post-merge review.

2 years agoFactor out low-level build_closing_transaction
Devrandom [Tue, 31 Aug 2021 13:23:48 +0000 (15:23 +0200)]
Factor out low-level build_closing_transaction

2 years agoMerge pull request #1055 from lightning-signer/2021-08-anchor-tx
Matt Corallo [Thu, 2 Sep 2021 21:54:11 +0000 (21:54 +0000)]
Merge pull request #1055 from lightning-signer/2021-08-anchor-tx

2 years agoAdd anchor outputs pair in CommitmentTransaction
Devrandom [Sun, 22 Aug 2021 09:08:28 +0000 (11:08 +0200)]
Add anchor outputs pair in CommitmentTransaction

The anchor ouputs pair is added if there are pending HTLCs. Or a
a per-party anchor is added if the party has a pending balance.

2 years agoMerge pull request #1057 from TheBlueMatt/2021-08-invoice-fails
Matt Corallo [Tue, 31 Aug 2021 22:11:22 +0000 (22:11 +0000)]
Merge pull request #1057 from TheBlueMatt/2021-08-invoice-fails

Fix and modernize lightning-invoice API

2 years agoRequire payment secrets when building and reading invoices 2021-08-invoice-fails
Matt Corallo [Fri, 27 Aug 2021 02:21:32 +0000 (02:21 +0000)]
Require payment secrets when building and reading invoices

2 years agoUse new BOLT 11 test vectors with payment_secrets and feature flags
Matt Corallo [Tue, 24 Aug 2021 23:22:55 +0000 (23:22 +0000)]
Use new BOLT 11 test vectors with payment_secrets and feature flags

This pulls the BOLT 11 test vectors from
https://github.com/lightningnetwork/lightning-rfc/pull/898,
tweaking our tests to properly handle them.

2 years ago[invoice] Ignore InvalidLength fields
Matt Corallo [Tue, 24 Aug 2021 23:15:07 +0000 (23:15 +0000)]
[invoice] Ignore InvalidLength fields

BOLT 11 states that a reader "MUST skip over...`p`, `h`, `s` or `n`
fields that do NOT have data_lengths of 52, 52, 52 or 53,
respectively." Here we do so by simply ignoring any invalid-length
field.

2 years agoImplement core::hash::Hash more incl invoice::RawTaggedField
Matt Corallo [Tue, 24 Aug 2021 21:00:17 +0000 (21:00 +0000)]
Implement core::hash::Hash more incl invoice::RawTaggedField

2 years agoCheck if invoices contain unknown required features
Matt Corallo [Sun, 22 Aug 2021 19:54:08 +0000 (19:54 +0000)]
Check if invoices contain unknown required features

This adds the final missing BOLT 11 failure test, checking for
unknown required feature flags before accepting an invoice.

2 years agoConvert the invoice creation API to millisats and req it for parse
Matt Corallo [Sun, 22 Aug 2021 19:42:29 +0000 (19:42 +0000)]
Convert the invoice creation API to millisats and req it for parse

The BOLT 11 invalid invoice test vectors suggest failing to parse
invoices which have an amount which is not a whole number of
millisatoshis. lightning-invoice, however, happily parses such
invoices. While we could continue to parse them, failing them makes
for one less check on the user code side, so we might as well.

In order to keep the invoice creation less likely to fail, we also
switch the Builder amount-setting function to use millisatoshis.

2 years ago[invoice] Fix non-recoverable sig handling and bogus SI prefix err
Matt Corallo [Sun, 22 Aug 2021 19:36:01 +0000 (19:36 +0000)]
[invoice] Fix non-recoverable sig handling and bogus SI prefix err

This adds two additional tests from the BOLT 11 invalid invoice
tests, fixing the two errors that broke them. It fixes a panic on
the "nonrecoverable signature" test and makes the error variant
more sensible on the bogus SI prefix test.

2 years ago[invoice] Add the BOLT 11 failure unit tests that we already pass
Matt Corallo [Sun, 22 Aug 2021 19:35:15 +0000 (19:35 +0000)]
[invoice] Add the BOLT 11 failure unit tests that we already pass

2 years agoMerge pull request #1040 from abhik-99/Issue#945
Matt Corallo [Tue, 31 Aug 2021 17:50:14 +0000 (17:50 +0000)]
Merge pull request #1040 from abhik-99/Issue#945

Multi-Hop Route Hint now considered. Added in unit tests for same.

2 years agoMulti-Hop Route Hint as per Bolt 12 now considered
abhik-99 [Mon, 9 Aug 2021 15:06:51 +0000 (20:36 +0530)]
Multi-Hop Route Hint as per Bolt 12 now considered

Bolt 12 details the process of picking up route hints from payee
using the lightning invoice. This PR brings the changes to use
multiple route hints from payee picked from the invoice.

The route hints are processed in the following manner:-
 - `get_route()` receives the hints in `last_hops`.
 - Every `RouteHintHop` in `RouteHint` is processed based on
   feasiblity of channel capacity and fees.
 - If a `RouteHintHop` then preceeding `RouteHintHop`s are not
   processed.
 - A direct route is checked from `first_hops_targets` to the
   first `RouteHintHop` if the respective `RouteHint` is
   processed from the payee's end till the first `RouteHintHop`.

`partial_route_hint_test`, `ignores_empty_last_hops_test`,
`multi_hint_last_hops_test` and `last_hops_with_public_channel_test`
test usage of partial route hints for building optimal route,
processing empty route hint hops, complete usage of private route
hints and presence of public channels in route hints respectively.

Resolves: #945

2 years agoMerge pull request #1039 from lightning-signer/2021-08-more-enforcement
Matt Corallo [Mon, 30 Aug 2021 02:43:01 +0000 (02:43 +0000)]
Merge pull request #1039 from lightning-signer/2021-08-more-enforcement

Introduce EnforcementState, validate release of revocation secret

2 years agoAdd get_anchor_script
Antoine Riard [Tue, 26 May 2020 07:55:03 +0000 (09:55 +0200)]
Add get_anchor_script

This is a script builder to generate anchor output ones. They can be
satisfied either by a signature for the committed funding pubkey or anyone
after CSV delay expiration.

This is used at anchor output addition while generating commitment transaction.

2 years agoAllow BaseSign validation functions to return an Err
Devrandom [Fri, 20 Aug 2021 19:57:18 +0000 (21:57 +0200)]
Allow BaseSign validation functions to return an Err

2 years agoImprove documentation for validate_holder_commitment and sign_counterparty_commitment
Devrandom [Thu, 19 Aug 2021 07:51:45 +0000 (09:51 +0200)]
Improve documentation for validate_holder_commitment and sign_counterparty_commitment

2 years agoAlways use KeysInterface.read_chan_signer for de-serializing EnforcingSigner in tests
Devrandom [Tue, 17 Aug 2021 11:04:29 +0000 (13:04 +0200)]
Always use KeysInterface.read_chan_signer for de-serializing EnforcingSigner in tests

2 years agoEnforce signing counterparty commitment only after revocation
Devrandom [Mon, 9 Aug 2021 14:48:06 +0000 (16:48 +0200)]
Enforce signing counterparty commitment only after revocation

2 years agoEnforce that revocation can only occur after we validated a new commitment
Devrandom [Mon, 9 Aug 2021 10:09:39 +0000 (12:09 +0200)]
Enforce that revocation can only occur after we validated a new commitment

2 years agoIntroduce EnforcementState for EnforcingSigner
Devrandom [Mon, 9 Aug 2021 08:56:15 +0000 (10:56 +0200)]
Introduce EnforcementState for EnforcingSigner

as we add more enforcement state variables, we want to keep track of them under a single structure

2 years agoMerge pull request #1060 from JosephGoulden/function_test_utils_logs
Matt Corallo [Fri, 27 Aug 2021 02:37:00 +0000 (02:37 +0000)]
Merge pull request #1060 from JosephGoulden/function_test_utils_logs

tests: use origin node logger instead of creating new TestLogger

2 years agoMerge pull request #1031 from p2pderivatives/dlc-version-generic
Matt Corallo [Wed, 25 Aug 2021 17:22:20 +0000 (17:22 +0000)]
Merge pull request #1031 from p2pderivatives/dlc-version-generic

Dlc version generic

2 years agoRemove wire::MessageType in favor of u16
Jeffrey Czyz [Wed, 18 Aug 2021 15:41:01 +0000 (10:41 -0500)]
Remove wire::MessageType in favor of u16

With custom messages, wire::Type was introduced. wire::MessageType is a
bit redundant, so use u16 instead and move is_even to wire::Message.

2 years agoAdd custom message handler to peer manager
Tibo-lg [Thu, 5 Aug 2021 05:51:17 +0000 (14:51 +0900)]
Add custom message handler to peer manager

2 years agoMerge pull request #1037 from sr-gi/add-txid-convert
Matt Corallo [Tue, 24 Aug 2021 18:57:51 +0000 (18:57 +0000)]
Merge pull request #1037 from sr-gi/add-txid-convert

Adds Txid to lighting-block-sync::convert

2 years agotests: use origin node logger instead of creating new TestLogger in functional_test_utils
Joseph Goulden [Tue, 24 Aug 2021 15:53:29 +0000 (16:53 +0100)]
tests: use origin node logger instead of creating new TestLogger in functional_test_utils

2 years agoAdds Txid to lighting-block-sync::convert
Sergi Delgado Segura [Fri, 6 Aug 2021 14:13:37 +0000 (16:13 +0200)]
Adds Txid to lighting-block-sync::convert

2 years ago[invoice] Update doctest example invoices to real LDK invoices
Matt Corallo [Sun, 22 Aug 2021 22:11:34 +0000 (22:11 +0000)]
[invoice] Update doctest example invoices to real LDK invoices

This swaps out our doctest example invoices for real LDK-generated
invoices on a real LDK node.

2 years agoMerge pull request #1051 from JosephGoulden/fix_ping_disconnect
Matt Corallo [Fri, 20 Aug 2021 18:06:58 +0000 (18:06 +0000)]
Merge pull request #1051 from JosephGoulden/fix_ping_disconnect

fix: peer is disconnected for not responding to ping

2 years agotest: increase ping timeout when running in debug mode
Joseph Goulden [Fri, 20 Aug 2021 14:48:40 +0000 (15:48 +0100)]
test: increase ping timeout when running in debug mode

2 years agoMerge pull request #1049 from TheBlueMatt/2021-08-nightly-warnings
Matt Corallo [Wed, 18 Aug 2021 19:10:54 +0000 (19:10 +0000)]
Merge pull request #1049 from TheBlueMatt/2021-08-nightly-warnings

Fix trailing semicolon warnings on latest rustc nightly

2 years agoFix trailing semicolon warnings on latest rustc nightly 2021-08-nightly-warnings
Matt Corallo [Wed, 18 Aug 2021 00:33:56 +0000 (00:33 +0000)]
Fix trailing semicolon warnings on latest rustc nightly

Latest rustc nightly compiles are filled with warnings like the
following, which we fix here:

```
warning: trailing semicolon in macro used in expression position
   --> lightning/src/util/macro_logger.rs:163:114
    |
163 |         $logger.log(&$crate::util::logger::Record::new($lvl, format_args!($($arg)+), module_path!(), file!(), line!()));
    |                                                                                                                        ^
    |
   ::: lightning/src/chain/chainmonitor.rs:165:9
    |
165 |         log_debug!(self.logger, "New best block {} at height {} provided via block_connected", header.block_hash(), height);
    |         -------------------------------------------------------------------------------------------------------------------- in this macro invocation
    |
    = note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
    = note: this warning originates in the macro `log_internal` (in Nightly builds, run with -Z macro-backtrace for more info)
```

2 years agoMerge pull request #1048 from TheBlueMatt/2021-08-no-net-print
Matt Corallo [Wed, 18 Aug 2021 00:31:28 +0000 (00:31 +0000)]
Merge pull request #1048 from TheBlueMatt/2021-08-no-net-print

Remove explicit print in lightning-net-tokio, reduce redundant block connection logging

2 years agoClarify docs on ShutdownScript::new_witness_program somewhat 2021-08-no-net-print
Matt Corallo [Tue, 17 Aug 2021 19:47:50 +0000 (19:47 +0000)]
Clarify docs on ShutdownScript::new_witness_program somewhat

This is especially important for C or other language bindings
clients as the `version` field may be exported as a `u8`.

2 years agoLog chain calls in ChainMonitor, reducing logs in ChannelMonitor
Matt Corallo [Tue, 17 Aug 2021 00:46:21 +0000 (00:46 +0000)]
Log chain calls in ChainMonitor, reducing logs in ChannelMonitor

For users with many ChannelMonitors, we log a large volume per
block simply because each ChannelMonitor lots several times per
block. Instead, we move to log only once at the TRACE level per
block call in ChannelMonitors, relying instead on a DEBUG level
log in ChainMonitor before we call any ChannelMonitor functions.

For most users, this will reduce redundant logging and also log at
the DEBUG level for block events, which is appropriate.

Fixes #980.

2 years agoStop printing to stderr in lightning-net-tokio for disconnections
Matt Corallo [Tue, 17 Aug 2021 00:04:34 +0000 (00:04 +0000)]
Stop printing to stderr in lightning-net-tokio for disconnections

It isn't exactly a critical error situation when we disconnect a
socket, so we shouldn't be printing to stderr, entirely bypassing
user logging, when it happens. We do still print to stderr if we
fail to write the first message to the socket, but this should
never happen unless the user has a reasonably-configured system
with at least one packet in bytes available for the socket buffer.

2 years agoEnsure we always at least log at TRACE when a peer disconnects
Matt Corallo [Tue, 17 Aug 2021 00:03:31 +0000 (00:03 +0000)]
Ensure we always at least log at TRACE when a peer disconnects

2 years agoMerge pull request #1044 from TheBlueMatt/0.0.100 v0.0.100
Matt Corallo [Tue, 17 Aug 2021 18:55:26 +0000 (18:55 +0000)]
Merge pull request #1044 from TheBlueMatt/0.0.100

Cut 0.0.100

2 years agoUpdate versions to 0.0.100 and lightning-invoice to 0.8 0.0.100
Matt Corallo [Sat, 14 Aug 2021 03:46:08 +0000 (03:46 +0000)]
Update versions to 0.0.100 and lightning-invoice to 0.8

2 years agoUpdate CHANGELOG for 0.0.100
Matt Corallo [Sat, 14 Aug 2021 03:42:51 +0000 (03:42 +0000)]
Update CHANGELOG for 0.0.100

2 years agoMerge pull request #1011 from TheBlueMatt/2021-07-new-closing-fee
Matt Corallo [Tue, 17 Aug 2021 17:53:21 +0000 (17:53 +0000)]
Merge pull request #1011 from TheBlueMatt/2021-07-new-closing-fee

Clean up existing and add range-based closing_signed negotiation

2 years agoAdd relatively simple tests of the legacy and target closing fee 2021-07-new-closing-fee
Matt Corallo [Fri, 13 Aug 2021 23:01:31 +0000 (23:01 +0000)]
Add relatively simple tests of the legacy and target closing fee

This doesn't exhaustively test closing fee negotiation at all, but
ensures that it is at least basically able to come to consensus and
sign cooperative closing transactions.

2 years agoSlightly clarify the closing_signed error msg on fee mismatch
Matt Corallo [Fri, 13 Aug 2021 18:46:50 +0000 (18:46 +0000)]
Slightly clarify the closing_signed error msg on fee mismatch

2 years agoAdd a test for shutdown negotiaion funder restart and timeout
Matt Corallo [Mon, 26 Jul 2021 22:50:49 +0000 (22:50 +0000)]
Add a test for shutdown negotiaion funder restart and timeout

2 years agoForce-close if finish closing_signed negotiation takes a full minute
Matt Corallo [Mon, 26 Jul 2021 20:43:05 +0000 (20:43 +0000)]
Force-close if finish closing_signed negotiation takes a full minute

2 years agoMove shutdown-related tests into a new module
Matt Corallo [Mon, 26 Jul 2021 18:59:03 +0000 (18:59 +0000)]
Move shutdown-related tests into a new module

Because ln::functional_tests if over 9000 LoC long, its useful to
move tests into new modules as we can. Here we move all
cooperative shutdown related tests into a new module entitled
`shutdown_tests`

2 years agoClean up existing and add range-based closing_signed negotiation
Matt Corallo [Tue, 20 Jul 2021 03:19:01 +0000 (03:19 +0000)]
Clean up existing and add range-based closing_signed negotiation

This adds the new range-based closing_signed negotiation specified
in https://github.com/lightningnetwork/lightning-rfc/pull/847 as
well as cleans up the existing closing_signed negotiation to unify
the new codepaths and the old ones.

Note that because the new range-based closing_signed negotiation
allows the channel fundee to ultimately select the fee out of a
range specified by the funder, which we, of course, always select
the highest allowed amount from. Thus, we've added an extra round
of closing_signed in the common case as we will not simply accept
the first fee we see, always preferring to make the funder pay as
much as they're willing to.

2 years agoSend initial closing_signed message asynchronously and handle errs
Matt Corallo [Mon, 19 Jul 2021 19:57:37 +0000 (19:57 +0000)]
Send initial closing_signed message asynchronously and handle errs

When we added the support for external signing, many of the
signing functions were allowed to return an error, closing the
channel in such a case. `sign_closing_transaction` is one such
function which can now return an error, except instead of handling
it properly we'd simply never send a `closing_signed` message,
hanging the channel until users intervene and force-close it.

Piping the channel-closing error back through the various callsites
(several of which already have pending results by the time they
call `maybe_propose_first_closing_signed`) may be rather
complicated, so instead we simply attempt to propose the initial
`closing_signed` in `get_and_clear_pending_msg_events` like we do
for holding-cell freeing.

Further, since we now (possibly) generate a `ChannelMonitorUpdate`
on `shutdown`, we may need to wait for monitor updating to complete
before we can send a `closing_signed`, meaning we need to handle
the send asynchronously anyway.

This simplifies a few function interfaces and has no impact on
behavior, aside from a few message-ordering edge-cases, as seen in
the two small test changes required.

2 years agoMerge pull request #1045 from TheBlueMatt/2021-08-chanmon-ser-upgradability
Matt Corallo [Mon, 16 Aug 2021 18:30:36 +0000 (18:30 +0000)]
Merge pull request #1045 from TheBlueMatt/2021-08-chanmon-ser-upgradability

Make `ChannelMonitor` serialization slightly more upgradable

2 years agoMigrate OnchainEvent serialization to be MaybeReadable. 2021-08-chanmon-ser-upgradability
Matt Corallo [Wed, 28 Jul 2021 20:24:20 +0000 (20:24 +0000)]
Migrate OnchainEvent serialization to be MaybeReadable.

This adds a new TLV-based enum serialization macro entitled
`impl_writeable_tlv_based_enum_upgradable`. As the name implies,
the new macro allows us to ignore odd-numbered variant entries.
Because the new macro implements only `MaybeReadable` and not
`Readable`, it is not applicable in many contexts, here only being
added for the two `OnchainEvent` structs.

2 years agoImplement `VecReadWrapper` for `MaybeReadable`
Matt Corallo [Wed, 28 Jul 2021 20:18:10 +0000 (20:18 +0000)]
Implement `VecReadWrapper` for `MaybeReadable`

This makes it much simpler to deal with `MaybeReadable` types in
`Vec`s in TLVs as we can transparently deal with them as `vec`,
with the wrapper doing the Right Thing.

This requires we implement `MaybeReadable` for all `Readable` which
has some downstream implications, but nothing too bad.

2 years agoDo not serialize `Channel::last_sent_closing_fee` to disk
Matt Corallo [Mon, 19 Jul 2021 18:32:11 +0000 (18:32 +0000)]
Do not serialize `Channel::last_sent_closing_fee` to disk

We're supposed to write `Channel` to disk as if
`remove_uncommitted_htlcs_and_mark_paused` had just run, however we
were writing `last_sent_closing_fee` to disk (if it is not-None),
whereas `remove_uncommitted_htlcs_and_mark_paused` clears it.
Indeed, the BOLTs say fee "... negotiation restarts on
reconnection."

2 years agoLog shutdown including which side of the channel initiated shutdown
Matt Corallo [Tue, 6 Jul 2021 23:51:11 +0000 (23:51 +0000)]
Log shutdown including which side of the channel initiated shutdown

2 years agoImplement the closing_signed TLV suffix with allowed fee ranges
Matt Corallo [Mon, 5 Jul 2021 23:21:36 +0000 (23:21 +0000)]
Implement the closing_signed TLV suffix with allowed fee ranges

This adds the serialization and structures for the new fee range
specifiers in closing_signed as added upstream at
https://github.com/lightningnetwork/lightning-rfc/pull/847

2 years agoImprove TLV serialization macro callability very slightly
Matt Corallo [Mon, 5 Jul 2021 23:18:41 +0000 (23:18 +0000)]
Improve TLV serialization macro callability very slightly

This allows decode_tlv_stream!() to be called with either a mutable
reference to a stream or a stream itself and allows
encode_tlv_stream!() to be called with an excess , at the end of
the parameter list.

2 years agoAdd new `ChannelError` category to send `warning` messages
Matt Corallo [Mon, 26 Jul 2021 20:01:36 +0000 (20:01 +0000)]
Add new `ChannelError` category to send `warning` messages

We don't actually yet support `warning` messages as there are
issues left to resolve in the spec PR, but there's nothing to stop
us adding an internal enum variant for sending a warning message
before we actually support doing so.

2 years agoAdd #[allow(unused_mut)] on reorg_test as older rustc requires mut
Matt Corallo [Mon, 9 Aug 2021 22:03:53 +0000 (22:03 +0000)]
Add #[allow(unused_mut)] on reorg_test as older rustc requires mut

2 years agoMerge pull request #985 from TheBlueMatt/2021-06-auto-chan-fee-updates
Matt Corallo [Fri, 13 Aug 2021 23:00:33 +0000 (23:00 +0000)]
Merge pull request #985 from TheBlueMatt/2021-06-auto-chan-fee-updates

Automatically Update fees on outbound channels

2 years agoLimit inbound fee updates by dust exposure instead of our estimator 2021-06-auto-chan-fee-updates
Matt Corallo [Wed, 30 Jun 2021 03:16:01 +0000 (03:16 +0000)]
Limit inbound fee updates by dust exposure instead of our estimator

Inbound fee udpates are rather broken in lightning as they can
impact the non-fundee despite the funder paying the fee, but only
in the dust exposure it places on the fundee.

At least lnd is fairly aggressively high in their (non-anchor) fee
estimation, running the risk of force-closure. Further, because we
relied on a fee estimator we don't have full control over, we
were assuming our users' fees are particularly conservative, and
thus were at a lot of risk to force-closures.

This converts our fee limiting to use an absurd upper bound,
focusing on whether we are over-exposed to in-flight dust when we
receive an update_fee.

2 years agoLog when we change HTLC state while sending a commitment transaction
Matt Corallo [Tue, 13 Jul 2021 16:07:01 +0000 (16:07 +0000)]
Log when we change HTLC state while sending a commitment transaction

2 years agoFix handling of inbound uncommitted feerate updates
Matt Corallo [Mon, 12 Jul 2021 15:39:27 +0000 (15:39 +0000)]
Fix handling of inbound uncommitted feerate updates

If we receive an update_fee but do not receive a commitment_signed,
we should not persist the pending fee update to disk or hold on to
it after our peer disconnects.

In order to make the code the most readable, we add a state enum
which matches the relevant states from InboundHTLCState, allowing
for more simple code comparison between inbound HTLC handling and
update_fee handling.

2 years agoFix re-sending commitment updates with an outbound fee update
Matt Corallo [Wed, 30 Jun 2021 18:12:51 +0000 (18:12 +0000)]
Fix re-sending commitment updates with an outbound fee update

When we send an update_fee to our counterparty on an outbound
channel, if we need to re-send a commitment update after
reconnection, the update_fee must be present in the re-sent
commitment update messages. However, wewere always setting the
update_fee field in the commitment update to None, causing us to
generate invalid commitment signatures and get channel
force-closures.

This fixes the issue by correctly detecting when an update_fee
needs to be re-sent, doing so when required.

2 years agoAdd more logging during chanmon_consistency runs
Matt Corallo [Tue, 13 Jul 2021 02:23:41 +0000 (02:23 +0000)]
Add more logging during chanmon_consistency runs

2 years agoAdd fuzz coverage of (potential) fee update messages
Matt Corallo [Wed, 30 Jun 2021 03:09:04 +0000 (03:09 +0000)]
Add fuzz coverage of (potential) fee update messages

2 years agoAutomatically update fees on outbound channels as fees change
Matt Corallo [Mon, 28 Jun 2021 03:41:44 +0000 (03:41 +0000)]
Automatically update fees on outbound channels as fees change

Previously we'd been expecting to implement anchor outputs before
shipping 0.1, thus reworking our channel fee update process
entirely and leaving it as a future task. However, due to the
difficulty of working with on-chain anchor pools, we are now likely
to ship 0.1 without requiring anchor outputs.

In either case, there isn't a lot of reason to require that users
call an explicit "prevailing feerates have changed" function now
that we have a timer method which is called regularly. Further, we
really should be the ones deciding on the channel feerate in terms
of the users' FeeEstimator, instead of requiring users implement a
second fee-providing interface by calling an update_fee method.

Finally, there is no reason for an update_fee method to be
channel-specific, as we should be updating all (outbound) channel
fees at once.

Thus, we move the update_fee handling to the background, calling it
on the regular 1-minute timer. We also update the regular 1-minute
timer to fire on startup as well as every minute to ensure we get
fee updates even on mobile clients that are rarely, if ever, open
for more than one minute.

2 years agoSet cfg=fuzzing when building fuzz crate in CI
Matt Corallo [Mon, 5 Jul 2021 18:13:16 +0000 (18:13 +0000)]
Set cfg=fuzzing when building fuzz crate in CI

We will likely drop the fuzztarget feature soon, and should thus be
setting cfg=fuzzing explicitly anyway.

2 years agoAdd standard derives for ConfirmationTarget
Matt Corallo [Sun, 4 Jul 2021 14:51:21 +0000 (14:51 +0000)]
Add standard derives for ConfirmationTarget

2 years agoMerge pull request #1009 from ariard/2021-07-add-forward-dust-limit
Matt Corallo [Tue, 10 Aug 2021 22:11:18 +0000 (22:11 +0000)]
Merge pull request #1009 from ariard/2021-07-add-forward-dust-limit

Add new config setting `max_balance_dust_htlc_msat`

2 years agoAdd test_max_balance_dust_htlc
Antoine Riard [Wed, 28 Jul 2021 23:59:11 +0000 (19:59 -0400)]
Add test_max_balance_dust_htlc

2 years agoEnforce `max_balance_dust_htlc_msat` at HTLC reception/forward
Antoine Riard [Wed, 28 Jul 2021 23:55:11 +0000 (19:55 -0400)]
Enforce `max_balance_dust_htlc_msat` at HTLC reception/forward

At `update_add_htlc()`/`send_htlc()`, we verify that the inbound/
outbound dust or the sum of both, on either sides of the link isn't
above new config setting `max_balance_dust_htlc_msat`.

A dust HTLC is hence defined as a trimmed-to-dust one, i.e including
the fee cost to publish its claiming transaction.

2 years agoModify pending inbound/outbound getters to access dust balances
Antoine Riard [Wed, 28 Jul 2021 23:54:20 +0000 (19:54 -0400)]
Modify pending inbound/outbound getters to access dust balances

2 years agoAdd new config setting `max_balance_dust_htlc_msat`
Antoine Riard [Wed, 28 Jul 2021 23:51:02 +0000 (19:51 -0400)]
Add new config setting `max_balance_dust_htlc_msat`

Trimmed-to-dust HTLCs are at risk of being burnt as miner fees
at anytime during their lifetime due to the broadcast of either
holder commitment transaction or counterparty's one.

To hedge against this risk, we introduce a new config setting
`max_balance_dust_htlc_msat`, with the initial value of
5_000_000 msat.

2 years agoMerge pull request #1025 from TheBlueMatt/2021-07-detect-htlcs-on-local-commitment
Matt Corallo [Tue, 10 Aug 2021 15:10:45 +0000 (15:10 +0000)]
Merge pull request #1025 from TheBlueMatt/2021-07-detect-htlcs-on-local-commitment

2 years agoMerge pull request #1038 from valentinewallace/2021-08-keysend-docs
Matt Corallo [Tue, 10 Aug 2021 00:56:25 +0000 (00:56 +0000)]
Merge pull request #1038 from valentinewallace/2021-08-keysend-docs

2 years agoAdd requirement of payment secret for multi path payments
Valentine Wallace [Fri, 6 Aug 2021 22:18:36 +0000 (18:18 -0400)]
Add requirement of payment secret for multi path payments

in send_payment_internal

2 years agoMerge pull request #1019 from jkczyz/2021-07-shutdown-pubkey
Matt Corallo [Mon, 9 Aug 2021 21:41:02 +0000 (21:41 +0000)]
Merge pull request #1019 from jkczyz/2021-07-shutdown-pubkey

Fetch shutdown script based on `commit_upfront_shutdown_pubkey`

2 years agoAdd APIError::IncompatibleShutdownScript
Jeffrey Czyz [Mon, 2 Aug 2021 03:31:07 +0000 (22:31 -0500)]
Add APIError::IncompatibleShutdownScript

2 years agoImplement Display for ShutdownScript
Jeffrey Czyz [Sat, 31 Jul 2021 04:27:58 +0000 (23:27 -0500)]
Implement Display for ShutdownScript

2 years agoPass InitFeatures by reference to Channel
Jeffrey Czyz [Sun, 1 Aug 2021 21:36:07 +0000 (16:36 -0500)]
Pass InitFeatures by reference to Channel

2 years agoRemove unreachable BroadcastChannelUpdate
Jeffrey Czyz [Mon, 9 Aug 2021 20:15:12 +0000 (15:15 -0500)]
Remove unreachable BroadcastChannelUpdate

When handling shutdown messages, Channel cannot move to
ChannelState::ShutdownComplete. Remove the code in ChannelManager that
adds a MessageSendEvent::BroadcastChannelUpdate in this case since it is
unreachable.

2 years agoGenerate shutdown script at channel close
Jeffrey Czyz [Mon, 26 Jul 2021 18:04:44 +0000 (14:04 -0400)]
Generate shutdown script at channel close

When a shutdown script is omitted from open_channel or accept_channel,
it must be provided when sending shutdown. Generate the shutdown script
at channel closing time in this case rather at channel opening.

This requires producing a ChannelMonitorUpdate with the shutdown script
since it is no longer known at ChannelMonitor creation.

2 years agoAdd features to NodeCfg and use in create_network
Jeffrey Czyz [Sat, 7 Aug 2021 06:02:11 +0000 (01:02 -0500)]
Add features to NodeCfg and use in create_network

2 years agoConnect nodes in remaining tests
Jeffrey Czyz [Sat, 31 Jul 2021 14:32:27 +0000 (09:32 -0500)]
Connect nodes in remaining tests

Similar to 2745bd5ac776c48950bcb630338538d31a9615d0, this ensures that
ChannelManager knows about the features its peers.

2 years agoSupport all shutdown scripts defined in BOLT 2
Jeffrey Czyz [Mon, 26 Jul 2021 16:31:24 +0000 (12:31 -0400)]
Support all shutdown scripts defined in BOLT 2

KeysInterface::get_shutdown_pubkey is used to form P2WPKH shutdown
scripts. However, BOLT 2 allows for a wider variety of scripts. Refactor
KeysInterface to allow any supported script while still maintaining
serialization backwards compatibility with P2WPKH script pubkeys stored
simply as the PublicKey.

Add an optional TLV field to Channel and ChannelMonitor to support the
new format, but continue to serialize the legacy PublicKey format.

2 years agoUse ShutdownScript to check scripts from peers
Jeffrey Czyz [Wed, 28 Jul 2021 19:04:10 +0000 (14:04 -0500)]
Use ShutdownScript to check scripts from peers

2 years agoAdd ShutdownScript for BOLT 2 acceptable scripts
Jeffrey Czyz [Thu, 22 Jul 2021 01:12:14 +0000 (20:12 -0500)]
Add ShutdownScript for BOLT 2 acceptable scripts

BOLT 2 enumerates the script formats that may be used for a shutdown
script. KeysInterface::get_shutdown_pubkey returns a PublicKey used to
form one of the acceptable formats (P2WPKH). Add a ShutdownScript
abstraction to encapsulate all accept formats and be backwards
compatible with P2WPKH scripts serialized as the corresponding
PublicKey.

2 years agoClean up and add shutdown script functional tests
Jeffrey Czyz [Thu, 29 Jul 2021 17:41:03 +0000 (12:41 -0500)]
Clean up and add shutdown script functional tests

2 years agoMerge pull request #1035 from TheBlueMatt/2021-08-faster-pings
Matt Corallo [Mon, 9 Aug 2021 18:52:25 +0000 (18:52 +0000)]
Merge pull request #1035 from TheBlueMatt/2021-08-faster-pings

Suggest faster ping in `PeerManager::timer_tick_occurred` docs

2 years agoHandle being asleep for more than double our ping time gracefully 2021-08-faster-pings
Matt Corallo [Sat, 7 Aug 2021 20:45:01 +0000 (20:45 +0000)]
Handle being asleep for more than double our ping time gracefully

If we've been asleep for double our ping time, for whatever reason,
disconnect all open sockets.

2 years agoUpdate lightning-background-processor to ping every five seconds
Matt Corallo [Thu, 5 Aug 2021 17:04:18 +0000 (17:04 +0000)]
Update lightning-background-processor to ping every five seconds

This updates lightning-background-processor calls to
PeerManager::timer_tick_occurred to match the new suggested rate in
the documentation.