Commit graph

625 commits

Author SHA1 Message Date
Matt Corallo
2f06b53abf Switch from slice to slice-of-refs for spend_spendable_outputs
Sadly, there's just not really a practical way to map a slice of
objects in our current bindings infrastructure - either we take
ownership of the underlying objects and move them into a Vec, or we
need to leave the original objects in place and have a list of
pointers to the Rust objects. Thus, the only practical mapping is
to create a slice of references using the pointers we have.
2021-02-19 13:58:05 -05:00
Matt Corallo
de58bcf271
Merge pull request #795 from TheBlueMatt/2021-02-features-bindings
Map Features objects in bindings
2021-02-18 09:54:59 -08:00
Matt Corallo
61f5e79062 Drop a useless import and use Self in return values in Features
`Result` is in the standard prelude, so no need to ever use it.

Sadly, returning a Features<T> in the `impl Futures {}` block
will confuse our new alias-impl-printing logic, as we end up
running through the normal impl-block-printing logic as if we had
an explicit `impl ConcreteFeatures` block.
2021-02-18 12:28:25 -05:00
Matt Corallo
95d0fe99ee Rename output descriptor types for some clarity
Both Miron and Val suggested naming tweaks in their reviews, so
clarifying things some would be good.
2021-02-16 16:36:11 -05:00
Matt Corallo
8dbadd1045 Clarify docs on revocation_pubkey in DynamicP2WSHOutputDescriptor 2021-02-16 15:58:02 -05:00
Matt Corallo
0df01c140e Drop stale and cleanup TODO entries in keysinterface 2021-02-16 15:58:02 -05:00
Matt Corallo
72186db8a7 Switch to calling new KeysManager output-spending fn in tests 2021-02-16 15:58:02 -05:00
Matt Corallo
325a021903 Add util fn for creating a Transaction from spendable outputs
This adds a utility method, `KeysManager::spend_spendable_outputs`,
which constructs a Transaction from a given set of
`SpendableOutputDescriptor`s, deriving relevant keys as needed.

It also adds methods which can sign individual inputs where
channel-specific key derivation is required to
`InMemoryChannelKeys`, making it easy to sign transaction inputs
when a custom `KeysInterface` is used with `InMemoryChannelKeys`.
2021-02-16 15:58:02 -05:00
Matt Corallo
294cba45cc Add utility function to add a change output to a transaction 2021-02-16 15:58:02 -05:00
Matt Corallo
4552c3df48 Drop dup txn in test_dynamic_spendable_outputs_local_htlc_success_tx
Previously, test_dynamic_spendable_outputs_local_htlc_success_tx
called connect_block with two identical transactions, which
resulted in duplicate SpendableOutputs Events back-to-back. This
is a test issue as such a block_connected call represents an
invalid block.
2021-02-16 15:58:02 -05:00
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