]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
3 years agoDon't print file paths in fuzz logger as they can be very long
Matt Corallo [Fri, 18 Jun 2021 20:21:42 +0000 (20:21 +0000)]
Don't print file paths in fuzz logger as they can be very long

3 years agoMerge pull request #957 from TheBlueMatt/2021-06-p2p-no-deadlock
Matt Corallo [Wed, 23 Jun 2021 01:34:55 +0000 (01:34 +0000)]
Merge pull request #957 from TheBlueMatt/2021-06-p2p-no-deadlock

Fix P2P Deadlocks

3 years agoClean up docs on peer_handler significantly. 2021-06-p2p-no-deadlock
Matt Corallo [Thu, 17 Jun 2021 22:54:46 +0000 (22:54 +0000)]
Clean up docs on peer_handler significantly.

There are various typo and grammatical fixes here, as well as
concrete updates to correctness.

3 years agoNo longer block disconnect_socket calls in lightning-net-tokio
Matt Corallo [Thu, 17 Jun 2021 22:54:06 +0000 (22:54 +0000)]
No longer block disconnect_socket calls in lightning-net-tokio

See the previous commit for more information.

3 years agoDo not require that no calls are made post-disconnect_socket
Matt Corallo [Thu, 17 Jun 2021 22:30:09 +0000 (22:30 +0000)]
Do not require that no calls are made post-disconnect_socket

The only practical way to meet this requirement is to block
disconnect_socket until any pending events are fully processed,
leading to this trivial deadlock:

 * Thread 1: select() woken up due to a read event
 * Thread 2: Event processing causes a disconnect_socket call to
             fire while the PeerManager lock is held.
 * Thread 2: disconnect_socket blocks until the read event in
             thread 1 completes.
 * Thread 1: bytes are read from the socket and
             PeerManager::read_event is called, waiting on the lock
             still held by thread 2.

There isn't a trivial way to address this deadlock without simply
making the final read_event call return immediately, which we do
here. This also implies that users can freely call event methods
after disconnect_socket, but only so far as the socket descriptor
is different from any later socket descriptor (ie until the file
descriptor is re-used).

3 years agoMerge pull request #948 from TheBlueMatt/2021-06-p2p-fixes
Matt Corallo [Mon, 21 Jun 2021 20:23:39 +0000 (20:23 +0000)]
Merge pull request #948 from TheBlueMatt/2021-06-p2p-fixes

Clean up message forwarding and relay gossip messages

3 years ago[peer_handler] Drop unused return from get_peer_for_forwarding!() 2021-06-p2p-fixes
Matt Corallo [Mon, 21 Jun 2021 18:48:51 +0000 (18:48 +0000)]
[peer_handler] Drop unused return from get_peer_for_forwarding!()

This avoids a now-unnecessary SocketDescriptor clone() call in
addition to cleaning up the callsite code somewhat.

3 years agoSomewhat simplify message handling error mapping in peer_handler
Matt Corallo [Thu, 17 Jun 2021 15:31:05 +0000 (15:31 +0000)]
Somewhat simplify message handling error mapping in peer_handler

3 years agoDrop peers_needing_send tracking and try to write for each peer
Matt Corallo [Thu, 10 Jun 2021 18:46:24 +0000 (18:46 +0000)]
Drop peers_needing_send tracking and try to write for each peer

We do a lot of work to track which peers have buffers which need
to be flushed, when we could instead just try to flush ever peer's
buffer.

3 years agoSkip forwarding gossip messages to peers if their buffer is over-full
Matt Corallo [Thu, 10 Jun 2021 18:26:57 +0000 (18:26 +0000)]
Skip forwarding gossip messages to peers if their buffer is over-full

3 years agoForward gossip msgs
Matt Corallo [Thu, 10 Jun 2021 18:20:16 +0000 (18:20 +0000)]
Forward gossip msgs

3 years agoRefactor message broadcasting out into a utility method
Matt Corallo [Thu, 10 Jun 2021 18:48:59 +0000 (18:48 +0000)]
Refactor message broadcasting out into a utility method

This will allow us to broadcast messages received in the next
commit.

3 years agoFix bogus reentrancy from read_event -> do_attempt_write_data
Matt Corallo [Wed, 16 Jun 2021 18:57:21 +0000 (18:57 +0000)]
Fix bogus reentrancy from read_event -> do_attempt_write_data

