Commit graph

563 commits

Author SHA1 Message Date
Antoine Riard
7e395e0265 Remove per_input_material introduce in commit 0011713
Caching of input material for HTLC transaction was introducted
prevently but since then API (InputMaterial) has changed
between ChannelMonitor and OnchainTxHandler
2020-04-17 17:43:50 -04:00
Antoine Riard
3cb61e979c Access signed local commitment through OnchainTxHandler
Implementing dynamic fee bumping implied to cache transaction material
including its witness, to generate a bumped version if needed.

ChannelMonitor is slowly rescoped to its parsing function with ongoing
patchset and data duplicata are removed. If signed local commitment tx
access is needed, it's done through OnchainTxHandler extended API

For test framework purpose, we use the test-only method
ChannelMonitor::unsafe_get_latest_local_commitment_txn to intentionally
generate unsafe local commitment to exerce revocation logic.
2020-04-17 17:43:50 -04:00
Antoine Riard
493ffb81e1 Cache current local commitment number in ChannelMonitor.
By caching current local commitment number instead of deciphering
it from local commitment tx, we may remove local commitment tx
from ChannelMonitor in next commit.
2020-04-17 17:43:50 -04:00
Antoine Riard
2be1f72005 Move local commitment tx generation in OnchainTxHandler
Local Commitment Transaction can't be bumped without anchor outputs
so their generation is one-time for now. We move them in
OnchainTxHandler for simplifying ChannelMonitor and to prepare
storage of keys material behind one external signer interface.

Some tests break due to change in transaction broadcast order but
number of transactions broadcast should stay the same.
2020-04-17 17:43:50 -04:00
Antoine Riard
e46e183084 Prevent any update of local commitment transaction once signed
To prevent any unsafe state discrepancy between offchain and onchain,
once local commitment transaction has been signed due to an event
(either block height for HTLC-timeout or channel force-closure), don't
allow any further update of local commitment transaction view
to avoid delivery of revocation secret to counterparty for the
aformentionned signed transaction.
2020-04-17 17:43:50 -04:00
Antoine Riard
73e0a0112a Cache local_commitment_tx in OnchainTxHandler
As transaction generation and signature is headed to be moved
inside OnchainTxHandler, cache local_commitment_tx signed by remote.

If access to local commitment transaction is needed, we extend Onchain
TxHandler API to do so.
2020-04-17 17:43:50 -04:00
Antoine Riard
04a17b2a15 Cache funding_redeemscript in OnchainTxHandler
As transaction generation and signature is headed to be moved
inside OnchainTxHandler, cache any usefule witness element.
2020-04-17 17:43:50 -04:00
Antoine Riard
f60519daf2 Remove duplicata for local commitment+HTLC txn
Previously, we would regenerate this class of txn twice due to
block-rescan triggered by new watching outputs registered.

This commmit doesn't change behavior, it only tweaks TestBroadcaster
to ensure we modify cleanly tests anticipating next commit
refactor.
2020-04-17 17:43:34 -04:00
Jeffrey Czyz
8ca6cb765e Add missing known features in constructor
PaymentSecret and BasicMPP were added in d39f25839a
but were not accounted for in with_known_relevant_init_flags.
2020-04-15 19:29:20 -07:00
Antoine Riard
5101d2086c Remove signing local commitment transaction from ChannelMonitor
Extend external signer interface to sign local commitment transactions
on its behalf without seckey passing. This move will allow us to remove
key access from ChannelMonitor hot memory in further work.

Local commitment transaction should stay half-signed by remote until
we need to broadcast for a channel force-close or a HTLC to timeout onchain.

Add an unsafe test-only version of sign_local_commitment to fulfill our
test_framework needs.
2020-04-15 22:23:01 -04:00
Jeffrey Czyz
fe73761d90 Add missing feature sanity checks
PaymentSecret and BasicMPP were added in d39f25839a
but the sanity test for supported features was missed.
2020-04-15 18:21:29 -07:00
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
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
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
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
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
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
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
Antoine Riard
aa84673cdb Move SpendableOutputDescriptor for closing tx in
is_paying_spendable_output

Add ChannelMonitor::shutdown_script to detect onchain tx
paying back to us
2020-03-19 22:29:26 -04:00
Antoine Riard
1cee5671c3 Move SpendableOutputDescriptor::DynamicOutputP2WPKH in
is_paying_spendable_output

Add ChannelMonitor::broadcasted_remote_payment_script to detect
onchain remote txn paying back to us.
2020-03-19 22:29:26 -04:00
Antoine Riard
a2bdadaeed Move SpendableOutputDescirptor::DynamicOutputP2WSH in
is_paying_spendable_output

Add ChannelMonitor::broadcasted_local_revokable_script to detect
onchain local txn paying back to us.

Fix tests in consequence
2020-03-19 22:29:26 -04:00