Commit graph

1537 commits

Author SHA1 Message Date
Matt Corallo
59b1bf6d0f Pass Route to send_payment as a reference, not move
ChannelManager::send_payment stopped utilizing its ownership of the
Route with MPP (which, for readability, now clone()s the individual
paths when creating HTLCSource::OutboundRoute objects). While this
isn't ideal, it likely also makes sense to ensure that the user has
access to the Route after sending to correlate individual path
failures with the paths in the route or, in the future, retry
individual paths.

Thus, the easiest solution is to just take the Route by reference,
allowing the user to retain ownership.
2020-04-14 20:50:42 -04:00
Matt Corallo
d3b6083ea2 panic!() when serializing OnionHopDatas with value > 21m BTC
Add documentation to the struct fields noting this to avoid missing
docs when various msg structs become public.
2020-04-14 20:50:42 -04:00
Matt Corallo
03a1b5264d Test basic AMP payments in chanmon_consistency 2020-04-14 20:50:42 -04:00
Matt Corallo
3512d6626d Refactor test utils and add a simple MPP send/claim test. 2020-04-14 20:50:42 -04:00
Matt Corallo
b2c9941015 Implement multipath sends using payment_secret.
This rather dramatically changes the return type of send_payment
making it much clearer when resending is safe and allowing us to
return a list of Results since different paths may have different
return values.
2020-04-14 20:50:42 -04:00
Matt Corallo
a93d6e905b Refactor payment-claim logic to ensure MPP-claim atomicity
Previously if we claimed an MPP where a previous-hop channel was
closed while we were waitng for the user to provide us the preimage
we'd simply skip claiming that HTLC without letting the user know.

This refactors the claim logic to first check that all the channels
are still available (which is actually all we need - we really
mostly care about updating the channel monitors, not the channels
themselves) and then claim the HTLCs in the same lock, ensuring
atomicity.
2020-04-14 20:50:41 -04:00
Matt Corallo
5260e81033 Expand the Route object to include multiple paths.
Rather big diff, but its all mechanical and doesn't introduce any
new features.
2020-04-14 19:54:17 -04:00
Matt Corallo
d39f25839a Add/announce features for payment_secret and basic_mpp 2020-04-14 19:54:17 -04:00
Matt Corallo
6d1bd8bc98 Impl Base AMP in the receive pipeline and expose payment_secret
Base AMP is centered around the concept of a 'payment_secret` - an
opaque 32-byte random string which is used to authenticate the
sender to the recipient as well as tie the various HTLCs which
make up one payment together. This new field gets exposed in a
number of places, though sadly only as an Option for backwards
compatibility when sending to a receiver/receiving from a sender
which does not support Base AMP.

Sadly a huge diff here, but almost all of it is changing the method
signatures for sending/receiving/failing HTLCs and the
PaymentReceived event, which all now need to expose an
Option<[u8; 32]> for the payment_secret.

