Commit graph

2884 commits

Author SHA1 Message Date
Matt Corallo
547dfb5f5c Update CHANGELOG for 0.0.100 2021-08-17 18:55:07 +00:00
Matt Corallo
6f16453275
Merge pull request #1011 from TheBlueMatt/2021-07-new-closing-fee
Clean up existing and add range-based closing_signed negotiation
2021-08-17 17:53:21 +00:00
Matt Corallo
82e7df1c0b 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.
2021-08-17 02:16:01 +00:00
Matt Corallo
0b481e91d5 Slightly clarify the closing_signed error msg on fee mismatch 2021-08-17 02:16:01 +00:00
Matt Corallo
dcb0832b76 Add a test for shutdown negotiaion funder restart and timeout 2021-08-17 02:16:01 +00:00
Matt Corallo
d63b024eff Force-close if finish closing_signed negotiation takes a full minute 2021-08-17 02:16:01 +00:00
Matt Corallo
5712de2da0 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`
2021-08-17 02:16:01 +00:00
Matt Corallo
177810b152 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.
2021-08-17 02:16:01 +00:00
Matt Corallo
67ddd46aed 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.
2021-08-17 02:16:01 +00:00
Matt Corallo
64159b385f
Merge pull request #1045 from TheBlueMatt/2021-08-chanmon-ser-upgradability
Make `ChannelMonitor` serialization slightly more upgradable
2021-08-16 18:30:36 +00:00
Matt Corallo
ee43975bf8 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.
2021-08-16 17:35:35 +00:00
Matt Corallo
45490d537e 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.
2021-08-16 17:35:35 +00:00
Matt Corallo
b1aa950f4f 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."
2021-08-13 23:07:53 +00:00
Matt Corallo
267053ff74 Log shutdown including which side of the channel initiated shutdown 2021-08-13 23:07:53 +00:00
Matt Corallo
6dc9076e66 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
2021-08-13 23:02:23 +00:00
Matt Corallo
769eea8a8d 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.
2021-08-13 23:02:23 +00:00
Matt Corallo
bd14069f04 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.
2021-08-13 23:02:23 +00:00
Matt Corallo
be9ffb4819 Add #[allow(unused_mut)] on reorg_test as older rustc requires mut 2021-08-13 23:02:23 +00:00
Matt Corallo
a369f9e64e
Merge pull request #985 from TheBlueMatt/2021-06-auto-chan-fee-updates
Automatically Update fees on outbound channels
2021-08-13 23:00:33 +00:00
Matt Corallo
d3af49e9f0 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.
2021-08-13 21:54:50 +00:00
Matt Corallo
01e8ff5ed8 Log when we change HTLC state while sending a commitment transaction 2021-08-13 21:54:50 +00:00
Matt Corallo
b3d0a8dd4e 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.
2021-08-13 21:54:50 +00:00
Matt Corallo
9d49c5c1a1 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.
2021-08-13 21:54:50 +00:00
Matt Corallo
b09a60b7b5 Add more logging during chanmon_consistency runs 2021-08-13 21:54:50 +00:00
Matt Corallo
f8caa325e5 Add fuzz coverage of (potential) fee update messages 2021-08-13 21:54:50 +00:00
Matt Corallo
03439ec99f 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.
2021-08-13 21:54:50 +00:00
Matt Corallo
692b0c78da 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.
2021-08-10 22:26:31 +00:00
Matt Corallo
29b43ba165 Add standard derives for ConfirmationTarget 2021-08-10 22:26:13 +00:00
Matt Corallo
9d8d24f690
Merge pull request #1009 from ariard/2021-07-add-forward-dust-limit
Add new config setting `max_balance_dust_htlc_msat`
2021-08-10 22:11:18 +00:00
Antoine Riard
730f6f334e Add test_max_balance_dust_htlc 2021-08-10 17:30:18 -04:00
Antoine Riard
1cf2b53508 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.
2021-08-10 17:30:15 -04:00
Antoine Riard
29e755bf42 Modify pending inbound/outbound getters to access dust balances 2021-08-10 13:50:24 -04:00
Antoine Riard
53b68236a4 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.
2021-08-10 13:43:32 -04:00
Matt Corallo
d4b6f58ba6
Merge pull request #1025 from TheBlueMatt/2021-07-detect-htlcs-on-local-commitment 2021-08-10 15:10:45 +00:00
Matt Corallo
6a94ff9dae
Merge pull request #1038 from valentinewallace/2021-08-keysend-docs 2021-08-10 00:56:25 +00:00
Valentine Wallace
552a244191
Add requirement of payment secret for multi path payments
in send_payment_internal
2021-08-09 20:09:32 -04:00
Matt Corallo
767f12030b
Merge pull request #1019 from jkczyz/2021-07-shutdown-pubkey
Fetch shutdown script based on `commit_upfront_shutdown_pubkey`
2021-08-09 21:41:02 +00:00
Jeffrey Czyz
1d3861e5f6
Add APIError::IncompatibleShutdownScript 2021-08-09 15:56:29 -05:00
Jeffrey Czyz
4a44bfa3a4
Implement Display for ShutdownScript 2021-08-09 15:56:29 -05:00
Jeffrey Czyz
e1989ada3c
Pass InitFeatures by reference to Channel 2021-08-09 15:56:28 -05:00
Jeffrey Czyz
f1c07b5573
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.
2021-08-09 15:56:10 -05:00
Jeffrey Czyz
ecb0b84241
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.
2021-08-09 15:55:28 -05:00
Jeffrey Czyz
1c449a39f4
Add features to NodeCfg and use in create_network 2021-08-09 15:55:27 -05:00
Jeffrey Czyz
89fa27432a
Connect nodes in remaining tests
Similar to 2745bd5ac7, this ensures that
ChannelManager knows about the features its peers.
2021-08-09 15:55:26 -05:00
Jeffrey Czyz
ccd11fc35a
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.
2021-08-09 15:55:26 -05:00
Jeffrey Czyz
1ab2c7c668
Use ShutdownScript to check scripts from peers 2021-08-09 15:55:26 -05:00
Jeffrey Czyz
ecc70757f9
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.
2021-08-09 15:55:25 -05:00
Jeffrey Czyz
2833786084
Clean up and add shutdown script functional tests 2021-08-09 15:55:25 -05:00
Matt Corallo
03537cc346
Merge pull request #1035 from TheBlueMatt/2021-08-faster-pings
Suggest faster ping in `PeerManager::timer_tick_occurred` docs
2021-08-09 18:52:25 +00:00
Matt Corallo
0f1a3b1698 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.
2021-08-09 18:11:19 +00:00