Commit graph

523 commits

Author SHA1 Message Date
Antoine Riard
9a23130db9 Change ChannelKeys interface nomenclature to holder/counterparty one
Transaction signing methods are changed from local_/remote_ prefix
to newer holder_/counterparty_ wihout any semantic changes.
2020-09-14 14:39:47 -04:00
Antoine Riard
b51721fc8a Underscore TxCreationKeys ownership
A TxCreationKeys set represents the key which will be embedded in output
scripts of a party's commitment tx state. Among them there is a always
a key belonging to counter-party, the HTLC pubkey. To dissociate
strongly, prefix keys with broadcaster/countersignatory.

A revocation keypair is attributed to the broadcaster as it's used
to punish a fraudulent broadcast while minding that such keypair
derivation method will be always used by countersignatory as it's
its task to enforce punishement thanks to the release secret.
2020-09-14 14:39:47 -04:00
Antoine Riard
c6a91f2ebd Change variable nomenclature for to_self_delay
To avoid reviewers confusion, rename counterparty_to_self_delay
to counteparty_selected_contest_delay, i.e the justice delay announced
by a channel counterparty restraining our transactions, and to_self_delay
to locally_selected_contest_delay, i.e the justice delay announced by us
restraining counterparty's transactions

We deviate from wider nomenclature by prefixing local data with a
locally_ extension due to the leak of this value in transactions/scripts
builder, where the confusion may happen.

Rename further AcceptChannelData to the new nomenclature.
2020-09-14 14:39:44 -04:00
Antoine Riard
c7ef6df672 Change variable nomenclature for Channel fields
Previously most of variable fields relative to data belonging to
our node or counterparty were labeled "local"/"remote". It has been
deemed confusing with regards to transaction construction which is
always done from a "local" viewpoint, even if owner is our counterparty
2020-09-14 13:16:12 -04:00
Antoine Riard
1d7c4f663c Change variable nomenclature in chan_utils
Variables should be named according to the script semantic which is
an invariant with regards to generating a local or remote commitment
transaction.

I.e a broadcaster_htlc_key will always guard a HTLC to the party able
to broadcast the computed transactions whereas countersignatory_htlc_key
will guard HTLC to a countersignatory of the commitment transaction.
2020-09-11 09:50:18 -04:00
Matt Corallo
5254d6b3d9 Add annotations for things which we cannot (yet) expose 2020-09-10 22:03:30 -04:00
Matt Corallo
bd5f2427c3 Remove a few final ::-containing paths in generic args
This cleans upa few last cases of functions/objects which our C
bindings generator doesn't know how to read.
2020-09-10 21:58:44 -04:00
Matt Corallo
25b0c2a475 Silence new rustc warning about useless muts 2020-09-10 16:32:45 -04:00
Matt Corallo
9d8efecadf Use rust-bitcoin's new SigHashCache instead of SignatureHashComp's
Thew new API is a bit harder to misuse by taking a reference to the
transaction to require the inputs match the input being signed.
2020-09-10 16:20:01 -04:00
Matt Corallo
b9707da138 Update to latest upstream rust-bitcoin 2020-09-10 16:20:01 -04:00
Matt Corallo
3defcc8962
Merge pull request #676 from TheBlueMatt/2020-08-c-bindings-cleanups-3
Pre-C-Bindings Cleanups #3
2020-08-26 08:14:34 -07:00
Matt Corallo
af69fae97b
Merge pull request #674 from TheBlueMatt/2020-08-keyif-rand-names
Simplify + clarify random-bytes-fetching from KeysInterface
2020-08-26 08:07:58 -07:00
Matt Corallo
d224c1def4 Add a C-bindings-compatible read lock type for NetworkGraph
In order to calculate a route, it is likely that users need to take
a read()-lock on NetGraphMsgHandler::network_graph. This is not
possible naively from C bindings, as Rust's native RwLock is not
exposed.

Thus, we provide a simple wrapper around the RwLockReadGuard and
expose simple accessor methods.
2020-08-25 21:26:51 -04:00
Matt Corallo
c6bae1fdb0 Rename TxCreationKeys::new to not conflict w/ auto-gen'd C bindings
The C bindings automatically create a _new() function for structs
which contain only pub fields which we know how to map. This
conflicts with the actual TxCreationKeys::new() function, so we
simply rename it to capture its nature as a derivation function.
2020-08-25 21:26:51 -04:00
Matt Corallo
2ff4ae782e Give ChannelManagerReadArgs HashMap-of-monitors ownership
Its somewhat awkward that ChannelManagerReadArgs requires a mutable
reference to a HashMap of ChannelMonitors, forcing the callsite to
define a scope for the HashMap which they almost certainly won't use
after deserializing the ChannelManager. Worse, to map the current
version to C bindings, we'd need to also create a HashMap binding,
which is overkill for just this one use.

