]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
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 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.

3 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

3 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

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

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

3 years agoSuggest faster ping in `PeerManager::timer_tick_occurred` docs
Matt Corallo [Wed, 4 Aug 2021 16:21:36 +0000 (16:21 +0000)]
Suggest faster ping in `PeerManager::timer_tick_occurred` docs

This clarifies the docs for `PeerManager::timer_tick_occurred` to
note that the call rate is entirely up to the user, and also
suggests a faster ping rate of "once every five to ten seconds"
instead of "every 30 seconds". There isn't a lot of reason to want
to ping less often, and faster ping means we detect disconnects
sooner, which is important.

3 years agoCorrectly detect missing HTLCs when a local commitment tx was broadcast 2021-07-detect-htlcs-on-local-commitment
Matt Corallo [Sat, 31 Jul 2021 03:34:16 +0000 (03:34 +0000)]
Correctly detect missing HTLCs when a local commitment tx was broadcast

If we forward an HTLC to our counterparty, but we force-closed the
channel before our counterparty provides us an updated commitment
transaction, we'll end up with a commitment transaction that does
not contain the HTLC which we attempted to forward. In this case,
we need to wait `ANTI_REORG_DELAY` blocks and then fail back the
HTLC as there is no way for us to learn the preimage and the
confirmed commitment transaction paid us the value of the HTLC.

However, check_spend_holder_transaction did not do this - it
instead only looked for dust HTLCs in the confirmed commitment
transaction, paying no attention to what other HTLCs may exist that
are missed.

This will eventually lead to channel force-closure as the channel
on which we received the inbound HTLC to forward will be closed in
time for the initial sender to claim the HTLC on-chain.

3 years agoDRY HTLC failure code in check_spend_counterparty_transaction
Matt Corallo [Sat, 31 Jul 2021 03:31:10 +0000 (03:31 +0000)]
DRY HTLC failure code in check_spend_counterparty_transaction

This extracts the HTLC-not-in-broadcasted-commitment-transaction
code from check_spend_counterparty_transaction and moves it to a
global macro, DRYing up the two very similar codepaths (fixing
some minor logging inconsistencies) in the process.

This macro will be used for local commitment transaction HTLC
failure as well in the next commit.

This commit has no functional change outside of logging.

3 years agoUpdate keysend docs
Valentine Wallace [Fri, 6 Aug 2021 22:17:58 +0000 (18:17 -0400)]
Update keysend docs

3 years agoMerge pull request #1029 from TheBlueMatt/2021-07-log-channel-close
Matt Corallo [Thu, 5 Aug 2021 21:05:43 +0000 (21:05 +0000)]
Merge pull request #1029 from TheBlueMatt/2021-07-log-channel-close

Log when a channel is closed on startup due to stale ChannelManager

3 years agoMake BackgroundProcessor `#[must_use]` to avoid dropping immediately 2021-07-log-channel-close
Matt Corallo [Sun, 1 Aug 2021 02:42:42 +0000 (02:42 +0000)]
Make BackgroundProcessor `#[must_use]` to avoid dropping immediately

It is easy for users to have a bug where they drop a
`BackgroundProcessor` immediately, causing it to start and then
immediately stop. Instead, add a `#[must_use]` tag to provide a
compiler warning for such instances.

3 years agoLog when a channel is closed on startup due to stale ChannelManager
Matt Corallo [Sun, 1 Aug 2021 02:13:36 +0000 (02:13 +0000)]
Log when a channel is closed on startup due to stale ChannelManager

This is one of the riskiest parts of our API from the perspective
of accidental force-closes - if users delay persisting the
ChannelManager much at all after a ChannelMonitor we may hit a
force-close after restart.

The fact that we don't log at all when this happens is criminal.

3 years agoAdd additional TLV serialization type of (default_value, N)
Matt Corallo [Fri, 16 Jul 2021 18:10:37 +0000 (18:10 +0000)]
Add additional TLV serialization type of (default_value, N)

This allows TLV serialization macros to read non-Option-wrapped
types but allow them to be missing, filling them in with the
provided default value as needed.

3 years agoMerge pull request #1004 from TheBlueMatt/2021-07-forward-event
Matt Corallo [Wed, 4 Aug 2021 22:58:14 +0000 (22:58 +0000)]
Merge pull request #1004 from TheBlueMatt/2021-07-forward-event

