Commit graph

1903 commits

Author SHA1 Message Date
Matt Corallo
c6d2697703 [bindings] Add support for mapping Write as a supertrait 2021-02-02 17:04:31 -05:00
Matt Corallo
dcfd95a700 [bindings] Handle MessageSendEventsProvider impl blocks in a util fn
Instead of having manually-written lightning-specific code in a
supertrait walk in the middle of a large function, move it to a
utility function up next to the other manually-written-impl-block
functions.
2021-02-02 17:04:31 -05:00
Matt Corallo
4edf514a05 [bindings] Always resolve supertrait types during supertrait walks
This is a rather trivial cleanup to ensure we always have the full
path when we walk supertraits even if the supertrait is specified
with only a single ident.
2021-02-02 17:04:31 -05:00
Matt Corallo
af3ad4b029 [bindings] Pass GenericTypes through to write_template_generic
With this we support types like `Result<Self::AssociatedType, ()>`.
2021-02-02 17:04:31 -05:00
Matt Corallo
3f5a287ca8 [bindings] Un-special-case returning an associated type
In the case that we return an associated type to C (ie when
implementing a trait which returns an associated type, we had to
convert the Rust-returned concrete Rust type to the C trait struct),
we had code to manually create the neccessary trait struct at the
return site.

This was special-cased in the method-body-writing function instead
of letting the type conversion logic handle it. As a result, we are
unable to do the same conversion when it appears in a different
context, for example inside of a generic like
`Result<Self::AssocType, ErrorType>`.

To solve this, we do the actual work in a
`impl From<nativeType> for CTraitStruct` implementation and then
call `into()` from within the type conversion logic.
2021-02-02 17:04:31 -05:00
Matt Corallo
086434f0c5 [bindings] Replace associated_types HashMaps with common Generics
Instead of handling associated types separately, we can just shove
them into the same generics resolution logic we use for template
types. While we should probably have some precedence logic,
aliasing type names seems like a bad idea anyway so no effort is
made to handle it.

This removes a good chunk of code and, more importantly, tees us up
for supporting `Type<Self::AssociatedType>`-style generics.
2021-02-02 17:04:31 -05:00
Matt Corallo
32abba7201 Drop spurious semicolon that new rustc complains about 2021-02-02 16:43:07 -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
ecf736a9a5 strip binaries in genbindings.sh for better size comparison 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
11f5e23357 Fix codecov by calling the new binary paths from rust 1.45
Rustc 1.45 moved the paths to test binaries, so we need to update
our CI scripts to run the correct ones under kcov.

The solution to this was pointed out by Val at
https://github.com/rust-bitcoin/rust-lightning/pull/774#issuecomment-763250623
2021-01-26 21:53:04 -05:00
Matt Corallo
07aff06f67 Bump MSRV for net-tokio to 1.45 as tokio 1.0 req very recent rustc 2021-01-26 18:37:04 -05:00
Matt Corallo
5a403bdb13 Update tokio to 1.0
This requires ensuring TcpStreams are set in nonblocking mode as
tokio doesn't handle this for us anymore, so we adapt the public
API to just accept std TcpStreams instead of an extra conversion
hop. Luckily converting them is cheap.
2021-01-26 18:37:04 -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
Matt Corallo
21a44da960
Merge pull request #770 from lightning-signer/holder-htlc-sigs
Fold sign_holder_commitment_htlc_transactions into sign_holder_commitment
2021-01-18 10:49:45 -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
b73e5fcf4c
Merge pull request #776 from valentinewallace/update-readme
Update readme
2021-01-18 10:13:11 -08:00
Matt Corallo
2ea3765b7a
Merge pull request #772 from ariard/2021-01-getting-project-context
Add GLOSSARY.md and more
2021-01-18 09:32:45 -08:00
Antoine Riard
2caf289a8b Extend Getting Started with GLOSSARY/meeting minutes in CONTRIBUTING.md 2021-01-18 11:06:57 -05:00
Antoine Riard
4205c4414b Add a GLOSSARY.md
Closes #766

Contributions by Devrandom <c1.devrandom@niftybox.net>
2021-01-18 11:05:57 -05:00
Valentine Wallace
2535695a00
Update README with RL customization details 2021-01-15 15:03:20 -05: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
Matt Corallo
aa9ecabf80
Merge pull request #769 from sr-gi/copy-trait-config
Adds Copy to ChannelHandshakeConfig and UserConfig
2021-01-08 08:48:53 -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
Matt Corallo
9c9c88147e
Merge pull request #742 from lightning-signer/tx-phase2
Introduce CommitmentTransactionInfo
2021-01-04 09:11:11 -08: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
Matt Corallo
74cd96f972
Merge pull request #736 from bmancini55/gossip_queries
Initiate gossip_queries
2020-12-15 11:17:11 -08:00
bmancini55
c026764e8d Fix comment for sync_routing_table
Corrects the comment for sync_routing_table in RoutingMessageHandler to
be less prescriptive about the implementor's actions.
2020-12-15 13:48:14 -05:00
bmancini55
e0bb63bc60 Remove should_request_full_sync from RoutingMessageHandler
This method was used to set the initial_routing_sync flag when sending
an outbound Init message to a peer. Since we are now relying on
gossip_queries instead of initial_routing_sync, synchronization can be
fully encapsulate into RoutingMessageHandler via sync_routing_table.

This commit removes should_request_full_sync from the trait
RoutingMessageHandler. The implementation is still used in
NetGraphMsgHandler and has been converted into a private method instead
of a trait function.
2020-12-14 12:52:59 -05:00
bmancini55
e742894492 Change routing table sync to use gossip_queries
This commit changes outbound routing table sync to use gossip_queries
instead of the effectively deprecated initial_routing_sync feature.

This change removes setting of initial_routing_sync in our outbound Init
message. Instead we now call sync_routing_table after receiving an Init
message from a peer. If the peer supports gossip_queries and
should_request_full_sync returns true, we initiate a full gossip_queries
sync.
2020-12-14 12:52:54 -05:00
bmancini55
7a4a29ffe0 Pass Init message to sync_routing_table method
This commit modifies sync_routing_table in RoutingMessageHandler to
accept a reference to the Init message received by the peer. This allows
the method to use the Peer's features to drive the operations of the
gossip_queries routing table sync.
2020-12-09 15:02:32 -05:00