Instead, we just give the ReadArgs struct ownership of the HashMap
and add a constructor which fills the HashMap for you.
2020-08-25 21:26:48 -04:00
Matt Corallo
6df9129ace Use ln OutPoints not bitcoin ones in SpendableOutputDescriptors
Lightning OutPoints only have 16 bits to express the output index
instead of Bitcoin's 32 bits, implying that some outputs are
possibly not expressible as lightning OutPoints. However, such
OutPoints can never be hit within the lightning protocol, and must
be on-chain spam sent by a third party wishing to donate us money.
Still, in order to do so, the third party would need to fill nearly
an entire block with garbage, so this case should be relatively
safe.

A new comment in channelmonitor explains the reasoning a bit
further.
2020-08-25 17:09:51 -04:00
Matt Corallo
de8c5dc76d Use slices to references not slices of concrete objects in pub API
Because the C bindings maps objects into new structs which contain
only a pointer to the underlying (immovable) Rust type, it cannot
create a list of Rust types which are contiguous in memory. Thus,
in order to allow C clients to call certain Rust functions, we have
to use &[&Type] not &[Type]. This commit fixes this issue for the
get_route function.
2020-08-25 17:09:51 -04:00
Matt Corallo
f65765872e Refer to return types by the trait that they're defined via
Instead of using the explicit type which is being returned, refer
to them as Self::AssociatedType, to make clear to the bindings what
type of thing is being returned.
2020-08-25 17:09:51 -04:00
Matt Corallo
bce202536d Refer to generic types by importing them instead of a super-mod.
This avoids one case the bindings generation hasn't bothered to
handle by simply importing types that are referred to.
2020-08-25 17:09:50 -04:00
Matt Corallo
a05b3fa897 Always refer to Deref types with where clauses instead of direct
This makes it a little easier to write C bindings generation as
we only have to handle one case instead of both.
2020-08-25 17:09:02 -04:00
Matt Corallo
4441a06dee Reorder struct definitions so that they are in dependency order.
There are a few cases where the upcoming C bindings don't know how
to handle something which depends on something defined later in the
file. Instead of adding another pass to the C bindings generator,
it is much simpler to just reorder structs.
2020-08-25 17:09:02 -04:00
Matt Corallo
501974db6d
Merge pull request #667 from valentinewallace/remove-channels-chanmon
Remove Channel's ChannelMonitor copy
2020-08-25 14:07:27 -07:00
Valentine Wallace
28d9036ce4
Remove Channel's ChannelMonitor copy 2020-08-25 16:37:53 -04:00
Valentine Wallace
ad18c4d853
Add commitment transaction broadcast as a ChannelMonitor event
To do this, we replace get_and_clear_pending_htlcs_updated with
get_and_clear_pending_monitor_events, and which still transmits HTLCUpdates
as before, but now also transmits a new MonitorEvent::CommitmentTxBroadcasted
event when a channel's commitment transaction is broadcasted.
2020-08-25 16:37:49 -04:00
Dominik Spicher
edeb122ce5 Refactor route tests
* Splits up the monolithic test into smaller unit tests

* Factors out helpers for graph setup

* Changes `id_to_feature_flags` to be a function, there was no
reason why it had to be a macro

* Activates a previously commented-out test that checks for
the failure case in `disable_node_test`
2020-08-25 00:50:54 +02:00
Matt Corallo
6497465762 Simplify + clarify random-bytes-fetching from KeysInterface
Due to a desire to be able to override temporary channel IDs and
onion keys, KeysInterface had two separate fetch-random-32-bytes
interfaces - an onion-key specific version which fetched 2 random
32 byte strings and a temporary-channel-id specific version.

