Commit graph

592 commits

Author SHA1 Message Date
Valentine Wallace
bf16dfd153
Rename PaymentFailed -> PaymentPathFailed
Since we don't want to imply to users that a payment has
completely failed when it really has just partially
failed
2021-09-21 17:39:40 -04:00
Matt Corallo
801d6e5256
Merge pull request #1068 from TheBlueMatt/2021-09-ser-cleanup
Simplify Message Serialization and Parse TLV Suffix
2021-09-18 01:42:29 +00:00
Matt Corallo
7f9eef553c [fuzz] Swap mode on most messages to account for TLV suffix 2021-09-18 01:01:41 +00:00
Matt Corallo
07b674ecb1 Drop writer size hinting/message vec preallocation
In order to avoid significant malloc traffic, messages previously
explicitly stated their serialized length allowing for Vec
preallocation during the message serialization pipeline. This added
some amount of complexity in the serialization code, but did avoid
some realloc() calls.

Instead, here, we drop all the complexity in favor of a fixed 2KiB
buffer for all message serialization. This should not only be
simpler with a similar reduction in realloc() traffic, but also
may reduce heap fragmentation by allocating identically-sized
buffers more often.
2021-09-18 01:01:41 +00:00
Matt Corallo
8fad498900 Increase our default/minimum dust limit to 354 sat/vbytes
330 sat/vbyte, the current value, is not sufficient to ensure a
future segwit script longer than 32 bytes meets the dust limit if
used for a shutdown script. Thus, we can either check the value
on shutdown or we can simply require segwit outputs and require a
dust value of no less than 354 sat/vbyte.

We swap the minimum dust value to 354 sat/vbyte here, requiring
segwit scripts in a future commit.

See https://github.com/lightningnetwork/lightning-rfc/issues/905
2021-09-17 20:32:59 +00:00
Valentine Wallace
3af0c8e146
Update fuzz README with latest instructions 2021-09-15 15:37:27 -04:00
Jeffrey Czyz
ba2c00b3f8
EventHandler for applying NetworkUpdate
PaymentFailed events contain an optional NetworkUpdate describing
changes to the NetworkGraph as conveyed by a node along a failed payment
path according to BOLT 4. An EventHandler should apply the update to the
graph so that future routing decisions can account for it.

Implement EventHandler for NetGraphMsgHandler to update NetworkGraph.
Previously, NetGraphMsgHandler::handle_htlc_fail_channel_update
implemented this behavior.
2021-09-15 11:50:31 -05:00
Jeffrey Czyz
eff9a47075
Refactor PaymentFailureNetworkUpdate event
MessageSendEvent::PaymentFailureNetworkUpdate served as a hack to pass
an HTLCFailChannelUpdate from ChannelManager to NetGraphMsgHandler via
PeerManager. Instead, remove the event entirely and move the contained
data (renamed NetworkUpdate) to Event::PaymentFailed to be processed by
an event handler.
2021-09-15 11:50:27 -05:00
Jeffrey Czyz
16ad7f17a1
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.
2021-09-09 23:11:09 -05:00
Devrandom
181d319630 Always use KeysInterface.read_chan_signer for de-serializing EnforcingSigner in tests 2021-08-28 11:01:15 +02:00
Devrandom
50966e25ba Introduce EnforcementState for EnforcingSigner
as we add more enforcement state variables, we want to keep track of them under a single structure
2021-08-28 11:01:15 +02:00
Tibo-lg
2e5e40e0b2 Add custom message handler to peer manager 2021-08-25 13:22:09 +09: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
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