Add a `PaymentForwarded` Event

3 years agoChange return value of `claim_funds` to ignore duplicate claims 2021-07-forward-event
Matt Corallo [Tue, 3 Aug 2021 16:49:31 +0000 (16:49 +0000)]
Change return value of `claim_funds` to ignore duplicate claims

While we should never reach `ClaimFundsFromHop::DuplicateClaim` in
most cases, if we do, it likely indicates the HTLC was timed out
some time ago and is no longer available to be claimed. Thus, it
does not make sense to imply that we `claimed_any_htlcs`.

3 years agoGenerate a PaymentForwarded event when a forwarded HTLC is claimed
Matt Corallo [Fri, 16 Jul 2021 02:16:50 +0000 (02:16 +0000)]
Generate a PaymentForwarded event when a forwarded HTLC is claimed

It is useful for accounting and informational reasons for users to
be informed when a payment has been successfully forwarded. Thus,
when an HTLC which represents a forwarded leg is claimed, we
generate a new `PaymentForwarded` event.

This requires some additional plumbing to return HTLC values from
`OnchainEvent`s. Further, when we have to go on-chain to claim the
inbound side of the payment, we do not inform the user of the fee
reward, as we cannot calculate it until we see what is confirmed
on-chain.

Substantial code structure rewrites by:
Valentine Wallace <vwallace@protonmail.com>

3 years agoMerge pull request #1022 from TheBlueMatt/2021-07-to-remote-reorg
Matt Corallo [Wed, 4 Aug 2021 03:08:53 +0000 (03:08 +0000)]
Merge pull request #1022 from TheBlueMatt/2021-07-to-remote-reorg

Fix to_remote SpendableOutputs generation in rare reorg cases

3 years agoFix to_remote SpendableOutputs generation in rare reorg cases 2021-07-to-remote-reorg
Matt Corallo [Thu, 29 Jul 2021 19:49:09 +0000 (19:49 +0000)]
Fix to_remote SpendableOutputs generation in rare reorg cases

If we first see a local commitment transaction, and then a reorg
causes the confirmed channel close transaction to instead be a
remote commitment transaction, we would fail a spurious `if else`
check, resulting in us not generating the correct `SpendableOutput`
event for the to_remote output now confirmed on chain.

This resolves the incorrect logic and adds a regression test.

3 years agoMerge pull request #1028 from lightning-signer/2021-08-no-std
Matt Corallo [Tue, 3 Aug 2021 17:06:59 +0000 (17:06 +0000)]
Merge pull request #1028 from lightning-signer/2021-08-no-std

Actual no_std support

3 years agoRename no_std feature to no-std
Devrandom [Tue, 3 Aug 2021 07:38:44 +0000 (09:38 +0200)]
Rename no_std feature to no-std

matches rust-bitcoin

3 years agoMerge pull request #1033 from TheBlueMatt/2021-07-fix-beta
Matt Corallo [Tue, 3 Aug 2021 14:41:35 +0000 (14:41 +0000)]
Merge pull request #1033 from TheBlueMatt/2021-07-fix-beta

Fix lightning-persister tests for upcoming rustc changes

3 years agoActual no_std support
Devrandom [Sun, 1 Aug 2021 16:22:06 +0000 (18:22 +0200)]
Actual no_std support

3 years agoCheck IO errors in test using `raw_os_error()` instead of `kind()` 2021-07-fix-beta
Matt Corallo [Mon, 2 Aug 2021 15:04:40 +0000 (15:04 +0000)]
Check IO errors in test using `raw_os_error()` instead of `kind()`

std::io::ErrorKind is a `#[non_exhaustive]` enum as more specific
error types are to be added in the future. It was unclear in the
docs until very recently, however, that this is to be done by
re-defining `ErrorKind::Other` errors to new enum variants. Thus,
our tests which check explicitly for `ErrorKind::Other` as a
result of trying to access a directory as a file were incorrect.
Sadly, these generated no meaningful feedback from rustc at all,
except that they're suddenly failing in rustc beta!

After some back-and-forth, it seems rustc is moving forward
breaking existing code in future versions, so we move to the
"correct" check here, which is to check the raw IO error.

See rust-lang/rust#86442 and rust-lang/rust#85746 for more info.