`Julian Knutsen <julianknutsen@users.noreply.github.com>` pointed
out in a previous discussion that `read_event` can reenter user
code despite the documentation stating explicitly that it will not.

This was addressed in #456 by simply codifying the reentrancy, but
its somewhat simpler to just drop the `do_attempt_write_data` call.

Ideally we could land most of Julian's work, but its still in need
of substantial git history cleanup to get it in a reviewable state
and this solves the immediate issue.

3 years agoDrop unused "peer gone" handling in get_peer_for_forwarding!()
Matt Corallo [Thu, 10 Jun 2021 16:26:33 +0000 (16:26 +0000)]
Drop unused "peer gone" handling in get_peer_for_forwarding!()

We can never assume that messages were reliably delivered whether
we placed them in the socket or not, so there isn't a lot of use in
explicitly handling the case that a peer was not connected when we
went to send it a message.

Two TODOs are left for the generation of a `FundingAbandoned` (or
similar) event, though it ultimately belongs in `ChannelManager`.

3 years agoMerge pull request #947 from GeneFerneau/hash
Matt Corallo [Sun, 20 Jun 2021 02:20:19 +0000 (02:20 +0000)]
Merge pull request #947 from GeneFerneau/hash

Use hashbrown replacements for std equivalents

3 years agoUse hashbrown replacements for std equivalents
Gene Ferneau [Thu, 27 May 2021 04:04:20 +0000 (04:04 +0000)]
Use hashbrown replacements for std equivalents

3 years agoMerge pull request #956 from jkczyz/2021-06-validate-pub
Matt Corallo [Fri, 18 Jun 2021 18:06:45 +0000 (18:06 +0000)]
Merge pull request #956 from jkczyz/2021-06-validate-pub

Increase poll::Validate visibility to pub

3 years agoMerge pull request #955 from TheBlueMatt/2021-06-rustc-bugz
Matt Corallo [Fri, 18 Jun 2021 15:24:21 +0000 (15:24 +0000)]
Merge pull request #955 from TheBlueMatt/2021-06-rustc-bugz

Fix trivial doc warnings and make CI use old rustc

3 years agoRemove unnecessary spaces
Jeffrey Czyz [Thu, 17 Jun 2021 18:55:11 +0000 (13:55 -0500)]
Remove unnecessary spaces

3 years agoIncrease poll::Validate visibility to pub
Jeffrey Czyz [Thu, 17 Jun 2021 18:40:52 +0000 (13:40 -0500)]
Increase poll::Validate visibility to pub

Previously, poll::Validate was pub(crate) to force external implementors
of Poll to define their implementation in terms of ChainPoller. This was
because ChainPoller::look_up_previous_header checks for consistency
between headers and any errors would be checked at that level rather
than by the caller. Otherwise, if performed by the caller, a Poll
implementation would not be aware if the underlying BlockSource was
providing bad data and therefore couldn't react accordingly.

Widening the visibility to pub relaxes this requirement, although it's
still encourage to use ChainPoller to implement Poll. This permits
either copying or moving lightning-block-sync's test utilities to a
separate crate since they use poll::Validate.

3 years agoClarify invoice comment noting the relevant final-cltv-expiry vals 2021-06-rustc-bugz
Matt Corallo [Thu, 17 Jun 2021 20:15:39 +0000 (20:15 +0000)]
Clarify invoice comment noting the relevant final-cltv-expiry vals

3 years agoMake links in message signing docs rustdoc links
Matt Corallo [Thu, 17 Jun 2021 15:49:17 +0000 (15:49 +0000)]
Make links in message signing docs rustdoc links

Latest rustc warns that "this URL is not a hyperlink" and notes that
"bare URLs are not automatically turned into clickable links". This
resolves those warnings.

Thanks to Joshua Nelson for pointing out the correct syntax for
this.

3 years agoExpose doc-linked constants in lightning-invoice
Matt Corallo [Thu, 17 Jun 2021 15:48:20 +0000 (15:48 +0000)]
Expose doc-linked constants in lightning-invoice

These constants are generally useful, and are linked from
documentation, so should be exposed in any case.

3 years agoOnly check docs on rustc 1.52 as rustc stable now crashes
Matt Corallo [Thu, 17 Jun 2021 15:41:16 +0000 (15:41 +0000)]
Only check docs on rustc 1.52 as rustc stable now crashes

