Commit graph

1720 commits

Author SHA1 Message Date
Matt Corallo
775a5adfb9 ChannelMonitor::get_funding_txo returns both the txid and scriptPK
... instead of only the txid.

This is another instance of it not being possible to fully
re-implement SimpleManyChannelMonitor using only public methods. In
this case you couldn't properly register outpoints for monitoring
so that the funding transaction would be matched.
2020-06-22 13:42:28 -04:00
Matt Corallo
70fca0784c
Merge pull request #641 from jkczyz/2020-06-deterministic-test-logging
Make test output deterministic
2020-06-21 19:44:56 +00:00
Jeffrey Czyz
43eed8dd8b
Make test output deterministic
Tests use sources of randomness to produce seeds, preimages, secrets,
and ephemeral data. However, this makes comparing logs between different
test runs difficult. Remove uses of random number generators and the
current time in favor of fixed values in order to make the test output
deterministic.
2020-06-18 19:28:50 -07:00
Matt Corallo
bd2fa43acd
Merge pull request #639 from valentinewallace/fix-feerate-new-channel
Use our actual feerate in open_channel messages, not a new one
2020-06-16 19:51:24 +00:00
Valentine Wallace
f91718722a
Switch all feerate u64's to u32's.
The protocol only allows a u32, so if we received or sent something
larger it would be an issue (though it's unlikely).
2020-06-15 21:52:52 -04:00
Valentine Wallace
4c655b2281
Use our actual feerate in open_channel messages, not a new one
When we were sending an open_channel messages we were asking the
feerate estimator for a new value instead of using the one we had.
If the feerate estimator gave a different value than the one it did
when we created the Channel struct, we'd start out-of-sync with our
counterparty and blow up on funding_signed. Even worse, the
ConfirmationTarget used was different, so its highly likely they
would disagree.

Also remove newly unused fee estimator parameter from get_open-channel
API.

Co-authored-by: Matt Corallo <git@bluematt.me>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2020-06-15 18:22:33 -04:00
Matt Corallo
c1c9b1175b
Merge pull request #577 from valentinewallace/fix-onchain-fee-check-htlcs
Incl tx fee when calcing inbound+outbound HTLC limits on channels
2020-06-15 20:17:03 +00:00
Valentine Wallace
17ccab4f4a
Update chanmon fuzzer to include small payment actions.
This change should allow the fuzzer to catch more edge cases, such as
channel reserve checks that cut it close when sending payments.
2020-06-15 15:51:15 -04:00
Valentine Wallace
c9926b9500
Add fee spike buffer + incl commit tx fee in chan reserve calculation
When we receive an inbound HTLC from a peer on an inbound channel,
make sure the funder can still cover the additional on-chain cost
of the HTLC while maintaining their channel reserve.

When we're sending an outbound HTLC, make sure the funder can still
cover the additional on-chain cost of the HTLC while maintaining
their channel reserve.

+ implement fee spike buffer for channel initiators sending payments.
Also add an additional spec-deviating fee spike buffer on the
receiving side (but don't close the channel if this reserve is
violated, just fail the HTLC).
From lightning-rfc PR #740.

Co-authored-by: Matt Corallo <git@bluematt.me>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2020-06-15 15:51:09 -04:00
Matt Corallo
9be497cad4
Merge pull request #634 from valentinewallace/improve-inbound-htlc-docs
Improve documentation for InboundHTLCState enum states.
2020-06-11 18:59:07 +00:00
Valentine Wallace
96daffaf63
Improve documentation for InboundHTLCState enum states. 2020-06-11 14:40:29 -04:00
Valentine Wallace
283c94727f
Refactor: move channel checks for HTLC adds into Channel
This also includes adding a closure that creates a new pending HTLC status
as a parameter for Channel's update_add_htlc. This will later be useful
when we add the check for fee spike buffer violations, which will also result
in changing an HTLC's pending status to failing.

Co-authored-by: Jeffrey Czyz <jkczyz@gmail.com>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2020-06-11 09:05:30 -04:00
Matt Corallo
7aae6d51e9
Merge pull request #629 from arik-so/message_handling_extraction
Extract wire message handling into a method.
2020-06-11 03:58:07 +00:00
Arik Sosman
3838c04172
Extract wire message handling into a method.
This is a response to splitting #585 into smaller components. This extraction should allow the subsequent creation of a trait for all message handling, thereby enabling more flexibility in the state machine, particularly for bindings.
2020-06-06 22:55:12 -07:00
Matt Corallo
f08d610270
Merge pull request #632 from TheBlueMatt/2020-05-drop-chankeys-privs
Drop ChannelKeys Private Key Methods
2020-06-06 23:22:59 +00:00
Matt Corallo
e5a74227f6 Drop requirement that all ChannelKeys expose htlc_basepoint 2020-06-06 15:59:27 -04:00
Matt Corallo
d77e40fa76 Drop requirement that ChannelKeys expose delayed_payment_basepoint 2020-06-06 15:59:27 -04:00
Matt Corallo
d9f5df99b0 Drop requirement that all ChannelKeys expose revocaion_basepoint 2020-06-06 15:59:27 -04:00
Matt Corallo
1a574d2055 Drop requirement that all ChannelKeys expose the payment_point 2020-06-06 15:59:27 -04:00
Matt Corallo
9f7bcfb1ed Drop requirement that all ChannelKeys expose the funding privkey 2020-06-06 15:59:27 -04:00
Matt Corallo
b1d536e57a Expose private keys from InMemoryChannelKeys publicly
As we drop the requirement that all ChannelKeys expose the private
keys used, we should have a way to access the private keys in use
when using InMemoryChannelKeys.
2020-05-28 16:16:17 -04:00
Matt Corallo
2087032e7a
Merge pull request #620 from TheBlueMatt/2020-05-pre-bindings-cleanups
Pre-C Bindings Cleanup
2020-05-28 19:34:42 +00:00
Matt Corallo
9dbce1c316
Merge pull request #610 from ariard/2020-04-cache-in-monitor
Move back to ChannelMonitor RemoteTxCache
2020-05-28 19:25:06 +00:00
Antoine Riard
81e358c91f Add test_key_derivation_params
`to_local` output or remote output on remote commitment transaction
needs a channel keys to be spent. As per-channel keys are derived from
KeysManager seed and per-channel secrets those must be backed up by
any descriptor bookmarking for latter spend. We test that generating
a new KeysManager loaded with such backed-up seed/per-channel secrets
return the correct keys for spending a `to_local` output.
2020-05-28 04:21:47 -04:00
Matt Corallo
d0c5e9c81d Significantly clarify key derivation and expose methods referenced 2020-05-28 04:21:47 -04:00
Antoine Riard
42b731d92b Document better DynamicOutputP2WSH 2020-05-28 04:21:47 -04:00
Antoine Riard
22daecb8e4 Remove useless build warnings 2020-05-28 04:21:47 -04:00
Antoine Riard
03fa056acc Make get_revokable_redeemscript 2020-05-28 04:21:47 -04:00
Antoine Riard
4f84b05d31 Make derive_private_key public 2020-05-28 04:21:47 -04:00
Antoine Riard
06445b6189 Dry-up witnessScript in sign_remote_htlc_transaction
Instead of blindly signing provided witnessScript, signer must derive
channel keys corresponding to the provided per-commitment-point and
regenerate templated witnessScript to ensure its syntax correctness.
2020-05-28 04:21:47 -04:00
Antoine Riard
479e1c8ddf Dry-up witnessScript in sign_justice_transaction
Instead of blindly signing provided witnessScript, signer must derive
channel keys corresponding to the provided per-commitment-point and
regenerate templated witnessScript to ensure its syntax correctness.
2020-05-28 04:21:47 -04:00
Antoine Riard
7de03e175b Imp Writer/Reader for RemoteCommitmentTransaction 2020-05-28 04:21:47 -04:00
Antoine Riard
3aef447992 Rename RemoteTxCache as RemoteCommitmentTransaction and document better
We also remove an unecessary build warning.
2020-05-28 04:21:47 -04:00
Antoine Riard
f655c516e7 Rename their_to_self_delay as on_local_tx_csv
on_remote_tx_csv is the CSV delay encumbering remote transactions
revokable outputs as required by local.

on_local_tx_csv is the CSV delay encumbering local transactions
revokable outputs as required by remote.

Local/remote is here defined from a code processing viewpoint,
process running this code is "local".
2020-05-28 04:21:47 -04:00
Antoine Riard
56ec6e0060 Drop remote_csv from OnchainTxHandler, cache it in Monitor's cache 2020-05-28 04:21:47 -04:00
Antoine Riard
9455b49a5d Dedup RemoteTxCache by removing OnchainTxHandler copy
RemoteTxCache was providing all data needed at transaction
signature for any remote HTLC transaction or justice transaction.
This move was making the API between OnchainTxHandle akward and
scope of responsibilites with ChannelMonitor unclear.

Instead scope OnchainTxHandler to transaction-finalization, fee-bumping
and broadcast only.
2020-05-28 04:21:47 -04:00
Antoine Riard
1d7ed17a64 Duplicate RemoteTxCache in ChannelMonitor
Dry-up remote pubkeys tracking in one struct.

This introduce a duplicate of RemoteTxCache, which is going
to be removed in next commit when OnchainTxHandler version is
removed.
2020-05-28 04:21:47 -04:00
Antoine Riard
2c07f8e794 Remove SecretKey from DynamicOuputP2WPKH descriptor
Add sign_payment_transaction in ChanSigner to be able to spend
SpendableOutputDescriptor in test framework

Extend ChannelKeys with remote_pubkeys to access remote revocation
basepoint for witnessScript construction.
2020-05-28 04:21:47 -04:00
Antoine Riard
3188ac9caf Remove SecretKey from DynamicOutputP2WSH descriptor
Add sign_delayed_transaction in ChanSigner to be able to spend
SpendableOutputDescriptor in test framework.
2020-05-28 04:21:47 -04:00
Antoine Riard
2f4f0aa766 Extend KeysInterface with derive_channel_keys
A dynamic-p2wsh-output like `to_local` on local commitment/HTLC txn
require a signature from delayed_payment_key to be spend. Instead of
sending private key in descriptor, we ask for spender to derive again
the corresponding ChannelKeys based on key state, uniquely identifying
a channel and encompassing its unique start data.

Descriptor modification is done in next commit.
2020-05-28 04:21:46 -04:00
Matt Corallo
fd71f8b01f
Merge pull request #624 from arik-so/encode_and_send_msg_method_refactor
Extract encode_and_send_msg into a method.
2020-05-22 18:45:55 +00:00
Matt Corallo
ba06507a4f Expose PeerHandleError::no_connection_possible
Its just a trivial bool and already has docs on it, so seems like
an oversight
2020-05-22 14:28:56 -04:00
Matt Corallo
0d77e7ce86 Three small fixes to work around our bindings generator limitations
* Return Self instead of the fully-written types for constructors,
 * Place definitions before use (in this case for KeysInterface),
 * Don't import foo::bar::self, but import foo::bar

 + a spelling fix in the KeysInterface docs for get_onion_rand.
2020-05-22 14:28:56 -04:00
Matt Corallo
9d4b6e762c Return a ChannelManager instead of result from ChannelManager::new()
We never actually fail, so we can just drop the Result type.
2020-05-22 14:28:56 -04:00
Matt Corallo
fab5d7e0ae Make RoutingMessageHandler a generic Deref instead of an Arc
We also update to use single idents when referencing the Deref=*
types since the automated code generator is pretty braindead.

This also moves some test utils out of peer_handler.rs and into
util::test_utils to standardize things a little bit, which we need
to concretize the PeerHandler types used in testing.
2020-05-22 14:28:13 -04:00
Matt Corallo
6afda60d88 Make ManyChannelMonitor Keys an associated type
Instead of using a raw generic type, an associted type allows us
to have explicit docs on the type, which is nice. More importantly,
however, our automated bindings generator knows how to read
associated types but not raw generics.

Also, our bindings generator expects things which are referenced to
have already been defined, so we move ManyChannelMonitor below the
ChannelMonitor definition.
2020-05-22 13:59:14 -04:00
Arik Sosman
dbdef7fac1
Extract encode_and_send_msg into a method.
This is a response to splitting #585 into smaller components. This extraction will permit a future extraction of all message handling into a separate method, and then later even into a separate trait that will be accessible through language bindings.
2020-05-22 02:11:45 -07:00
Antoine Riard
f8ea748268 Add KeysManager::derive_unique_start
In next commit, we add derive_channel_keys, a helper to rederive
keys from a SpendableOuptutDescriptor. We still need to ensure
that user rederive same set of keys even if KeyManager is started
at a later time. For doing so we need to pass starting time as
part of the re-derived sha_state, therefore we need to make it
accessible and part of channel state key material.

Seed is already required to be conserved between KeysManager
serializations.
2020-05-18 04:50:26 -04:00
Antoine Riard
ea238a24b4 Move remote htlc transaction signature behind ChanSigner 2020-05-18 04:49:45 -04:00
Antoine Riard
0a345c046c Build witness_script for remote htlc transactions inside
OnchainTxHandler

By moving script generation inside OnchainTxHandler, we may dry-up
further ChannelMonitor in next commits

Comment MINIMALIF rule
2020-05-18 04:48:22 -04:00