Commit graph

380 commits

Author SHA1 Message Date
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
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
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
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
Jeffrey Czyz
1d3861e5f6
Add APIError::IncompatibleShutdownScript 2021-08-09 15:56:29 -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
Matt Corallo
69ee486084
Merge pull request #1004 from TheBlueMatt/2021-07-forward-event
Add a `PaymentForwarded` Event
2021-08-04 22:58:14 +00:00
Matt Corallo
2024c5e104 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>
2021-08-04 21:48:21 +00:00
Matt Corallo
3f229052ea Bump dependencies to bitcoin 0.27 and bech32 0.8 2021-07-31 18:29:07 +00:00
Matt Corallo
306e9a5acf Fix channel reserve calculation on the sending side
As the variable name implies holder_selected_chan_reserve_msat is
intended to be in millisatoshis, but is instead calculated in
satoshis.

We fix that error here and update the relevant tests to more
accurately calculate the expected reserve value and test both
success and failure cases.

Bug discovered by chanmon_consistency fuzz target.
2021-07-13 17:13:58 +00:00
Matt Corallo
99953ed8ff Update full_stack_target demo input to match new, fewer, fee gets 2021-07-09 00:50:30 +00:00
Matt Corallo
c620944f16 Make the base fee configurable in ChannelConfig
Currently the base fee we apply is always the expected cost to
claim an HTLC on-chain in case of closure. This results in
significantly higher than market rate fees [1], and doesn't really
match the actual forwarding trust model anyway - as long as
channel counterparties are honest, our HTLCs shouldn't end up
on-chain no matter what the HTLC sender/recipient do.

While some users may wish to use a feerate that implies they will
not lose funds even if they go to chain (assuming no flood-and-loot
style attacks), they should do so by calculating fees themselves;
since they're already charging well above market-rate,
over-estimating some won't have a large impact.

Worse, we current re-calculate fees at forward-time, not based on
the fee we set in the channel_update. This means that the fees
others expect to pay us (and which they calculate their route based
on), is not what we actually want to charge, and that any attempt
to forward through us is inherently race-y.

This commit adds a configuration knob to set the base fee
explicitly, defaulting to 1 sat, which appears to be market-rate
today.

[1] Note that due to an msat-vs-sat bug we currently actually
    charge 1000x *less* than the calculated cost.
2021-07-09 00:50:30 +00:00
Matt Corallo
12253e5331
Merge pull request #988 from TheBlueMatt/2021-07-chan-details-usability
Improve ChannelDetails readability significantly.
2021-07-08 17:25:53 +00:00
Matt Corallo
2b08a47e88 Improve ChannelDetails readability significantly.
After the merge of #984, Jeff pointed out that `ChannelDetails` has
become a bit of a "bag of variables", and that a few of the variable
names in #984 were more confusing than necessary in context.

This addresses several issues by:
 * Splitting counterparty parameters into a separate
   `ChannelCounterpartyParameters` struct,
 * using the name `unspendable_punishment_reserve` for both outbound
   and inbound channel reserves, differentiating them based on their
   position in the counterparty parameters struct or not,
 * Using the name `force_close_spend_delay` instead of
   `spend_csv_on_our_commitment_funds` to better communicate what
   is occurring.
2021-07-08 16:46:57 +00:00
Matt Corallo
99938455f7
Merge pull request #949 from TheBlueMatt/2021-06-send-priv-update
Send channel_update messages to direct peers on private channels
2021-07-07 20:17:10 +00:00
Matt Corallo
e3968e0993 Send channel_update messages to direct peers on private channels
If we are a public node and have a private channel, our
counterparty needs to know the fees which we will charge to forward
payments to them. Without sending them a channel_update, they have
no way to learn that information, resulting in the channel being
effectively useless for outbound-from-us payments.

This commit fixes our lack of channel_update messages to private
channel counterparties, ensuring we always send them a
channel_update after the channel funding is confirmed.
2021-07-07 19:45:33 +00:00
Matt Corallo
da298e498f Expose the current best chain tip from ChannelManager + Monitors
Fixes #979
2021-07-06 00:18:27 +00:00
Matt Corallo
0882655680 Expand the fields exposed to users in ChannelDetails
This adds four new fields in `ChannelDetails`:
1. holder_selected_ and counterparty_selected_channel_reserve_delay
   are useful to determine what amount of the channel is
   unavailable for payments.
