Commit graph

615 commits

Author SHA1 Message Date
Matt Corallo
c60812bffb Drop unused Network argument to KeysManager::new().
KeyManager::new() took a bitcoin::Network parameter which needs to
be passed to the BIP 32 Extended Key constructor, but because we
never write out the BIP 32 serialization, it isn't used. Instead,
we just pass a dummy value into `ExtendedPrivKey`, dropping the
unused argument to KeysManager::new().
2021-02-16 15:58:02 -05:00
Matt Corallo
e7784a6fa5 f fix typos val caught 2021-02-16 15:58:02 -05:00
Matt Corallo
a21decf0db Struct-ify SpendableOutputDescriptor entries relevant to channels
Both SpendableOutputDescriptor::DynamicOutputP2WSH and
SpendableOutputDescriptor::StaticOutputCounterpartyPayment are
relevant only in the context of a given channel, making them
candidates for being passed into helper functions in
`InMemoryChannelKeys`. This moves them into their own structs so
that they can later be used standalone.
2021-02-16 12:40:06 -05:00
Matt Corallo
311555a191 [tests] Correct witness len calc in StaticOutputCounterpartyPayment
We previously counted 35 bytes for a length + public key, but in
reality they are never larger than 34 bytes - 33 for the key and 1
for the push length.
2021-02-16 12:40:06 -05:00
Matt Corallo
2088f4bec3
Merge pull request #786 from TheBlueMatt/2021-02-chansigner-util
Expand documentation and fields in SpendableOutputDescriptors
2021-02-16 09:33:37 -08:00
Matt Corallo
09f37ae89b
Merge pull request #797 from TheBlueMatt/2021-02-no-addr-order
Drop address ordering enforcement in NodeAnnouncement deser
2021-02-16 08:05:26 -08:00
Matt Corallo
2ae6b3fad4 Add a trivial benchmark of calculating routes on today's graph
Sadly rust upstream never really figured out the benchmark story,
and it looks like the API we use here may not be long for this
world. Luckily, we can switch to criterion with largely the same
API if that happens before upstream finishes ongoing work with the
custom test framework stuff.

Sadly, it requires fetching the current network graph, which I did
using Val's route-testing script written to test the MPP router.
2021-02-15 16:51:51 -05:00
Matt Corallo
d873e72789 Allow gossip messages to have 1KB of uninterpreted data and relay 2021-02-15 16:45:22 -05:00
Matt Corallo
35bb2d0085 Drop trailing semicolons which rustc nightly generates warnings for 2021-02-15 15:17:25 -05:00
Matt Corallo
7dbced3f28 Slightly expand documentation on KeysInterface
Specifically, this notes when methods can or can not return the
same value on each call.
2021-02-12 18:57:20 -05:00
Matt Corallo
36cc5814c1 Expand documentation and fields in SpendableOutputDescriptors
This adds a channel_value_satoshis field to
SpendableOutputDescriptors as it is required to recreate our
InMemoryChannelKeys. It also slightly expands documentation.
2021-02-12 18:57:20 -05:00
Matt Corallo
e885d0a774 Swap key_derivation_params (u64, u64) for channel_keys_id [u8; 32]
Instead of `key_derivation_params` being a rather strange type, we
call it `channel_keys_id` and give it a generic 32 byte array. This
should be much clearer for users and also more flexible.
2021-02-12 18:57:20 -05:00
Matt Corallo
8dd08bd962 Drop address ordering enforcement in NodeAnnouncement deser
It seems many other nodes never bothered to enforce these
requirements, so there's little reason that we should either.

cc https://github.com/lightningnetwork/lightning-rfc/pull/842
2021-02-12 16:43:25 -05:00
Matt Corallo
75d71cead3 Add additional Clone derives
The only API change outside of additional derives is to change
the inner field in `DecodeError::Io()` to an `std::io::ErrorKind`
instead of an `std::io::Error`. While `std::io::Error` obviously
makes more sense in context, it doesn't support Clone, and the
inner error largely doesn't have a lot of value on its own.
2021-02-10 22:34:19 -05:00
Matt Corallo
c35002fa9c
Merge pull request #787 from TheBlueMatt/2021-02-check-close-source 2021-02-10 09:09:53 -08:00
Matt Corallo
bd8382a4d3 Fix documentation on PeerHandleError 2021-02-09 19:06:00 -05:00
Matt Corallo
d3f61c0ad7 Add test for error message hangline resulting in force-close 2021-02-09 19:04:54 -05:00
Matt Corallo
61164afb2b Check the PK of the source of an error before closing chans from it
When we receive an error message from a peer, it can indicate a
channel which we should close. However, we previously did not
check that the counterparty who sends us such a message is the
counterparty with whom we have the channel, allowing any
connected peer to make us force-close any channel we have as long
as they know the channel id.