3 years agoMerge pull request #944 from TheBlueMatt/2021-06-0.0.99 v0.0.98
Matt Corallo [Fri, 11 Jun 2021 17:02:11 +0000 (17:02 +0000)]
Merge pull request #944 from TheBlueMatt/2021-06-0.0.99

0.0.98

3 years agoMerge pull request #946 from jkczyz/2021-06-get-route-interface
Matt Corallo [Fri, 11 Jun 2021 16:51:48 +0000 (16:51 +0000)]
Merge pull request #946 from jkczyz/2021-06-get-route-interface

Align get_route's interface with ChannelManager and Invoice

3 years agoFix type name in docs
Jeffrey Czyz [Thu, 10 Jun 2021 02:25:40 +0000 (19:25 -0700)]
Fix type name in docs

3 years agoAccept multi-hop route hints in get_route
Jeffrey Czyz [Thu, 10 Jun 2021 22:49:14 +0000 (15:49 -0700)]
Accept multi-hop route hints in get_route

Lightning invoices allow for zero or more multi-hop route hints. Update
get_route's interface to accept such hints, although only the last hop
from each is used for the time being.

Moves RouteHint from lightning-invoice crate to lightning crate. Adds a
PrivateRoute wrapper around RouteHint for use in lightning-invoice.

3 years agoAdd find_all_extract macro to lightning-invoice
Jeffrey Czyz [Thu, 10 Jun 2021 19:29:55 +0000 (12:29 -0700)]
Add find_all_extract macro to lightning-invoice

Used for extracting more than one field of the same type.

3 years agoBump versions to 0.0.98, lightning-invoice to 0.6.0 2021-06-0.0.99
Matt Corallo [Tue, 8 Jun 2021 21:07:38 +0000 (21:07 +0000)]
Bump versions to 0.0.98, lightning-invoice to 0.6.0

3 years agoMerge pull request #940 from TheBlueMatt/2021-06-fix-docs
Matt Corallo [Tue, 8 Jun 2021 02:28:46 +0000 (02:28 +0000)]
Merge pull request #940 from TheBlueMatt/2021-06-fix-docs

Clean up docs on public chan_utils methods to be more useful

3 years agoMerge pull request #936 from TheBlueMatt/2021-05-spendable-event-locktime-delay
Matt Corallo [Tue, 8 Jun 2021 01:53:03 +0000 (01:53 +0000)]
Merge pull request #936 from TheBlueMatt/2021-05-spendable-event-locktime-delay

Delay DelayedPaymentOutput spendable events until the CSV delay

3 years agoMerge pull request #943 from lightning-signer/2021-06-signet
Matt Corallo [Tue, 8 Jun 2021 01:52:38 +0000 (01:52 +0000)]
Merge pull request #943 from lightning-signer/2021-06-signet

Add proper signet support for invoices

3 years agoClean up docs on public chan_utils methods to be more useful 2021-06-fix-docs
Matt Corallo [Mon, 7 Jun 2021 01:41:51 +0000 (01:41 +0000)]
Clean up docs on public chan_utils methods to be more useful

3 years agoMerge pull request #939 from TheBlueMatt/2021-05-derives
Matt Corallo [Tue, 8 Jun 2021 01:51:41 +0000 (01:51 +0000)]
Merge pull request #939 from TheBlueMatt/2021-05-derives

Add additional derives for a few structs

3 years agoMerge pull request #942 from lightning-signer/2021-06-accept-channel-reserve-dust
Matt Corallo [Mon, 7 Jun 2021 22:03:11 +0000 (22:03 +0000)]
Merge pull request #942 from lightning-signer/2021-06-accept-channel-reserve-dust

Remove unwanted check in accept_channel

3 years agoAdd proper signet support for invoices
Devrandom [Mon, 7 Jun 2021 14:29:39 +0000 (16:29 +0200)]
Add proper signet support for invoices

3 years agoRemove unwanted check in accept_channel
Devrandom [Mon, 7 Jun 2021 14:22:07 +0000 (16:22 +0200)]
Remove unwanted check in accept_channel

This caused an interoperability issue with lnd, because they can propose a reserve lower than their dust limit (but not lower than ours).

3 years agoAdd additional derives for a few structs 2021-05-derives
Matt Corallo [Wed, 2 Jun 2021 16:20:31 +0000 (16:20 +0000)]
Add additional derives for a few structs