2. confirmations_required is useful when awaiting funding
   confirmation to determine how long you will need to wait.
3. to_self_delay is useful to determine how long it will take to
   receive funds after a force-close.

Fixes #983.
2021-07-06 00:18:27 +00:00
Matt Corallo
95f9523097 Drop rust-bitcoin crate patches in fuzz now that they're merged
These patches have been merged upstream and are in releases now so
we don't need to patch them locally.
2021-06-23 01:35:26 +00:00
Matt Corallo
d61d698bb8 Don't print file paths in fuzz logger as they can be very long 2021-06-23 01:35:23 +00:00
Jeffrey Czyz
200f3d155c
Accept multi-hop route hints in get_route
Lightning invoices allow for zero or more multi-hop route hints. Update
get_route's interface to accept such hints, although only the last hop
from each is used for the time being.

Moves RouteHint from lightning-invoice crate to lightning crate. Adds a
PrivateRoute wrapper around RouteHint for use in lightning-invoice.
2021-06-11 08:44:32 -07:00
Matt Corallo
c05347f48a
Merge pull request #892 from TheBlueMatt/2021-04-fix-htlc-ser
Correct Channel outbound HTLC serialization and expand fuzzing coverage
2021-05-31 23:52:22 +00:00
Matt Corallo
e003c43183 [fuzz] Expand chanmon_consistency to do single message delivery
While trying to debug the issue ultimately tracked down to a
`PeerHandler` locking bug in #891, the ability to deliver only
individual messages at a time in chanmon_consistency looked
important. Specifically, it initially appeared there may be a race
when an update_add_htlc was delivered, then a node sent a payment,
and only after that, the corresponding commitment-signed was
delivered.

This commit adds such an ability, greatly expanding the potential
for chanmon_consistency to identify channel state machine bugs.
2021-05-31 18:20:22 +00:00
Matt Corallo
b780cbdbfc [fuzz] Fix hang due to double-lock in full_stack_target 2021-05-31 18:20:22 +00:00
Matt Corallo
a53764a58b [fuzz] Do not fail in FST if a channel is closed before we fund it 2021-05-31 18:20:22 +00:00
Matt Corallo
29a780e9e0 Delay broadcast of PackageTemplate packages until their locktime
This stores transaction templates temporarily until their locktime
is reached, avoiding broadcasting (or RBF bumping) transactions
prior to their locktime. For those broadcasting transactions
(potentially indirectly) via Bitcoin Core RPC, this ensures no
automated rebroadcast of transactions on the client side is
required to get transactions confirmed.
2021-05-28 23:56:44 +00:00
Jeffrey Czyz
7c465d69dc
Refactor EventsProvider to take an EventHandler 2021-05-24 14:16:16 -07:00
Matt Corallo
34fcd99f51 Add trace to ci-fuzz.sh to make debugging CI issues easier 2021-05-21 15:10:45 +00:00
Matt Corallo
da54848ba4 Read monitors from our KeysInterface in chanmon_consistency_fuzz
If the fuzz target is failing due to a channel force-close, the
immediately-visible error is that we're signing a stale state. This
is because the ChannelMonitorUpdateStep::ChannelForceClosed event
results in a signature in the test clone which was deserialized
using a OnlyReadsKeysInterface. Instead, we need to deserialize
using the full KeysInterface instance.
2021-05-21 15:10:45 +00:00
Matt Corallo
8acdbaf2a4 [fuzz] Handle monitor updates during get_and_clear_pending_msg_events
Because we may now generate a monitor update during
get_and_clear_pending_msg_events calls, we need to ensure we
re-serialize the relevant ChannelManager before attempting to
reload it, if such a monitor update occurred.
2021-05-21 15:10:45 +00:00
Matt Corallo
1fa2da391c [fuzz] Allow SendAnnouncementSigs events in chanmon_consistency
Because of the merge between peer reconnection and channel monitor
updating channel restoration code, we now sometimes generate
(somewhat spurious) announcement signatures when restoring channel
monitor updating. This should not result in a fuzzing failure.
2021-05-20 21:18:35 +00:00
Matt Corallo
d90aac8d95 [fuzz] Be more strict about msg events in chanmon_consistency
This fails chanmon_consistency on IgnoreError error events and on
messages left over to be sent to a just-disconnected peer, which
should have been drained.