It doesn't yet properly fail back pending HTLCs when the full AMP
payment is never received (which should result in accidental
channel force-closures). Further, as sending AMP payments is not
yet supported, the only test here is a simple single-path payment
with a payment_secret in it.
2020-04-14 19:54:17 -04:00
Matt Corallo
1442acf74b Refuse to deserialize OnionHopDatas with values > 21 million
We should probably do this for all values (and define a newtype
for msat values), but this will do for now.
2020-04-14 19:54:17 -04:00
Matt Corallo
b54817397d Support (de)serializing payment_data in onion TLVs and track them
This is the first step in Base AMP support, just tracking the
relevant data in internal datastructures.
2020-04-14 19:54:17 -04:00
Matt Corallo
f26e373396 Split only-receive/forward data out of PendingHTLCInfo into an enum
This should avoid blowing up the size of the struct when we add
additional data that is only relevant for receive.
2020-04-14 19:54:17 -04:00
Matt Corallo
e8a8fd0fb0
Merge pull request #582 from arik-so/trailing_newline_config
Mandate new line at end of file in editorconfig.
2020-04-11 20:28:26 +00:00
Arik Sosman
d0f941f732
Mandate new line at end of file in editorconfig. 2020-04-11 11:33:07 -07:00
Matt Corallo
c9c9415e5f
Merge pull request #570 from naumenkogs/2020_04_routing_message_handler_tests
Add tests for routing message handler
2020-04-11 18:31:00 +00:00
User
79c8491120 Add tests for getting node announcements 2020-04-11 08:59:08 -04:00
User
42587500d0 Add tests for getting next channel announcements 2020-04-11 08:59:07 -04:00
User
c8a1460ccd Add tests for handling htlc fail channel updates 2020-04-11 08:30:21 -04:00
User
1da1ffa04b Add tests for handling channel updates 2020-04-11 08:30:21 -04:00
User
37f0c1af79 Add tests for handling channel announcements 2020-04-11 08:30:21 -04:00
Matt Corallo
c59468a889 Allow relaying of only one direction in a channel, log on recv 2020-04-11 08:30:21 -04:00
User
fce5c15711 Add tests for handling node announcements 2020-04-11 08:30:21 -04:00
Matt Corallo
60dd37d9a0
Merge pull request #581 from arik-so/fuzz_docs
Create docs for fuzzing
2020-04-11 03:10:58 +00:00
Arik Sosman
cdb1f8e48a
Update documentation to reflect target-dependent local reproduction steps. 2020-04-10 17:15:12 -07:00
Arik Sosman
aea2971f5c
Add details on asserting latest version in the dependencies and listing targets. 2020-04-10 11:22:46 -07:00
Arik Sosman
df18f99b5a
Create docs for fuzzing 2020-04-10 01:28:45 -07:00
Matt Corallo
a4e4056240
Merge pull request #571 from ariard/2020-04-fix-minimalif
Enforce MINIMALIF-compliant witnesses
2020-04-03 16:15:27 +00:00
Antoine Riard
1508253bf0 Enforce MINIMALIF-compliant witness for spending revokable redeemscript 2020-04-02 17:13:13 -04:00
Antoine Riard
0bc82ee1bc Enforce MINIMALIF-compliant witness for timeout tx 2020-04-02 17:10:35 -04:00
Matt Corallo
f0b037ce14
Merge pull request #568 from jkczyz/2020-03-handle-error-deadlock
Fix deadlock in ChannelManager's handle_error!()
2020-04-02 20:06:00 +00:00
Jeffrey Czyz
3968647997 Test failing backward any pending HTLCs
Upon channel failure, any pending HTLCs in a channel's holding cell must
be failed backward. The added test exercises this behavior and
demonstrates a deadlock triggered within the handle_error!() macro. The
deadlock occurs when the channel_state lock is already held and then
reacquired when finish_force_close_channel() is called.
2020-04-01 16:36:49 -07:00
Matt Corallo
86143fd69d Fix deadlock in handle_error!() when we have HTLCs to fail-back.
This partially reverts 933ae34703,
though note that 933ae34703 fixed a
similar deadlock while introducing this one.

If we have HTLCs to fail backwards, handle_error!() will call
finish_force_close_channel() which will attempt to lock channel_state
while it is locked at the original caller. Instead, hold the lock for
shorter scopes such that it is not held upon entering handle_error!().

Co-authored-by: Matt Corallo <git@bluematt.me>
Co-authored-by: Jeffrey Czyz <jkczyz@gmail.com>
2020-04-01 16:27:22 -07:00
Matt Corallo
b8876a90ae
Merge pull request #556 from valentinewallace/add-PR550-test
Test that do_attempt_write_data does not infinitely loop
2020-03-27 20:27:15 +00:00
Valentine Wallace
3e0aed23a3
Test that do_attempt_write_data does not infinitely loop
when all the channel messages can't fit into the buffer.

