]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
3 years agoFail with PERM|8 (permanent_channel_failure)
Jeffrey Czyz [Wed, 25 Aug 2021 01:24:23 +0000 (20:24 -0500)]
Fail with PERM|8 (permanent_channel_failure)

This affects the htlc_fail_async_shutdown test.

3 years agoRemove test_invalid_channel_announcement
Jeffrey Czyz [Wed, 25 Aug 2021 00:41:35 +0000 (19:41 -0500)]
Remove test_invalid_channel_announcement

It doesn't seem to be testing anything useful that isn't covered
elsewhere.

3 years agoAdd a read-only view of NetworkGraph
Jeffrey Czyz [Mon, 16 Aug 2021 23:40:19 +0000 (18:40 -0500)]
Add a read-only view of NetworkGraph

Hide the internal locking of NetworkGraph by providing a read-only
view. This way the locking order is handled internally.

3 years agoRemove RwLock from around NetworkGraph
Jeffrey Czyz [Tue, 10 Aug 2021 14:47:27 +0000 (09:47 -0500)]
Remove RwLock from around NetworkGraph

Now that NetworkGraph uses interior mutability, the RwLock used around
it in NetGraphMsgHandler is no longer needed. This allows for shared
ownership without a lock.

3 years agoIndividually lock NetworkGraph fields
Jeffrey Czyz [Tue, 10 Aug 2021 03:24:41 +0000 (22:24 -0500)]
Individually lock NetworkGraph fields

In preparation for giving NetworkGraph shared ownership, wrap individual
fields in RwLock. This allows removing the outer RwLock used in
NetGraphMsgHandler.

3 years agoPass Event by reference to EventHandler
Jeffrey Czyz [Tue, 17 Aug 2021 16:12:18 +0000 (11:12 -0500)]
Pass Event by reference to EventHandler

Passing an Event by reference rather and by move gives more flexibility
for composing event handlers without needing to clone events.

3 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

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

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

3 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

3 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.

3 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.

3 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

3 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

3 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.

3 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

3 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

3 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.

3 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.

3 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

3 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.

3 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.

3 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.

3 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

3 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.

3 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

3 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

3 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.

3 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

3 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

3 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

3 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

3 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

3 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

3 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

3 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

3 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.

3 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

3 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

3 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

3 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

3 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.

3 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

3 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

3 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

3 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)
```

3 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

3 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`.

3 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.

3 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.

3 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

3 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

3 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

3 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

3 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

3 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.

3 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

3 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

3 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

3 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`

3 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.

3 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.

3 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

3 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.

3 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.

3 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."

3 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

3 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

3 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.

3 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.

3 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

3 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

3 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.

3 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

3 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.

3 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.

3 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

3 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

3 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.

3 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.

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

3 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`

3 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

3 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.

3 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

3 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.

3 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

3 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

3 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

3 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`

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

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

3 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

3 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.

3 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.

3 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

3 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.

3 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.

3 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

3 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.