3 years agoDelay DelayedPaymentOutput spendable events until the CSV delay 2021-05-spendable-event-locktime-delay
Matt Corallo [Mon, 31 May 2021 20:04:36 +0000 (20:04 +0000)]
Delay DelayedPaymentOutput spendable events until the CSV delay

3 years agoMerge pull request #935 from TheBlueMatt/2021-05-enum-tlvs
Matt Corallo [Tue, 1 Jun 2021 21:53:15 +0000 (21:53 +0000)]
Merge pull request #935 from TheBlueMatt/2021-05-enum-tlvs

TLV-ize enum serialization and a few additional structs

3 years agoUpdate network graph sample used in benchmarks
Matt Corallo [Tue, 1 Jun 2021 02:02:40 +0000 (02:02 +0000)]
Update network graph sample used in benchmarks

3 years agoConvert SpendableOutputDescriptor to new TLV-based serialization
Matt Corallo [Mon, 31 May 2021 18:39:11 +0000 (18:39 +0000)]
Convert SpendableOutputDescriptor to new TLV-based serialization

3 years agoClean up ChannelMonitor object serialization to use TLVs/versions
Matt Corallo [Mon, 31 May 2021 16:48:20 +0000 (16:48 +0000)]
Clean up ChannelMonitor object serialization to use TLVs/versions

3 years agoUse TLVs inside of serialization of Event variants
Matt Corallo [Mon, 31 May 2021 16:46:34 +0000 (16:46 +0000)]
Use TLVs inside of serialization of Event variants

3 years agoConvert remaining channel inner structs and enums to TLV-based ser
Matt Corallo [Mon, 31 May 2021 16:44:59 +0000 (16:44 +0000)]
Convert remaining channel inner structs and enums to TLV-based ser

3 years agoConvert most chain::* inner structs and enums to TLV-based ser macros
Matt Corallo [Mon, 31 May 2021 16:41:02 +0000 (16:41 +0000)]
Convert most chain::* inner structs and enums to TLV-based ser macros

3 years agoAdd generic serialization implementations for Boxs and 3-tuples
Matt Corallo [Sun, 30 May 2021 23:47:52 +0000 (23:47 +0000)]
Add generic serialization implementations for Boxs and 3-tuples

These are used in the next commit(s).

3 years agoUse TLV instead of explicit length for VecReadWrapper termination
Matt Corallo [Sun, 30 May 2021 23:24:43 +0000 (23:24 +0000)]
Use TLV instead of explicit length for VecReadWrapper termination

VecReadWrapper is only used in TLVs so there is no need to prepend
a length before writing/reading the objects - we can instead simply
read until we reach the end of the TLV stream.

3 years agoAdd a macro to implement serialization of enums using TLVs
Matt Corallo [Sun, 30 May 2021 22:27:37 +0000 (22:27 +0000)]
Add a macro to implement serialization of enums using TLVs

3 years agoMerge pull request #938 from lightning-signer/2020-06-test-background
Matt Corallo [Tue, 1 Jun 2021 17:32:29 +0000 (17:32 +0000)]
Merge pull request #938 from lightning-signer/2020-06-test-background

Expose test_process_background_events

3 years agoExpose test_process_background_events
Devrandom [Tue, 1 Jun 2021 16:54:30 +0000 (18:54 +0200)]
Expose test_process_background_events

3 years agoGive OnchainEvent::HTLCUpdate individual fields instead of a pair
Matt Corallo [Sun, 30 May 2021 20:44:26 +0000 (20:44 +0000)]
Give OnchainEvent::HTLCUpdate individual fields instead of a pair

3 years agoMerge pull request #933 from TheBlueMatt/2021-05-ser-fast
Matt Corallo [Tue, 1 Jun 2021 16:11:24 +0000 (16:11 +0000)]
Merge pull request #933 from TheBlueMatt/2021-05-ser-fast

Speed up deserialization of secp256k1 objects significantly

3 years agoAdd additional inline hints in serialization methods 2021-05-ser-fast
Matt Corallo [Fri, 28 May 2021 14:07:39 +0000 (14:07 +0000)]
Add additional inline hints in serialization methods

This substantially improves deserialization performance when LLVM
decides not to inline many short methods, eg when not building
with LTO/codegen-units=1.

Even with the default bench params of LTO/codegen-units=1, the
serialization benchmarks on an Intel 2687W v3 take:

test routing::network_graph::benches::read_network_graph  ... bench: 1,955,616,225 ns/iter (+/- 4,135,777)
test routing::network_graph::benches::write_network_graph ... bench: 165,905,275 ns/iter (+/- 118,798)

