Commit graph

1641 commits

Author SHA1 Message Date
Antoine Riard
6622ea724f Improve PermanentFailure requiremnts documentation
Sources of the failure may be multiple in case of distributed watchtower
deployment. In either case, the channel manager must return a final
update asking to its channel monitor(s) to broadcast the lastest state
available. Revocation secret must not be released for the faultive
channel.

In the future, we may return wider type of failures to take more
fine-grained processing decision (e.g if local disk failure and
redudant remote channel copy available channel may still be processed
forward).
2020-09-15 18:17:37 -04:00
Antoine Riard
e706c67bdb Add test_concurrent_monitor_claim
Watchower Alice receives block 134, broadcasts state X, rejects state Y.
Watchtower Bob accepts state Y, receives blocks 135, broadcasts state Y.
State Y confirms onchain. Alice must be able to claim outputs.
2020-09-15 18:17:37 -04:00
Antoine Riard
e73036c684 Implement concurrent broadcast tolerance for distributed watchtowers
With a distrbuted watchtowers deployment, where each monitor is plugged
to its own chain view, there is no guarantee that block are going to be
seen in same order. Watchtower may diverge in their acceptance of a
submitted `commitment_signed` update due to a block timing-out a HTLC
and provoking a subset but yet not seen by the other watchtower subset.
Any update reject by one of the watchtower must block offchain coordinator
to move channel state forward and release revocation secret for previous
state.

In this case, we want any watchtower from the rejection subset to still
be able to claim outputs if the concurrent state, has accepted by the
other subset, is confirming. This improve overall watchtower system
fault-tolerance.

This change stores local commitment transaction unconditionally and fail
the update if there is knowledge of an already signed commitment
transaction (ChannelMonitor.local_tx_signed=true).
2020-09-15 18:17:35 -04:00
Matt Corallo
343aacc50c
Merge pull request #684 from bmancini55/gossip_queries
Adding gossip_queries messages and serializations
2020-09-14 13:45:12 -07:00
bmancini55
10e818ac53 Adding fuzzers for gossip_queries messages
This commit adds ser/deser fuzzers for five new structs in ln::msgs used
for gossip_queries.
2020-09-14 16:19:32 -04:00
bmancini55
5ba4560be9 Adding gossip_queries message structs and serialization
This adds the message structs and implements Readable and Writeable
traits for the standard gossip_queries messages.
2020-09-14 16:19:23 -04:00
Matt Corallo
d5912ec75f
Merge pull request #633 from ariard/2020-05-rename-keys-var
Rename a's keys as local's keys and b's keys as remote's keys
2020-09-14 12:49:56 -07:00
Antoine Riard
21d0a955ef Cleanup locally-selected-delay
Comment meaning of holder/counterparty

Diverse chan_utils cleanups

Cleanups post-cbindings merge

Fix misusage of holder_selected_contest_delay instead of counterparty
_selected_contest_delay in HolderCommitmentTransaction

Fix old payment_point comment
2020-09-14 15:19:06 -04:00
Antoine Riard
6133498ca1 Overhaul LocalCommitmentTx to new nomenclature 2020-09-14 14:39:47 -04:00
Antoine Riard
00d063df5c Overhaul ChannelMonitor/OnchainTxHandler to new nomenclature 2020-09-14 14:39:47 -04:00
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
Matt Corallo
baa58c18b0
Merge pull request #688 from TheBlueMatt/2020-09-dev-docs
Add developer guideline notes for C/C++ bindings generation
2020-09-13 18:26:16 -07:00
Matt Corallo
3fa054887b Add a few more things to gitignore for bindings 2020-09-13 20:58:50 -04:00
Matt Corallo
dce831ed20 Rename lightning C/C++ bindings library to libldk
This should fix #689.
2020-09-13 20:58:50 -04:00
Matt Corallo
53182a8cec Note that genbindings.sh is really also a test script. 2020-09-13 20:58:50 -04:00
Matt Corallo
dbf4f58987 Remove the bindings crate from the root namespace to let it break
Until we get the bindings generation process super stable, let the
bindings get stale with respect to the main repo while still letting
`cargo check` pass.
2020-09-13 20:58:50 -04:00
Matt Corallo
83322e1c0d Add developer guideline notes for C/C++ bindings generation 2020-09-11 19:33:29 -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
253af8dd61
Merge pull request #618 from TheBlueMatt/2020-05-sample-c-bindings
C/C++ Bindings
2020-09-10 19:23:39 -07:00
Matt Corallo
0ab7f90578 Use Debian experimental in CI to match LLVM between rustc and clang 2020-09-10 22:03:32 -04:00
Matt Corallo
3c12b0d0af Specify panic = abort in profiles for lightning-c-bindings 2020-09-10 22:03:32 -04:00
Matt Corallo
9e03087d6a Apply -O1 only to tests, not all dev (which is used for bindings) 2020-09-10 22:03:32 -04:00
Matt Corallo
4f6f34fa30 Add bindings README 2020-09-10 22:03:32 -04:00
Matt Corallo
9f0fa04f62 Add CI run for bindings generation (though we'll allow it to fail) 2020-09-10 22:03:32 -04:00
Matt Corallo
af9d1cf776 LTO in release mode by default, which is really critical for C libs 2020-09-10 22:03:32 -04:00
Matt Corallo
76eaa61725 Update the root Cargo.toml to point to the new subcrate 2020-09-10 22:03:32 -04:00
Matt Corallo
96b2927a9a Add automatically generated C/C++ wrapper bindings 2020-09-10 22:03:32 -04:00
Matt Corallo
1af8a464b4 Add all the manually-generated bits for the c-bindings crate
Including:
 * A script to automatically generate all the rest,
 * Cargo.toml and cbindgen.toml,
 * manually-written wrapper types for a few types
2020-09-10 22:03:32 -04:00
Matt Corallo
5254d6b3d9 Add annotations for things which we cannot (yet) expose 2020-09-10 22:03:30 -04:00
Matt Corallo
48e8678a9a Add tool to read a Rust crate and generate C-compatible wrappers
In general, it maps:
 * Traits to a struct with a void* and a list of function pointers,
   emulating what the compiler will do for a dyn trait anyway,
 * Structs as a struct with a single opaque pointer to the
   underlying type and a flag to indicate ownership. While this is
   a bit less effecient than just a direct pointer, it neatly lets
   us expose in the public interface the concept of ownership by
   setting a flag in the generated struct.
 * Unit enums as enums with each type copied over and conversion
   functions,
 * Non-unit enums have each field converted back and forth with a
   type flag and a union across all the C-mapped fields.
2020-09-10 21:58:44 -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
2dd8b3e896
Merge pull request #686 from TheBlueMatt/2020-09-bump-deps
Bump rust-bitcoin and friends
2020-09-10 15:11:30 -07: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