Commit graph

846 commits

Author SHA1 Message Date
Matt Corallo
fd0ebcf8ec Add some simple tests of payment secret tracking 2021-04-28 15:30:25 -04:00
Matt Corallo
f9a6cb2a8b Fail PendingInboundPayments after their expiry time is reached 2021-04-28 15:30:25 -04:00
Matt Corallo
3b8ac139ba Give users who use get_payment_secret_preimage the PaymentPreimage
For users who get PaymentPreimages via
`get_payment_secret_preimage`, they need to provide the
PaymentPreimage back in `claim_funds` but they aren't actually
given the preimage anywhere.

This commit gives users the PaymentPreimage in the
`PaymentReceived` event.
2021-04-28 15:30:25 -04:00
Matt Corallo
ecaeddca47 Make the PaymentSecret in PaymentReceived events non-Optional 2021-04-28 15:30:25 -04:00
Matt Corallo
5e968114b6 Drop the amount parameter to claim_funds
Like the payment_secret parameter, this paramter has been the source
of much confusion, so we just drop it.

Users should prefer to do this check when registering the payment
secret instead of at claim-time.
2021-04-28 15:30:25 -04:00
Matt Corallo
5a1404809f Drop now-useless PaymentSecret parameters when claiming/failing-back 2021-04-28 15:30:25 -04:00
Matt Corallo
210b887d7c Add a user_payment_id to get_payment_secret+PaymentReceived
This allows users to store metadata about an invoice at
invoice-generation time and then index into that storage with a
general-purpose id when they call `get_payment_secret`. They will
then be provided the same index when the payment has been received.
2021-04-28 15:30:25 -04:00
Matt Corallo
25e4f3e46e Drop dead code for handling non-MPP payments in claim_funds 2021-04-28 15:30:25 -04:00
Matt Corallo
8bf3d8dec2 Req+check payment secrets for inbound payments pre-PaymentReceived
Our current PaymentReceived API is incredibly easy to mis-use -
the "obvious" way to implement a client is to always call
`ChannelManager::claim_funds` in response to a `PaymentReceived`
event. However, users are *required* to check the payment secret
and value against the expected values before claiming in order to
avoid a number of potentially funds-losing attacks.

Instead, if we rely on payment secrets being pre-registered with
the ChannelManager before we receive HTLCs for a payment we can
simply check the payment secrets and never generate
`PaymentReceived` events if they do not match. Further, when the
user knows the value to expect in advance, we can have them
register it as well, allowing us to check it for them.

Other implementations already require payment secrets for inbound
payments, so this shouldn't materially lose compatibility.
2021-04-28 15:30:25 -04:00
Matt Corallo
a7082901fe Use payment_secrets in all sends in functional tests
This prepares us for requiring payment_secrets for all received
payments, by demonstrating test changes work even prior to the new
requirement.

In order to avoid needing to pipe payment secrets through to
additional places in the claim logic and then removing that
infrastructure once payment secrets are required, we use the new
payment secret storage in ChannelManager to look up the payment
secret for any given pament hash in claim and fail-back functions.
This part of the diff is reverted in the next commit.
2021-04-28 15:30:25 -04:00
Matt Corallo
73a3bb3dca Use known InvoiceFeatures for routing in tests 2021-04-28 15:30:25 -04:00
Matt Corallo
6e5cf5e8d4 Pipe through PaymentSecrets in tests during payment hash creation
In order to reduce code movement in the next commit, this commit
simply tweaks get_payment_preimage_hash!() and related functions in
functional tests to return a payment secret. Further, we ensure
that we always call get_payment_preimage_hash!() with the node
which will ultimately receive the payment.
2021-04-28 15:30:25 -04:00
Matt Corallo
7d8dc7ac1a DRY the get_route_and_payment_hash!() macro duplicated in tests 2021-04-28 15:30:25 -04:00
Matt Corallo
7bf6bd2317 Add payment secret and preimage tracking in ChannelManager
This adds support for tracking payment secrets and (optionally)
payment preimages in ChannelManager. This potentially makes client
implementations much simper as they don't have to have external
payment preimage tracking.

This doesn't yet use such tracking anywhere.
2021-04-28 15:30:25 -04:00
Matt Corallo
3180c436f5 Set payment_secret to required in features flags 2021-04-27 23:40:33 +00:00
Matt Corallo
affefb677e
Merge pull request #854 from TheBlueMatt/2021-03-fix-lens
Fix serialization expected lengths and check them in test/fuzzing
2021-04-27 02:05:29 +00:00
Matt Corallo
ee0ffe5dfd Use more descriptive names in serialization impl macros 2021-04-27 01:09:12 +00:00
Matt Corallo
25b9fd8079 Fix serialization expected lengths and check them in test/fuzzing 2021-04-27 01:09:12 +00:00
Matt Corallo
6b9ec8b6e6
Merge pull request #894 from TheBlueMatt/2021-04-fix-docs
Fix doc resolution in rustc 1.48
2021-04-26 19:59:32 +00:00
Matt Corallo
cc18e8a279
Merge pull request #876 from valentinewallace/invoice-features
Invoice features
2021-04-26 18:00:33 +00:00
Valentine Wallace
b24d02c6a2
Add Features feature to invoices. 2021-04-26 12:29:46 -04:00
Matt Corallo
36570f4593
Merge pull request #890 from TheBlueMatt/2021-04-fix-chan-shutdown-crash
Fix (and test) panic when our counterparty uses a bogus funding tx
2021-04-24 00:03:42 +00:00
Matt Corallo
eb42caf8a0 Fix (and test) panic when our counterparty uses a bogus funding tx
During the block API refactor, we started calling
Channel::force_shutdown when a channel is closed due to a bogus
funding tx. However, we still set the channel's state to Shutdown
prior to doing so, leading to an assertion in force_shutdown (that
the channel is not already closed).