This commit simply changes the force-close logic to check that the
sender matches the channel's counterparty node_id, though as noted
in #105, we eventually need to change the indexing anyway to allow
absurdly terrible peers to open channels with us.

Found during review of #777.
2021-02-09 19:04:54 -05:00
Matt Corallo
6dcb7c4d05
Merge pull request #793 from galderz/t_double_validation_792 2021-02-05 06:17:46 -08:00
Galder Zamarreño
048e862a4b Unknown bits feature only needs to be validated once #792 2021-02-05 13:29:56 +01:00
Matt Corallo
89be6254ae
Merge pull request #790 from bmancini55/sync_complete
Interpret sync_complete in reply_channel_range
2021-02-04 09:18:52 -08:00
bmancini55
77690fada2 Interpret sync_complete in reply_channel_range
LN Spec PR #826 changes full_information to indicate completion of a
sequence of reply_channel_range messages.
2021-02-04 09:19:02 -05:00
Matt Corallo
ac078c103c [bindings] Don't require trait impl for-structs to have no generics
This (finally) exposes `ChannelManager`/`ChannelMonitor` _write
methods, which were (needlessly) excluded as the structs themselves
have generic parameters. Sadly, we also now need to parse
`(C-not exported)` doc comments on impl blocks as we otherwise try
to expose _write methods for `&Vec<RouteHop>`, which doesn't work
(and isn't particularly interesting for users anyway). We add such
doc comments there.
2021-02-03 10:11:28 -05:00
Matt Corallo
b2bf57eb82 [bindings] Don't export new functions with unexportable types
`CommitmentTransaction::new_with_auxiliary_htlc_data()` includes a
unbounded generic parameter which we can't concretize and it's of
limited immediate use for users in any case. We should eventually
add a non-generic version which uses `()` for the generic but that
can come later.

`CommitmentTransaction::htlcs()` returns a reference to a Vec,
which we cannot currently map. It should, however, be exposed to
users, so in the future we'll need to have a duplication function
which returns Vec of references or a cloned Vec.
2021-02-02 17:04:31 -05:00
Matt Corallo
70440a529e [bindings] Use consistent imports for MessageSendEvents traits
Our bindings generator is braindead with respect to the idents
used in a trait definition - it treats them as if they were used
where the trait is being used, instead of where the trait is
defined. Thus, if the idents used in a trait definition are not
also imported the same in the files where the traits are used, we
will claim the idents are bogus.

I spent some time trying to track the TypeResolvers globally
through the entire conversion run so that we could use the original
file's TypeResolver later when using the trait, but it is somewhat
of a lifetime mess. While likely possible, import consistency is
generally the case anyway, so unless it becomes more of an issue in
the future, it likely makes the most sense to just keep imports
consistent.

This commit keeps imports consistent across trait definition files
around `MessageSendEvent` and `MessageSendEventsProvider`.
2021-02-01 16:52:57 -05:00
Matt Corallo
151d4ac0a3
Merge pull request #783 from ariard/2021-01-disconnect-node-id
Add PeerManager::disconnect_node_id()
2021-02-01 11:46:40 -08:00
Antoine Riard
5b7d7ed940 Add PeerManager::disconnect_by_node_id()
This public method allows a client to easily disconnect peers while only
owning its node id. It will clean up peer state and disconnect properly
its descriptor.
2021-02-01 14:13:37 -05:00
Matt Corallo
f151c02975
Merge pull request #764 from lightning-signer/revoke-enforcement
Revocation enforcement
2021-01-25 09:06:43 -08:00
Matt Corallo
25c9a37e18
Merge pull request #777 from sr-gi/cm-force-close-checks
Makes ChannelManager::force_close_channel fail for unknown chan_ids
2021-01-25 07:25:25 -08:00
Devrandom
142b0d624e Let some tests disable revocation policy check
When simulating a bad actor that broadcasts a revoked tx, the policy check would otherwise panic.
2021-01-21 11:37:28 -08:00
Sergi Delgado Segura
821f6cdd1e
Makes ChannelManager::force_close_channel fail for unknown chan_ids
ChannelManager::force_close_channel does not fail if a non-existing channel id is being passed, making it hard to catch from an API point of view.

Makes force_close_channel return in the same way close_channel does so the user calling the method with an unknown id can be warned.
2021-01-21 16:12:57 +01:00
Devrandom
bd4345d6a2 Fix fuzzing issue with revocation 2021-01-18 17:59:43 -08:00
Devrandom
a5869b9281 Revocation enforcement in signer
We want to make sure that we don't sign revoked transactions.

Given that ChannelKeys are not singletons and revocation enforcement is stateful,
we need to store the revocation state in KeysInterface.
2021-01-18 17:59:43 -08:00
Devrandom
2cbb8358f1 Use TestKeysInterface in functional tests
This allows stateful validation in EnforcingChannelKeys
2021-01-18 11:59:39 -08:00
Devrandom
0b20cf62e7 Simplify handling of OnChainTx.holder_commitment
It is no longer optional since it is available at construction time.
2021-01-18 10:24:31 -08:00
Devrandom
63c56a4a86 Panic if signing fails in OnChainTx
Signatures in OnChainTx must not fail, or we stand to lose funds
2021-01-18 10:24:31 -08:00
Devrandom
cb83cfe366 Fold sign_holder_commitment_htlc_transactions into sign_holder_commitment
Signing the commitment transaction is almost always followed by signing the attached HTLC transactions, so fold the signing operations into a single method.
2021-01-18 10:24:31 -08:00
Matt Corallo
d529a8827b
Merge pull request #771 from jkczyz/2021-01-bolt3-test-vectors
Add BOLT 3 test vector for CLTV tiebreaker
2021-01-13 14:40:41 -08:00
Jeffrey Czyz
caa16e0fb5
Add BOLT 3 test vector for CLTV tiebreaker
The test vector was added in https://github.com/lightningnetwork/lightning-rfc/pull/539.
2021-01-08 12:48:24 -08:00
Matt Corallo
b2f1327536
Merge pull request #761 from TheBlueMatt/2020-10-chansigner-no-ser
Add a new method `read_chan_signer` to `KeysInterface`
2021-01-08 08:59:19 -08:00
Sergi Delgado Segura
ee51de9bce
Adds Copy to ChannelHandshakeConfig and UserConfig
This commits adds Copy to ChannelHandshakeConfig and UserConfig for consistency with the rest of config structs.
2021-01-05 20:20:35 +01:00
Matt Corallo
990d1de99a Use KeysInterface::read_chan_signer for all channel keys deser
This drops any direct calls to a generic `ChannelKeys::read()` and
replaces it with the new `KeysInterface::read_chan_signer()`. Still,
under the hood all of our own `KeysInterface::read_chan_signer()`
implementations simply call out to a `Readable::read()` implemention.
2021-01-04 12:40:40 -05:00
Matt Corallo
c07b4de983 Expose test_utils to fuzztarget (in addition to _test_utils feature) 2021-01-04 12:40:40 -05:00
Matt Corallo
45d4d26987 Add a new method read_chan_signer to KeysInterface
This adds a new method to the general cross-channel `KeysInterface`
which requires it to handle the deserialization of per-channel
signer objects. This allows the deserialization of per-channel
signers to have more context available, which, in the case of the
C bindings, includes the actual KeysInterface information itself.
2021-01-04 12:40:40 -05:00
Matt Corallo
0f5580afd4 Use Writeable for ChannelMonitor instead of a specific function.
There's no reason to have ChannelMonitor::write_for_disk instead of
just using the Writeable trait anymore. Previously, it was used to
differentiate with `write_for_watchtower`, but support for
watchtower-mode ChannelMonitors was never completed and the partial
bits were removed long ago.

This has the nice benefit of hitting the custom Writeable codepaths
in C bindings instead of trying to hit trait-generics paths.
2021-01-04 12:40:40 -05:00
Matt Corallo
4345aa88ae Universally Require Writeable for ChannelKeys
It doesn't make sense to ever build a lightning node which doesn't
ever write ChannelMonitors to disk, so having a ChannelKeys object
which doesn't implement Writeable is nonsense.

Here we require Writeable for all ChannelKeys objects, simplifying
code generation for C bindings somewhat.
2021-01-04 12:40:40 -05:00
Matt Corallo
c5fca8c41c Cache fields instead of storing a ChannelKeys in ChannelMonitor
We only actually use two of the fields in ChannelKeys inside a
ChannelMonitor - the holder revocation_basepoint and the
derivation parameters. Both are relatively small, so there isn't
a lot of reason to hold a full copy of the ChannelKeys (with most
of the interaction with it being inside the OnchainTxHandler).

Further, this will avoid calling read on a `ChannelKeys` twice,
which is a somewhat strange API quirk.
2021-01-04 12:37:47 -05:00
Devrandom
9291a38c70 Use new get_commitment_transaction_number_obscure_factor utility function 2020-12-30 13:40:18 -08:00
Devrandom
2de29ae049 Introduce CommitmentTransaction, ChannelTransactionParameters
CommitmentTransaction maintains the per-commitment transaction fields needed to construct the associated bitcoin transactions (commitment, HTLC).  It replaces passing around of Bitcoin transactions.  The ChannelKeys API is modified accordingly.

By regenerating the transaction when implementing a validating external signer, this allows a higher level of assurance that all relevant aspects of the transactions were checked for policy violations.

ChannelTransactionParameters replaces passing around of individual per-channel fields that are needed to construct Bitcoin transactions.

Eliminate ChannelStaticData in favor of ChannelTransactionParameters.

Use counterparty txid instead of tx in channelmonitor update.
2020-12-30 13:40:18 -08:00
Devrandom
a294a3f906 Unwrap unneeded macros 2020-12-18 15:31:51 -08:00