Commit graph

1361 commits

Author SHA1 Message Date
Matt Corallo
02c1925c16
Merge pull request #559 from ariard/2020-03-move-local-commitment
Split parsing and transaction management for local transactions between Chanmon/Onchain
2020-04-18 00:05:11 +00:00
Antoine Riard
95830edac7 Add test_update_err_monitor_lockdown
This test tries the new lockdown logic in case of a signed-and-broadcast
local commitment transaction while a concurrent ChannelMonitorUpdate for
a next _local_ commitment is submitted from offchain. Update is rejected
as expected with a ChannelMonitorUpdateErr.
2020-04-17 17:50:26 -04:00
Antoine Riard
851ab92ea2 Monitor should panic on receiving buggy update sequences
Channel shouldn't send a ChannelForceClosed update followed by
a LatestLocalCommitmentTxInfo as it would be a programming error
leading to risk of money loss. Force-closing the channel will
broadcast the local commitment transaction, if the revocation
secret for this one is released after its broadcast, it would
allow remote party to claim outputs on this transaction using
the revocation path.
2020-04-17 17:50:26 -04:00
Antoine Riard
ba880e3662 Make acces and signature of local commitment transaction unique
Local commitment transaction broadcast can be triggered by a)
a Channel force-close or b) reaching some block height implying
a onchain HTLC-timeout. If one of this condition is fulfilled,
commitment is signed and from then any state update would be
rejected.

ChannelMonitor init at Channel creation need to be refactored
before to make get_fully_signed_local_tx infaillible to avoid
choking in the test framework.
2020-04-17 17:50:26 -04:00
Antoine Riard
9faf6ca85f Remove temporary anti-duplicata logic 2020-04-17 17:50:26 -04:00
Antoine Riard
1107ab06c3 Move HTLC tx generation in OnchainTxHandler
HTLC Transaction can't be bumped without sighash changes
so their gneeration is one-time for nwo. 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 broadcaster order.
Number of transactions may vary because of temporary anti-duplicata
tweak can't dissociate between 2- broadcast from different
origins (ChannelMonitor, ChannelManager) and 2-broadcast from same
component.
2020-04-17 17:50:21 -04:00
Antoine Riard
8369541f63 Add OnchainTxHandler::get_fully_signed_htlc
In case of channel force-closure, access to local commitment
transactions and its dependent HTLCs is needed. Instead of using
broadcast_by_local_state which registers outpoint to claim and
outputs to watch which are going to be discarded in this case,
we simply ask OnchainTxHandler to build and sign HTLC transactions
through new API.
2020-04-17 17:43:50 -04:00
Antoine Riard
6b8a516647 Cache csv_local inside OnchainTxHandler
csv_local is csv_delay encumbering local revokable_redeemscript
for to_local an htlc output on local commitment/HTLC transactions.
2020-04-17 17:43:50 -04:00
Antoine Riard
080afeb6ea Cache per-HTLC data in OnchainTxHandler::HTLCTxCache
Splitting further parsing from transaction generation, we cache
transaction elements needed for local HTLC transaction inside
OnchainTxHandler. Duplicated data will be removed from ChannelMonitor
in future commits.
2020-04-17 17:43:50 -04:00
Antoine Riard
010fb3051c Cache HTLC transaction material inside OnchainTxHandler
Splitting further parsing from transaction generation, we cache
transaction elements needed for local HTLC transaction inside
OnchainTxHandler. Duplicated data will be removed from ChannelMonitor
in future commits.
2020-04-17 17:43:50 -04:00
Antoine Riard
c2347d61b4 Remove signing htlc transaction from ChannelMonitor
Extend external signer interface to sign HTLC transactions on its
behalf without seckey passing. This move will allow us to remove
key access access from ChannelMonitor hot memory in further work.

HTLC transactions should stay half-signed by remote until
we need to broadcast them for timing-out/claiming HTLCs onchain.
2020-04-17 17:43:50 -04:00
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
Matt Corallo
a44454e1da
Merge pull request #589 from jkczyz/2020-04-feature-fixes
Missing feature checks and tests
2020-04-17 20:03:06 +00: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
7ec16e5ad1
Merge pull request #441 from TheBlueMatt/2020-01-mpp
Multi-Path Payments
2020-04-15 01:36:44 +00: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
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