These should never appear, so consider them a fuzzer fail case.
2021-05-20 21:18:35 +00:00
Matt Corallo
acc9ff6274 [fuzz] Print the output of all failed test cases, not one test.
Our fuzz tests previously only printed the log output of the first
fuzz test case to fail. This commit changes that (with lots of
auto-generated updates) to ensure we print all log outputs.
2021-05-20 21:18:35 +00:00
Matt Corallo
b6de28182f
Merge pull request #918 from TheBlueMatt/2021-05-dup-claims
Make payments not duplicatively fail/succeed on reload/reconnect
2021-05-20 17:10:52 +00:00
Matt Corallo
864375e5f2 [fuzz] Make get_secure_random_bytes in chanmon_consistency unique 2021-05-20 16:38:18 +00:00
Valentine Wallace
438e70e083
Add new DecodeError for messages that include zlib-compressed values
No need to disconnect peers if this error is encountered. It just means
we can't use some of their gossip messages.
2021-05-20 11:25:39 -04:00
Valentine Wallace
4503ef3523
Correct default expiry.
We previously stated in the codebase that the default invoice expiry
stated in the spec is 2 hours. It's actually 1 hour.
2021-05-14 16:51:46 -04:00
Matt Corallo
7297e13871
Merge pull request #912 from TheBlueMatt/2021-05-more-chan-info
Add flags for if a channel is pub and funding txo in ChannelDetails
2021-05-07 15:19:44 +00:00
Matt Corallo
62f466a0a2 Rename ChannelDetails::is_live to is_usable
This matches is_usable_channels and slightly better captures the
meaning.
2021-05-06 20:49:20 +00:00
Matt Corallo
6a79eece21 Indiciate if a channel is outbound/confirmed in ChannelDetails 2021-05-06 20:49:20 +00:00
Matt Corallo
2d6f060c06 Add flags for if a channel is pub and funding txo in ChannelDetails 2021-05-06 20:49:20 +00:00
Matt Corallo
e84f5edbc5 Increase the CLTV delay required on payments and forwards
This increases the CLTV_CLAIM_BUFFER constant to 18, much better
capturing how long it takes to go on chain to claim payments.
This is also more in line with other clients, and the spec, which
sets the default CLTV delay in invoices to 18.

As a side effect, we have to increase MIN_CLTV_EXPIRY_DELTA as
otherwise as are subject to an attack where someone can hold an
HTLC being forwarded long enough that we *also* close the channel
on which we received the HTLC.
2021-05-05 20:09:11 +00:00
Matt Corallo
58e4ce251e
Merge pull request #845 from ariard/2021-03-hardcode-dust
Switch to a max counterparty's `dust_limit_satoshis` constant
2021-05-04 01:44:18 +00:00
Matt Corallo
b307c1f2ad Make third HTLC non-dust again in the full_stack_target demo seed 2021-05-03 19:14:50 -04:00
Antoine Riard
16619ff590 Replace config max counterpary dust_limit_satoshis by a constant.
Current Bitcoin Core's policy will reject a p2wsh as a dust if it's
under 330 satoshis. A typical p2wsh output is 43 bytes big to which
Core's `GetDustThreshold()` sums up a minimal spend of 67 bytes (even
if a p2wsh witnessScript might be smaller). `dustRelayFee` is set
to 3000 sat/kb, thus 110 * 3000 / 1000 = 330. As all time-sensitive
outputs are p2wsh, a value of 330 sat is the lower bound desired
to ensure good propagation of transactions. We give a bit margin to
our counterparty and pick up 660 satoshis as an accepted
`dust_limit_satoshis` upper bound.

As this reasoning is tricky and error-prone we hardcode it instead of
letting the user picking up a non-sense value.

Further, this lower bound of 330 sats is also hardcoded as another constant
(MIN_DUST_LIMIT_SATOSHIS) instead of being dynamically computed on
feerate (derive_holder_dust_limit_satoshis`). Reducing risks of
non-propagating transactions in casee of failing fee festimation.
2021-05-03 15:37:38 -04:00
Valentine Wallace
feb882f6a4
Move invoice signing behind KeysInterface 2021-04-29 18:39:47 -04:00
Valentine Wallace
f24bbd63cc
Move PaymentPreimage+PaymentHash+PaymentSecret to top-level ln module 2021-04-29 18:39:47 -04:00
Devrandom
ec35fe62a1 Remove Send and Sync from core crate 2021-04-29 21:07:28 +02:00