3 years agoImpl `serialized_length()` without `LengthCalculatingWriter`
Matt Corallo [Sat, 29 May 2021 18:32:53 +0000 (18:32 +0000)]
Impl `serialized_length()` without `LengthCalculatingWriter`

With the new `serialized_length()` method potentially being
significantly more efficient than `LengthCalculatingWriter`, this
commit ensures we call `serialized_length()` when calculating
length of a larger struct.

Specifically, prior to this commit a call to
`serialized_length()` on a large object serialized with
`impl_writeable`, `impl_writeable_len_match`, or
`encode_varint_length_prefixed_tlv` (and
`impl_writeable_tlv_based`) would always serialize all inner fields
of that object using `LengthCalculatingWriter`. This would ignore
any `serialized_length()` overrides by inner fields. Instead, we
override `serialized_length()` on all of the above by calculating
the serialized size using calls to `serialized_length()` on inner
fields.

Further, writes to `LengthCalculatingWriter` should never fail as
its `write` method never returns an error. Thus, any write failures
indicate a bug in an object's write method or in our
object-creation sanity checking. We `.expect()` such write calls
here.

As of this commit, on an Intel 2687W v3, the serialization
benchmarks take:

test routing::network_graph::benches::read_network_graph  ... bench: 2,039,451,296 ns/iter (+/- 4,329,821)
test routing::network_graph::benches::write_network_graph ... bench: 166,685,412 ns/iter (+/- 352,537)

3 years agoAvoid calling libsecp serialization fns when calculating length
Matt Corallo [Sat, 29 May 2021 18:24:16 +0000 (18:24 +0000)]
Avoid calling libsecp serialization fns when calculating length

When writing out libsecp256k1 objects during serialization in a
TLV, we potentially calculate the TLV length twice before
performing the actual serialization (once when calculating the
total TLV-stream length and once when calculating the length of the
secp256k1-object-containing TLV). Because the lengths of secp256k1
objects is a constant, we'd ideally like LLVM to entirely optimize
out those calls and simply know the expected length. However,
without cross-language LTO, there is no way for LLVM to verify that
there are no side-effects of the calls to libsecp256k1, leaving
LLVM with no way to optimize them out.

This commit adds a new method to `Writeable` which returns the
length of an object once serialized. It is implemented by default
using `LengthCalculatingWriter` (which LLVM generally optimizes out
for Rust objects) and overrides it for libsecp256k1 objects.

As of this commit, on an Intel 2687W v3, the serialization
benchmarks take:

test routing::network_graph::benches::read_network_graph  ... bench: 2,035,402,164 ns/iter (+/- 1,855,357)
test routing::network_graph::benches::write_network_graph ... bench: 308,235,267 ns/iter (+/- 140,202)

3 years agoDrop byte_utils in favor of native `to/from_be_bytes` methods
Matt Corallo [Fri, 28 May 2021 01:40:22 +0000 (01:40 +0000)]
Drop byte_utils in favor of native `to/from_be_bytes` methods

Now that our MSRV supports the native methods, we have no need
for the helpers anymore. Because LLVM was already matching our
byte_utils methods as byteswap functions, this should have no
impact on generated (optimzied) code.

This removes most of the byte_utils usage, though some remains to
keep the patch size reasonable.

3 years agoAdd bench profiles to Cargo.toml to force codegen-units=1
Matt Corallo [Fri, 28 May 2021 14:16:20 +0000 (14:16 +0000)]
Add bench profiles to Cargo.toml to force codegen-units=1

This makes a small difference for NetworkGraph deserialization
as it enables more inlining across different files, hopefully
better matching user performance as well.

As of this commit, on an Intel 2687W v3, the serialization
benchmarks take:

test routing::network_graph::benches::read_network_graph  ... bench: 2,037,875,071 ns/iter (+/- 760,370)
test routing::network_graph::benches::write_network_graph ... bench: 320,561,557 ns/iter (+/- 176,343)

3 years agoAdd benchmark of deserializing a NetworkGraph.
Matt Corallo [Fri, 28 May 2021 00:47:11 +0000 (00:47 +0000)]
Add benchmark of deserializing a NetworkGraph.

NetworkGraph is one of the largest structures we generally
deserialize, so it makes for a good benchmark, even if it isn't the
most complicated one.

As of this commit, on an Intel 2687W v3, these benchmarks take:

test routing::network_graph::benches::read_network_graph  ... bench: 2,101,420,078 ns/iter (+/- 6,649,020)
test routing::network_graph::benches::write_network_graph ... bench: 344,696,835 ns/iter (+/- 229,061)

3 years agoMerge pull request #892 from TheBlueMatt/2021-04-fix-htlc-ser
Matt Corallo [Mon, 31 May 2021 23:52:22 +0000 (23:52 +0000)]
Merge pull request #892 from TheBlueMatt/2021-04-fix-htlc-ser

Correct Channel outbound HTLC serialization and expand fuzzing coverage

3 years agoMerge pull request #934 from TheBlueMatt/2021-05-new-tag
Matt Corallo [Mon, 31 May 2021 20:35:16 +0000 (20:35 +0000)]
Merge pull request #934 from TheBlueMatt/2021-05-new-tag

Add new `(C-not implementable)` tag on `EventsProvider`

3 years agoCorrect Channel outbound HTLC serialization 2021-04-fix-htlc-ser
Matt Corallo [Wed, 21 Apr 2021 20:47:24 +0000 (20:47 +0000)]
Correct Channel outbound HTLC serialization

Channel serialization should happen "as if
remove_uncommitted_htlcs_and_mark_paused had just been called".

This is true for the most part, but outbound RemoteRemoved HTLCs
were being serialized as normal, even though
`remote_uncommitted_htlcs_and_mark_paused` resets them to
`Committed`.

This led to a bug identified by the `chanmon_consistency_target`
fuzzer wherein, if we receive a update_*_htlc message bug not the
corresponding commitment_signed prior to a serialization roundtrip,
we'd force-close the channel due to the peer "attempting to
fail/claim an HTLC which was already failed/claimed".

3 years ago[fuzz] Expand chanmon_consistency to do single message delivery
Matt Corallo [Wed, 21 Apr 2021 17:03:57 +0000 (17:03 +0000)]
[fuzz] Expand chanmon_consistency to do single message delivery

While trying to debug the issue ultimately tracked down to a
`PeerHandler` locking bug in #891, the ability to deliver only
individual messages at a time in chanmon_consistency looked
important. Specifically, it initially appeared there may be a race
when an update_add_htlc was delivered, then a node sent a payment,
and only after that, the corresponding commitment-signed was
delivered.

This commit adds such an ability, greatly expanding the potential
for chanmon_consistency to identify channel state machine bugs.

3 years ago[fuzz] Fix hang due to double-lock in full_stack_target
Matt Corallo [Wed, 21 Apr 2021 01:35:12 +0000 (01:35 +0000)]
[fuzz] Fix hang due to double-lock in full_stack_target

3 years ago[fuzz] Do not fail in FST if a channel is closed before we fund it
Matt Corallo [Wed, 21 Apr 2021 00:35:23 +0000 (00:35 +0000)]
[fuzz] Do not fail in FST if a channel is closed before we fund it

3 years agoMerge pull request #931 from jkczyz/2021-05-http-client-reconnect
Matt Corallo [Mon, 31 May 2021 18:05:45 +0000 (18:05 +0000)]
Merge pull request #931 from jkczyz/2021-05-http-client-reconnect

Cache socket address in HttpClient for reconnect

3 years agoAdd new `(C-not implementable)` tag on `EventsProvider` 2021-05-new-tag
Matt Corallo [Sun, 30 May 2021 17:04:21 +0000 (17:04 +0000)]
Add new `(C-not implementable)` tag on `EventsProvider`

This makes it so that users cannot usefully implement their own
`EventsProvider`, which would require substantial new logic in the
bindings generator (for generic methods). In the case of
`EventsProvider`, because there are no Rust methods which accept an
`EventsProvider` as an argument, this is perfectly OK as the
generated code would be entirely unused anyway.

3 years agoMerge pull request #932 from TheBlueMatt/2021-05-broadcast-locktime-delay
Matt Corallo [Sat, 29 May 2021 02:07:33 +0000 (02:07 +0000)]
Merge pull request #932 from TheBlueMatt/2021-05-broadcast-locktime-delay

Broadcast transactions only after their timelock is up

3 years agopanic if locktime is violated when broadcasting in tests 2021-05-broadcast-locktime-delay
Matt Corallo [Wed, 26 May 2021 20:02:30 +0000 (20:02 +0000)]
panic if locktime is violated when broadcasting in tests