Adds a test for PR #550.
2020-03-27 16:15:57 -04:00
Matt Corallo
a5e08346c2
Fix initial outbound sync infinite loop 2020-03-23 17:47:17 -04:00
Matt Corallo
e5bedc43d2
Merge pull request #555 from ariard/2020-03-begin-dryup-chanmon-keys
Begin dry-up ChannelMonitor key access
2020-03-21 22:21:38 +00:00
Antoine Riard
502197d943 Remove useless local commitment txn signatures
check_spend_local_transaction is tasked with detection of
onchain local commitment transaction and generate HTLC transaction.
Signing an already onchain tx isn't necessary.
2020-03-21 17:03:54 -04:00
Antoine Riard
82e78872df Dryup SecretKey from ChannelMonitor::OnchainDetection
Key access is provided through ChanSigner.
2020-03-21 17:03:54 -04:00
Antoine Riard
16fba9fd66 Add ChanSigner in OnchainTxHandler
Rename ChannelMonitor::Storage to OnchainDetection,
holder of channel state (base_key+per_commitment_point)
to detect onchain transactions accordingly.

Going further between splitting detection and transaction
generation, we endow OnchainTxHandler with keys access.
That way, in latter commits, we may remove secret keys entirely
from ChannelMonitor.
2020-03-21 17:03:48 -04:00
Matt Corallo
e2be482306
Merge pull request #557 from ariard/2020-03-link-arch-md
Link ARCH.md in README.md
2020-03-21 19:10:26 +00:00
Antoine Riard
e2bd46df63 Link ARCH.md in README.md 2020-03-20 23:13:37 -04:00
Matt Corallo
f1c7fd2ab9
Merge pull request #516 from TheBlueMatt/2020-02-checkin-arch
Add some basic arch diagrams/descriptions.
2020-03-21 01:50:53 +00:00
Matt Corallo
dd375e6157 Add some basic arch diagrams/descriptions. 2020-03-20 20:40:37 -04:00
Matt Corallo
ed0d5d1f6d
Merge pull request #554 from TheBlueMatt/2020-03-stale-mon-fail-man-deser
Fail to deserialize ChannelManager if it is ahead of any monitor(s)
2020-03-20 23:58:51 +00:00
Antoine Riard
1dbda4faed Remove Watchtower mode from Storage enum and make it a struct
Watchtower will be supported through external signer interface
where a watchtower implementation may differ from a local one
by the scope of key access and pre-signed datas.
2020-03-20 17:05:38 -04:00
Matt Corallo
8bd155e774
Merge pull request #552 from ariard/2020-03-ismine-spendable
Introduce IsMine logic in ChannelMonitor for SpendableOutputDescriptor detection
2020-03-20 19:09:10 +00:00
Antoine Riard
1c7b6c8288 Add test_static_spendable_outputs_timeout_tx
Cover previously missing SpendableOuputDescriptor for
timeout tx on non-revoked remote commitment tx.

Fix #338
2020-03-20 14:34:17 -04:00
Matt Corallo
4aa95af272 Test that ChannelManager fails to deserialize if monitors are stale 2020-03-20 12:50:34 -04:00
Matt Corallo
492983f54f Fail to deserialize ChannelManager if it is ahead of any monitor(s)
If any monitors are out of sync with the Channel, we previously
closed the channel, but we should really only do that if the
monitor is ahead of the channel, opting to call the whole thing
invalid if the channel is ahead of the monitor.
2020-03-20 12:30:57 -04:00
Antoine Riard
b7407b219d Implement reorg-safety for SpendableOutputDescriptor detection
We delay SpendableOutputDescriptor until reaching ANTI_REORG_DELAY
to avoid misleading user wallet in case of reorg and alternative
settlement on a channel output.

Fix tests in consequence.
2020-03-19 22:31:48 -04:00