It turns out, we never actually need to override both at once (as
creating a new channel and sending an outbound payment are always
separate top-level calls), so there's no reason to add two
functions to the interface when both really do the same thing.
2020-08-23 19:39:59 -04:00
Devrandom
500c00ae9a Make message fields public 2020-08-23 22:11:06 +02:00
Matt Corallo
d0b4f521e1
Merge pull request #669 from joemphilips/fix_capacity-is-always-zero-bug_in_list_channels
Fix bug in Channel
2020-08-13 14:06:39 -07:00
joe.miyamoto
54916db957
Fix bug in Channel
Before this commit, `fn get_inbound_outbound_available_balance_msat` always returns 0.
It is because using `cmp::min` instead of `cmp::max` .
2020-08-13 17:10:24 +09:00
Devrandom
c3a90a2d56 fix typo 2020-08-13 09:58:55 +02:00
Devrandom
fd2db4028a check the input shape in LocalCommitmentTransaction.new_missing_local_sig 2020-08-11 11:00:32 +02:00
Devrandom
f60026387e make LocalCommitmentTransaction constructor public
Allows calling of InMemoryChannelKeys methods
2020-08-11 09:23:31 +02:00
Devrandom
31b4d89cde make SimpleManyChannelMonitor.monitors public 2020-08-11 09:23:31 +02:00
Devrandom
ce0cecd50a export "unsafe_revoked_tx_signing" feature
Allows unsafe signing in dev code, such as functional testing of
justice transactions outside our crate.
2020-08-11 09:23:31 +02:00
Matt Corallo
4395b92cc8 Relicense as dual Apache-2.0 + MIT
This changes the LICENSE file and adds license headers to most files
to relicense under dual Apache-2.0 and MIT. This is helpful in that
we retain the patent grant issued under Apache-2.0-licensed work,
avoiding some sticky patent issues, while still allowing users who
are more comfortable with the simpler MIT license to use that.

See https://github.com/rust-bitcoin/rust-lightning/issues/659 for
relicensing statements from code authors.
2020-08-10 21:12:44 -04:00
Matt Corallo
093fcaba68
Merge pull request #664 from lightning-signer/tx-creation-keys
Wrap transaction creation keys
2020-08-10 13:25:03 -07:00
Devrandom
8058202c4c nit 2020-08-10 22:09:03 +02:00
Devrandom
6f635c6bc3 Expose TxCreationKeys in LocalCommitmentTransaction via a method
This makes it obvious to signer implementers that the pre-derived keys are a local cache and should not be trusted in a validating signer.
2020-08-10 20:22:01 +02:00
Devrandom
d2e6f2ac18 Make TxCreationKeys public and wrap it in PreCalculatedTxCreationKeys
Allows calling of InMemoryChannelKeys methods.

The wrapping makes it obvious to signer implementers that the pre-derived keys are a local cache and should not be trusted in a validating signer.
2020-08-10 20:21:07 +02:00
Valentine Wallace
523cab8ef7
Holding cell: if we fail to free an HTLC, fail it backwards
Plus add a test.
2020-08-08 16:32:15 -04:00
Devrandom
48d73b3264 ChannelKeys - provide to_self_delay alongside the remote channel pubkeys
In the phase 2 signer, we will construct the commitment transaction inside the signer.
In preparation, provide needed channel related data.
2020-07-29 20:43:39 +02:00
Matt Corallo
779ff6721b
Merge pull request #651 from naumenkogs/2020-06-routing-data-improvements
Routing improvements
2020-07-27 10:18:13 -07:00
Gleb Naumenko
dd0e4f4034 Check htlc_maximum_msat on channel update 2020-07-27 14:06:20 +03:00
Gleb Naumenko
3a57cfc7c6 Store channel capacity if available 2020-07-27 14:06:20 +03:00
Gleb Naumenko
8b4f6e8861 Add htlc_maximum_msat field 2020-07-27 14:06:16 +03:00
Devrandom
b19d4475cb ChannelKeys - separate commitment revocation from getting the per-commitment point
The commitment secret is sensitive - it can be used by an attacker to
steal funds if the node also signs the same transaction. Therefore,
only release the secret from ChannelKeys when we are revoking a
transaction.
2020-07-22 11:47:10 -07:00
Gleb Naumenko
a66b8017c0 Improve routing announcement test 2020-07-22 16:21:04 +03:00
Gleb Naumenko
430d57c610 Fix formatting 2020-07-22 16:21:04 +03:00
Gleb Naumenko
5309197150 Use constant for max msats 2020-07-22 16:21:04 +03:00
Gleb Naumenko
7838727a5c Update get_route comment to reflect new parameters 2020-07-22 16:20:19 +03:00