Commit graph

637 commits

Author SHA1 Message Date
Matt Corallo
71f1eba91f Clarify documentation on deserialization reorg requirements 2020-04-23 13:34:56 -04:00
Matt Corallo
b04219a767 Drop ChannelMonitor::write_for_watchtower
Not only was watchtower mode never implemented, but the bits that
we had were removed some time ago. It doesn't seem likely we'll
move forward with a "watchtower-mode" ChannelMonitor, instead
we'll likely have some other, separate struct for this.
2020-04-22 16:48:13 -04:00
Marty Jones
f5a6796a47
Update lightning/src/util/byte_utils.rs 2020-04-21 20:29:46 -04:00
Marty Jones
09a39725f8 add tests 2020-04-21 20:27:35 -04:00
Matt Corallo
5a2ed03247
Merge pull request #594 from TheBlueMatt/2020-04-cleanups
Trivial Cleanups
2020-04-20 21:54:35 +00:00
Franck Royer
236887da76
Test that height is included for incorrect payment details
Ensure that the best know blockchain height is included in the
data of `incorrect_or_unknown_payment_details` message failure.
2020-04-20 08:30:47 +10:00
Franck Royer
fae46a02e3
Include height to incorrect_or_unknown_payment_details failure
`incorrect_or_unknown_payment_details` failure message,
`0x4000 (PERM) | 15`, should include the following data:
- [u64:htlc_msat]
- [u32:height]
This patches ensure that the height is included in all
the occurrences of this failure message.
2020-04-20 08:30:45 +10:00
Matt Corallo
c89514c37c De-Option<> some fields in ChannelMonitor which are set at init
After we moved the ChannelMonitor creation later during Channel
init, we never went back and cleaned up ChannelMonitor to remove
a number of now-useless Option<>s, so we do that now.
2020-04-18 22:02:38 -04:00
Matt Corallo
f5b0663f6a Drop std::error::Error impl for DecodeError
It appears to be effectively-deprecated in Rust now, and didn't
really appear to serve a lot of purpose anyway.
2020-04-18 20:47:16 -04:00
Matt Corallo
41b3be7ad0 Fix new rustc warnings for unnecessary parenthesis 2020-04-18 20:47:16 -04:00
Matt Corallo
e286afd0b0 Drop uneccessary indirection in map-updating in 1107ab06c3
1107ab06c3 added a Vec of future
updates to apply during a loop, fixing a borrow checker issue that
didn't exist in the merged version of the patch. This simply reverts
that small part of the change.
2020-04-18 20:47:16 -04:00
Matt Corallo
b49e63b1bc Flatten ChannelMonitor substructs that don't add clarity
The new OnchainDetection struct (which is the remnants of the old
KeyStorage enum, which was removed in 1dbda4faed)
doesn't really add any clarity to ChannelMonitor, so best to just
drop it and move its members into ChannelMonitor directly.
2020-04-18 18:10:54 -04:00
Matt Corallo
3c5ba6b619 Drop uneccessary clone() introduced in 16fba9fd66 2020-04-18 18:09:43 -04:00
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
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