This removes the state-set call and adds a (long-overdue) test for
this case.

Fixes: 60b962a18e
2021-04-23 22:52:43 +00:00
Valentine Wallace
f52b617c12
Expose Features::from_le_bytes() method
Useful for constructing features objects from raw feature bytes.
2021-04-23 17:11:40 -04:00
Matt Corallo
f1fa961c40 Fix doc resolution in rustc 1.48 2021-04-23 20:42:11 +00:00
Matt Corallo
0d75a63ead
Merge pull request #889 from jkczyz/2021-04-electrum-trait
Define chain::Confirm trait for use by Electrum clients
2021-04-23 19:13:23 +00:00
Jeffrey Czyz
99e2283aee
Drop pub functions for ChainMonitor's Listen impl 2021-04-22 14:17:26 -07:00
Jeffrey Czyz
93d20ff63e
Implement chain::Confirm for ChainMonitor 2021-04-22 14:17:26 -07:00
Jeffrey Czyz
23c4c8b7c7
Implement chain::Confirm for relevant structs 2021-04-22 14:17:26 -07:00
Jeffrey Czyz
6b12dd207f
Define chain::Confirm trait
Define a separate trait akin to chain::Listen for notifying when
transactions have been confirmed on chain or unconfirmed during a chain
reorganization. Whereas chain::Listen is used for block-oriented chain
sources, chain::Confirm is used for chain sources supplying data for
activity related to transactions and outputs registered via
chain::Filter.
2021-04-22 14:17:25 -07:00
Matt Corallo
bfd1128213 [peer_handler] Take the peers lock before getting messages to send
Previously, if a user simultaneously called
`PeerHandler::process_events()` from two threads, we'd race, which
ended up sending messages out-of-order in the real world.
Specifically, we first called `get_and_clear_pending_msg_events`,
then take the `peers` lock and push the messages we got into the
sending queue. Two threads may both get some set of messages to
send, but then race each other into the `peers` lock and send the
messages in random order.

Because we already hold the `peers` lock when calling most message
handler functions, we can simply take the lock before calling
`get_and_clear_pending_msg_events`, solving the race.
2021-04-21 22:03:45 +00:00
Matt Corallo
f40e47c1ef
Merge pull request #887 from valentinewallace/invoice-use-RL-routehint
invoice: swap RouteHop for RouteHint
2021-04-21 15:21:39 +00:00
Valentine Wallace
ad900658ce
Rename RouteHint to RouteHintHop (which is more accurate) 2021-04-20 16:26:56 -04:00
Valentine Wallace
21cb8db1b6
invoice: swap RouteHop for RouteHint
To prevent naming conflicts in bindings
2021-04-20 16:26:52 -04:00
Matt Corallo
e6c922803f
Merge pull request #844 from sr-gi/843-ln-signing
Adds lightning message signing/verification/pk_recovery
2021-04-20 00:45:30 +00:00
Sergi Delgado Segura
7bcf5a1731
Changes zbase32 crate from pub to pub(crate) 2021-04-16 07:35:04 +02:00
Matt Corallo
f13e38c3f7
Correct license header in zbase32 to match original work
The original work is licensed dual MIT+Apache-2 just like us, so
the license header should not only mention MIT.
2021-04-16 07:35:04 +02:00
Matt Corallo
d8716455b3
Replace spaces with tabs in zbase32.rs 2021-04-16 07:35:04 +02:00
Matt Corallo
7c9302f6a7
Fix a number of bugs in zbase32 and add a fuzzer which caught them. 2021-04-16 07:35:03 +02:00
Sergi Delgado Segura
6f7a2bcdd1
Adds lightning message signing/verification/pk_recovery 2021-04-16 07:34:51 +02:00
Matt Corallo
ffedc055b5 Make the used-in-pub-interfaces TransactionOutputs type alias pub 2021-04-15 16:10:21 -04:00
Jeffrey Czyz
524c532d40
Rename onchain_events_waiting_threshold_conf 2021-04-14 13:00:16 -07:00
Jeffrey Czyz
5e8b683333
Parameterize test_htlc_on_chain_timeout
This test failed when ConnectionStyle was set to a SkippingBlocks
variant because of a bug in ChannelMonitor::update_best_block.
Parameterize the test with these styles to catch any regressions.
2021-04-14 13:00:16 -07:00
Jeffrey Czyz
d45b38f43f
Test ChainMonitor's Electrum interface 2021-04-14 12:57:06 -07:00
Jeffrey Czyz
87f74fd451
Reuse txdata in functional_test_utils.rs 2021-04-14 12:57:06 -07:00
Jeffrey Czyz
1c72489e52
Add an internal typedef for transaction outputs 2021-04-14 12:57:06 -07:00
Jeffrey Czyz
34792d0f1a
Remove unnecessary script_pubkey clones 2021-04-14 12:57:05 -07:00
Jeffrey Czyz
f57c8856b5
Electrum interface for ChainMonitor
Add an interface to ChainMonitor for Electrum users, delegating to the
corresponding methods in each ChannelMonitor.
2021-04-14 12:57:05 -07:00
Jeffrey Czyz
c57bf73a02
Add ChannelMonitor::get_relevant_txids
Define an Electrum-friendly interface for ChannelMonitor where txids of
relevant transactions can be obtained. For any of these transactions
that are re-orged out of the chain, users must call
transaction_unconfirmed.
2021-04-14 12:57:05 -07:00
Jeffrey Czyz
65e588fd92
Add ChannelMonitor::transaction_unconfirmed
Define an Electrum-friendly interface for ChannelMonitor where
transactions are unconfirmed independently from updating the latest
block.
2021-04-14 12:57:05 -07:00