3 years agoMerge pull request #1032 from jkczyz/2021-08-clippy
Matt Corallo [Mon, 2 Aug 2021 16:28:14 +0000 (16:28 +0000)]
Merge pull request #1032 from jkczyz/2021-08-clippy

3 years agoFail linter on #[warn(clippy::try_err)]
Jeffrey Czyz [Mon, 2 Aug 2021 15:30:01 +0000 (10:30 -0500)]
Fail linter on #[warn(clippy::try_err)]

Some heavily used macros are using ? directly on an Err. Using a return
is easier to read and removes hundreds of linter warnings.

https://rust-lang.github.io/rust-clippy/master/index.html#try_err

3 years agoFix #[warn(clippy::try_err)] in ser_macros.rs
Jeffrey Czyz [Mon, 2 Aug 2021 14:29:49 +0000 (09:29 -0500)]
Fix #[warn(clippy::try_err)] in ser_macros.rs

3 years agoAdd CI runs on rustc beta on Windows and MacOS
Matt Corallo [Mon, 2 Aug 2021 14:52:02 +0000 (14:52 +0000)]
Add CI runs on rustc beta on Windows and MacOS

This should catch any platform-specific behavior changes in rustc
before they land in stable.

3 years agoMerge pull request #1012 from TheBlueMatt/2021-07-bump-deps
Matt Corallo [Sat, 31 Jul 2021 20:42:59 +0000 (20:42 +0000)]
Merge pull request #1012 from TheBlueMatt/2021-07-bump-deps

Bump dependencies to bitcoin 0.27 and bech32 0.8

3 years agoAdd a `#[macro_use]` on the `alloc` import for `format!()` 2021-07-bump-deps
Matt Corallo [Thu, 22 Jul 2021 15:18:22 +0000 (15:18 +0000)]
Add a `#[macro_use]` on the `alloc` import for `format!()`

3 years agoFix no_std warnings due to unused includes
Matt Corallo [Thu, 22 Jul 2021 15:13:37 +0000 (15:13 +0000)]
Fix no_std warnings due to unused includes

3 years agoDrop MSRV for no_std to 1.47 as that's what Ubuntu LTS ships with
Matt Corallo [Thu, 22 Jul 2021 15:01:03 +0000 (15:01 +0000)]
Drop MSRV for no_std to 1.47 as that's what Ubuntu LTS ships with

...but disable it for now given core2 is broken (it claims an MSRV
of 1.47 but does not build).

3 years agoBump dependencies to bitcoin 0.27 and bech32 0.8
Matt Corallo [Thu, 22 Jul 2021 14:31:37 +0000 (14:31 +0000)]
Bump dependencies to bitcoin 0.27 and bech32 0.8

3 years agoMerge pull request #1024 from TheBlueMatt/2021-07-always-connect-in-tests
Matt Corallo [Fri, 30 Jul 2021 20:53:30 +0000 (20:53 +0000)]
Merge pull request #1024 from TheBlueMatt/2021-07-always-connect-in-tests

Connect peers on startup in tests

3 years agoConnect peers on startup in tests 2021-07-always-connect-in-tests
Matt Corallo [Fri, 30 Jul 2021 18:21:12 +0000 (18:21 +0000)]
Connect peers on startup in tests

This avoids `ChannelManager` ever being confused by the fact that
it received a message from a peer which it didn't think it was
connected to.

3 years agoMerge pull request #1021 from TheBlueMatt/2021-07-broken-beta
Matt Corallo [Thu, 29 Jul 2021 18:06:05 +0000 (18:06 +0000)]
Merge pull request #1021 from TheBlueMatt/2021-07-broken-beta

Disable fast-fail to let CI actually run even though beta is broken

3 years agoMerge pull request #1007 from jkczyz/2021-07-stop-drop-shutem-down
Matt Corallo [Thu, 29 Jul 2021 17:49:05 +0000 (17:49 +0000)]
Merge pull request #1007 from jkczyz/2021-07-stop-drop-shutem-down

Stop BackgroundProcessor's thread on drop

3 years agoDisable fast-fail to let CI actually run even though beta is broken 2021-07-broken-beta
Matt Corallo [Thu, 29 Jul 2021 17:40:14 +0000 (17:40 +0000)]
Disable fast-fail to let CI actually run even though beta is broken