Commit graph

426 commits

Author SHA1 Message Date
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
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
Antoine Riard
276c607fa8 Move justice transaction signature behind ChanSigner 2020-05-18 04:46:48 -04:00
Antoine Riard
824e318be3 Build witness_script for justice tx inside OnchainTxHandler
By moving script generation inside OnchainTxHandler, we may dry-up
further ChannelMonitor in next commits.
2020-05-18 04:44:06 -04:00
Antoine Riard
6512e8a8dd Replace is_htlc in InputMaterial by InputDescriptor
As we cache more and more transaction elements in OnchainTxHandler
we should dry up completly InputMaterial until them being replaced
directly by InputDescriptor
2020-05-18 04:42:09 -04:00
Antoine Riard
275814cc1d Cache remote HTLC inside OnchainTxHandler::RemoteTxCache
As we can't predict if any and which revoked commitment tx is
going to appear onchain we have by design to cache all htlc information
to regenerate htlc script if needed.
2020-05-18 04:39:26 -04:00
Antoine Riard
6b1afcc313 Cache remote basepoint and remote_csv in new OnchainTxHandler::RemoteTxCache
Used in next commits to avoid passing script between ChannelMonitor
and OnchainTxHandler. ChannelMonitor duplicata will be removed
in future commits.
2020-05-18 04:39:26 -04:00
Matt Corallo
8ade071d56 Drop OutPoint::new since the struct is all pub
This makes it easier for our automated bindings generator to
function as it tries to automatically create a ::new if the struct
contains only pub elements who's type is convertible.
2020-05-17 23:24:41 -04:00
Valentine Wallace
222f0cbdd2
PeerManager Logger Arc --> Deref 2020-05-17 13:02:32 -04:00
Valentine Wallace
87126b391b
ChannelManager+Router++ Logger Arc --> Deref
This caused a bunch of cascading changes, including
passing loggers down to Channels in function calls
rather than having each Channel have a pointer to the
ChannelManager's Logger (which was a circular reference).
Other structs that the Channel had passed its Logger to also
had their loggers removed. Other newly unused Loggers were
also removed, especially when keeping them would've caused
a bunch of extra test changes to be necessary, e.g. with
the ChainWatchInterfaceUtil's Logger.
2020-05-17 12:33:43 -04:00
Sourabh Marathe
9c587e5312 Serialize ChannelManager events
Also adds a test for de/serializing events
2020-05-14 17:02:54 -04:00
Matt Corallo
b1c80970e9 Fix some new indentation nits 2020-05-12 14:16:43 -04:00
Matt Corallo
6e1aa6cab5 Fix a few new (and one old) issues in the new channel_update
We need to always set lowest_inbound_channel_fees to None if there
are no channels (and we should ignore the channels which are
disabled for the purpose of lowest-fee calculations). Further, we
cannot unwrap the channel lookups as they may be for channels which
are not related to the channel we are processing an update for.
Finally, we can satisfy borrowck much easier since things are on
self instead of on a MutexGuard.
2020-05-12 14:02:40 -04:00
Matt Corallo
94df32b108 Add assertion since we now have a pub field that is PartialEq
We previously were only able to assert that the route graph
serialization roundtrips were good by comparing the network
messages returned from them, but we can now do better as the graph
is exposed publicly via a simple datastructure that implements
PartialEq.
2020-05-12 14:02:40 -04:00
Matt Corallo
57ac2ec1b6 Add missing comment on why last_update_message is None 2020-05-12 14:02:40 -04:00
Matt Corallo
0e3bf19b66 Move get_addresses to network_graph and drop now-useless log_trace
Because we expose the internals we don't need a method to log
their contents anymore, and get_addresses can now avoid copying as
we expose the RwLock directly
2020-05-12 14:02:40 -04:00
Matt Corallo
5dc724f875 Drop new test Node field introduced in 8ce2223b6952567b28adfcc11c2
8ce2223b6952567b28adfcc11c23c9f19c4c0324 introduced a new field in
the "Node" objects used in our functional tests - the node_id. Its
not a bad idea to cache it, but unless we want to commit and use it
everywhere, we should avoid duplicating data, especially in tests
where we'd rather exercise the underlying code than bypass it.
2020-05-12 14:02:40 -04:00
Gleb Naumenko
07a7e34f89 Improve routing-related documentation 2020-05-12 09:27:12 -04:00
Gleb Naumenko
7ec98e6206 Remove NetGraphMsgHandler serialization 2020-05-12 09:27:11 -04:00
Gleb Naumenko
8467223a5d Make DirectionalChannelInfo optional 2020-05-12 09:27:11 -04:00
Gleb Naumenko
afd4282107 Move node announcement fields into a separate struct 2020-05-12 09:27:11 -04:00
Gleb Naumenko
a7e193241c Expose some network graph methods 2020-05-12 09:27:11 -04:00
Gleb Naumenko
e553d2c2c0 Split routing from getting network messages 2020-05-12 09:27:11 -04:00
Gleb Naumenko
6164a95267 Remove non-bitcoin chain helpers 2020-05-12 09:27:11 -04:00
Gleb Naumenko
5bd7f24634 Move router to a separate module 2020-05-12 09:27:11 -04:00
Matt Corallo
d2520f4908
Merge pull request #539 from TheBlueMatt/2020-03-static-remotekey
Require static_remotekey
2020-05-06 02:07:02 +00:00
Matt Corallo
07db23d102 Rename payment_basepoint/key to simply payment_point/key.
We no longer derive any keys from the payment point, so they aren't
a "base" but simply a point/key.
2020-05-05 21:42:36 -04:00
Matt Corallo
babf0af30b Require option_static_remotekey in channel/channelmonitor.
This simplifies channelmonitor quite nicely (as expected) as we
never have to be concerned with learning data in a DataLossProtect
which is require for us to claim our funds from the latest remote
commitment transaction.
2020-05-05 21:42:36 -04:00
Matt Corallo
22dded737b Add detection of feature_static_remotekey support and print
This adds the ability to check for static_remotekey in appropriate
feature contexts and prints it at connect time. It is still
considered unknown for the purposes of requires_unknown_bits() as
we don't yet implement it.
2020-05-05 21:40:51 -04:00
Valentine Wallace
1b656f4d4a
Make channel reserve variable names less confusing.
Previous to this commit, variables such as their_channel_reserve
referred to the channel reserve that _we_ are required to keep,
(the value is initially set by the remote). Similarly,
variables such as our_channel_reserve referred to the channel
reserve that we require the remote to keep.

Change this to use local_channel_reserve / remote_channel_reserve
to refer to the the channel reserve that the local is required to keep
and the channel reserve that the remote is required to keep, respectively.
2020-05-01 19:35:44 -04:00
Matt Corallo
18981a0024 Check local signtures explicitly in channel tx-generation tests
It appears the local signatures which are specified in the channel
transaction-generation tests were never checked directly (though
they were checked as a part of the overall fully-signed-transaction
tests).

Check them explicitly so that they can be updated for static remote
key.
2020-04-29 14:50:09 -04:00
Matt Corallo
3fb482a8d9 Add additional trace logging in channel signature validation
This makes it easier to amend the full_stack_target
test_no_existing_test_breakage test by always providing the
neccessary data in the log.
2020-04-29 14:50:09 -04:00