3 years agoDont broadcast HTLC-Timeouts when closing a channel until locktime
Matt Corallo [Wed, 26 May 2021 19:58:59 +0000 (19:58 +0000)]
Dont broadcast HTLC-Timeouts when closing a channel until locktime

3 years agoSkip transactions which are locktime'd when broadcasting in test
Matt Corallo [Wed, 26 May 2021 19:59:35 +0000 (19:59 +0000)]
Skip transactions which are locktime'd when broadcasting in test

3 years agoTrack the blocks a node has connected in the TestBroadcaster
Matt Corallo [Wed, 26 May 2021 19:05:00 +0000 (19:05 +0000)]
Track the blocks a node has connected in the TestBroadcaster

3 years agoDelay broadcast of PackageTemplate packages until their locktime
Matt Corallo [Wed, 19 May 2021 21:47:42 +0000 (21:47 +0000)]
Delay broadcast of PackageTemplate packages until their locktime

This stores transaction templates temporarily until their locktime
is reached, avoiding broadcasting (or RBF bumping) transactions
prior to their locktime. For those broadcasting transactions
(potentially indirectly) via Bitcoin Core RPC, this ensures no
automated rebroadcast of transactions on the client side is
required to get transactions confirmed.

3 years agoAlways pass height to OnchainTxHandler::update_claims_view
Matt Corallo [Wed, 19 May 2021 21:47:30 +0000 (21:47 +0000)]
Always pass height to OnchainTxHandler::update_claims_view

This simplifies logic somewhat and avoids duplicating the storage
of the current height in OnchainTxHandler.

3 years agoExpose the timelock of transaction packages
Matt Corallo [Fri, 21 May 2021 21:02:03 +0000 (21:02 +0000)]
Expose the timelock of transaction packages

3 years agoSimplify tx checks in functional tests to make later commits simpler
Matt Corallo [Sun, 23 May 2021 21:11:21 +0000 (21:11 +0000)]
Simplify tx checks in functional tests to make later commits simpler

This cleans up some of the transaction format verification and docs
to make it easier when we delay CLTV-locked transactions to update
the tests.

3 years agoSimplify HolderHTLCOutput constructor and track CLTV expiry
Matt Corallo [Wed, 26 May 2021 17:17:29 +0000 (17:17 +0000)]
Simplify HolderHTLCOutput constructor and track CLTV expiry

This allows us to interrogate a PackageTemplate for the CLTV
timelock of the resulting transaction.

3 years agoAdd assertions to ensure we don't use an invalid package_amount
Matt Corallo [Wed, 26 May 2021 15:47:29 +0000 (15:47 +0000)]
Add assertions to ensure we don't use an invalid package_amount

This somewhat cleans up the public API of PackageSolvingData to
make it harder to get an invalid amount and use it, adding further
debug assertion to check it at test-time.

3 years agoMerge pull request #928 from TheBlueMatt/2021-05-really-tlv-ser
Matt Corallo [Thu, 27 May 2021 23:05:47 +0000 (23:05 +0000)]
Merge pull request #928 from TheBlueMatt/2021-05-really-tlv-ser

Migrate some inner structs to TLVs

3 years agoUpdate net_graph used for benchmarks to use new ser format. 2021-05-really-tlv-ser
Matt Corallo [Thu, 27 May 2021 00:12:30 +0000 (00:12 +0000)]
Update net_graph used for benchmarks to use new ser format.

3 years agoMigrate packages sub-fields to TLV serialization
Matt Corallo [Thu, 27 May 2021 19:19:47 +0000 (19:19 +0000)]
Migrate packages sub-fields to TLV serialization

3 years agoUse TLV serialization for Commitment transaction structures
Matt Corallo [Thu, 27 May 2021 19:19:54 +0000 (19:19 +0000)]
Use TLV serialization for Commitment transaction structures

3 years agoAdd TLV suffix to PackageTemplate
Matt Corallo [Wed, 26 May 2021 03:06:12 +0000 (03:06 +0000)]
Add TLV suffix to PackageTemplate

3 years agoMove NetworkGraph inner structs to TLV storage
Matt Corallo [Tue, 25 May 2021 23:13:11 +0000 (23:13 +0000)]
Move NetworkGraph inner structs to TLV storage

3 years agoMove ChannelManager-inner structs to TLV storage
Matt Corallo [Tue, 25 May 2021 21:20:02 +0000 (21:20 +0000)]
Move ChannelManager-inner structs to TLV storage

Note that enums are left alone as we can use the type byte already
present for future compatibility.

3 years agoAdd dummy OutPoint constructor to be used when reading it in a TLV
Matt Corallo [Tue, 25 May 2021 21:18:49 +0000 (21:18 +0000)]
Add dummy OutPoint constructor to be used when reading it in a TLV

3 years agoAdd a macro which implements Readable/Writeable using TLVs only
Matt Corallo [Tue, 25 May 2021 21:18:30 +0000 (21:18 +0000)]
Add a macro which implements Readable/Writeable using TLVs only

This also includes a `VecWriteWrapper` and `VecReadWrapper` which
implements serialization for any `Readable`/`Writeable` type that is
in a Vec. We do this instead of implementing `Readable`/`Writeable`
directly as there isn't always a univerally-defined way to serialize
a Vec and this makes things more explicit.

Finally, this tweaks existing macros (and in the new macros) to
support a trailing `,` after a list, eg
`write_tlv_fields!(stream, {(0, a),}, {});` whereas previously the
trailing `,` after the `(0, a)` would be a compile-error.

3 years agoMerge pull request #924 from GeneFerneau/alloc
Matt Corallo [Thu, 27 May 2021 19:08:00 +0000 (19:08 +0000)]
Merge pull request #924 from GeneFerneau/alloc

Use alloc for no_std builds

3 years agoUse alloc for no_std builds
Gene Ferneau [Wed, 19 May 2021 04:21:39 +0000 (04:21 +0000)]
Use alloc for no_std builds

Replace std structs with alloc equivalents to support no_std builds

f use prelude::* credit @devrandom

3 years agoCache socket address in HttpClient for reconnect
Jeffrey Czyz [Thu, 27 May 2021 15:53:14 +0000 (08:53 -0700)]
Cache socket address in HttpClient for reconnect

If the HttpClient attempts to reconnect to bitcoind that is no longer
running, the client fails to get the address from the stream. Cache the
address when connecting to prevent this.

3 years agoFix compile warnings reading type-0 TLVs
Matt Corallo [Tue, 25 May 2021 20:29:09 +0000 (20:29 +0000)]
Fix compile warnings reading type-0 TLVs

3 years agoMerge pull request #929 from jkczyz/2021-05-json-rpc-error
Matt Corallo [Thu, 27 May 2021 00:20:08 +0000 (00:20 +0000)]
Merge pull request #929 from jkczyz/2021-05-json-rpc-error

Parse RPC errors as JSON content

3 years agoParse RPC errors as JSON content
Jeffrey Czyz [Wed, 26 May 2021 17:57:39 +0000 (10:57 -0700)]
Parse RPC errors as JSON content

Bitcoin Core's JSON RPC server returns errors as HTTP error responses
with JSON content in the body. Parse this content as JSON to give a more
meaningful error. Otherwise, "binary" is given because the content
contains ASCII control characters.

3 years agoDefine an HttpError for returning error contents
Jeffrey Czyz [Wed, 26 May 2021 17:51:16 +0000 (10:51 -0700)]
Define an HttpError for returning error contents

Return an HTTP error response as a status code and contents. This allows
clients to interpret the response as desired (e.g., the contents as a
JSON-formatted error).

3 years agoMerge pull request #642 from ariard/2020-06-anchor-backend-refacto
Matt Corallo [Wed, 26 May 2021 15:50:25 +0000 (15:50 +0000)]
Merge pull request #642 from ariard/2020-06-anchor-backend-refacto

Anchor-outputs (1/3): Refactoring chain backend to extract PackageTemplate

3 years agoAdd package template unit tests
Antoine Riard [Mon, 26 Apr 2021 23:23:43 +0000 (19:23 -0400)]
Add package template unit tests

3 years agoMove compute_output_value as part of package member functions
Antoine Riard [Tue, 18 May 2021 18:09:02 +0000 (14:09 -0400)]
Move compute_output_value as part of package member functions

3 years agoMove get_height_timer out of OnchainTxHandler
Antoine Riard [Mon, 26 Apr 2021 22:22:53 +0000 (18:22 -0400)]
Move get_height_timer out of OnchainTxHandler

3 years agoMove onchain* to chain/
Antoine Riard [Sun, 18 Apr 2021 23:18:30 +0000 (19:18 -0400)]
Move onchain* to chain/