Commit graph

2476 commits

Author SHA1 Message Date
Gene Ferneau
da7a851d47
Use hashbrown replacements for std equivalents 2021-06-18 21:54:21 +00:00
Matt Corallo
4d1c1a32f2
Merge pull request #956 from jkczyz/2021-06-validate-pub
Increase poll::Validate visibility to pub
2021-06-18 18:06:45 +00:00
Matt Corallo
244ad8349e
Merge pull request #955 from TheBlueMatt/2021-06-rustc-bugz
Fix trivial doc warnings and make CI use old rustc
2021-06-18 15:24:21 +00:00
Jeffrey Czyz
7302c8c38a
Remove unnecessary spaces 2021-06-18 00:26:36 -05:00
Jeffrey Czyz
8cc026b406
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.
2021-06-18 00:26:33 -05:00
Matt Corallo
f875579311 Clarify invoice comment noting the relevant final-cltv-expiry vals 2021-06-17 20:17:24 +00:00
Matt Corallo
84ac66e80f 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.
2021-06-17 16:58:59 +00:00
Matt Corallo
e7974dac84 Expose doc-linked constants in lightning-invoice
These constants are generally useful, and are linked from
documentation, so should be exposed in any case.
2021-06-17 15:48:20 +00:00
Matt Corallo
27d9feda58 Only check docs on rustc 1.52 as rustc stable now crashes 2021-06-17 15:41:16 +00:00
Matt Corallo
294009969a
Merge pull request #944 from TheBlueMatt/2021-06-0.0.99
0.0.98
2021-06-11 17:02:11 +00:00
Matt Corallo
7b4b753010
Merge pull request #946 from jkczyz/2021-06-get-route-interface
Align get_route's interface with ChannelManager and Invoice
2021-06-11 16:51:48 +00:00
Jeffrey Czyz
d0355b7b45
Fix type name in docs 2021-06-11 08:44:35 -07:00
Jeffrey Czyz
200f3d155c
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.
2021-06-11 08:44:32 -07:00
Jeffrey Czyz
c9d1ed5c14
Add find_all_extract macro to lightning-invoice
Used for extracting more than one field of the same type.
2021-06-10 12:54:55 -07:00
Matt Corallo
9c9081dfcb Bump versions to 0.0.98, lightning-invoice to 0.6.0 2021-06-08 21:08:29 +00:00
Matt Corallo
a8038a8234
Merge pull request #940 from TheBlueMatt/2021-06-fix-docs
Clean up docs on public chan_utils methods to be more useful
2021-06-08 02:28:46 +00:00
Matt Corallo
1d4f9c8dec
Merge pull request #936 from TheBlueMatt/2021-05-spendable-event-locktime-delay
Delay DelayedPaymentOutput spendable events until the CSV delay
2021-06-08 01:53:03 +00:00
Matt Corallo
0e101417a5
Merge pull request #943 from lightning-signer/2021-06-signet
Add proper signet support for invoices
2021-06-08 01:52:38 +00:00
Matt Corallo
8cdc855f01 Clean up docs on public chan_utils methods to be more useful 2021-06-08 01:52:09 +00:00
Matt Corallo
ffec147f0f
Merge pull request #939 from TheBlueMatt/2021-05-derives
Add additional derives for a few structs
2021-06-08 01:51:41 +00:00
Matt Corallo
8808e4051c
Merge pull request #942 from lightning-signer/2021-06-accept-channel-reserve-dust
Remove unwanted check in accept_channel
2021-06-07 22:03:11 +00:00
Devrandom
bac5f4930f Add proper signet support for invoices 2021-06-07 16:29:39 +02:00
Devrandom
b22e5c0c9b 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).
2021-06-07 16:22:07 +02:00
Matt Corallo
ed6a69c1cf Add additional derives for a few structs 2021-06-02 16:21:00 +00:00
Matt Corallo
e60ccbb1a8 Delay DelayedPaymentOutput spendable events until the CSV delay 2021-06-01 22:32:56 +00:00
Matt Corallo
3996eaab6e Merge pull request #935 from TheBlueMatt/2021-05-enum-tlvs
TLV-ize enum serialization and a few additional structs
2021-06-01 21:53:15 +00:00
Matt Corallo
73576574a9 Update network graph sample used in benchmarks 2021-06-01 21:53:06 +00:00
Matt Corallo
c56265d225 Convert SpendableOutputDescriptor to new TLV-based serialization 2021-06-01 21:53:06 +00:00
Matt Corallo
3c93967cd2 Clean up ChannelMonitor object serialization to use TLVs/versions 2021-06-01 21:53:06 +00:00
Matt Corallo
9e5d9516dd Use TLVs inside of serialization of Event variants 2021-06-01 21:53:06 +00:00
Matt Corallo
66784e32fe Convert remaining channel inner structs and enums to TLV-based ser 2021-06-01 21:53:06 +00:00
Matt Corallo
86641ea680 Convert most chain::* inner structs and enums to TLV-based ser macros 2021-06-01 21:53:06 +00:00
Matt Corallo
68313da695 Add generic serialization implementations for Boxs and 3-tuples
These are used in the next commit(s).
2021-06-01 21:53:06 +00:00
Matt Corallo
b385a40e4a 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.
2021-06-01 21:53:06 +00:00
Matt Corallo
ccc828412e Add a macro to implement serialization of enums using TLVs 2021-06-01 21:53:06 +00:00
Matt Corallo
ee29bc4096
Merge pull request #938 from lightning-signer/2020-06-test-background
Expose test_process_background_events
2021-06-01 17:32:29 +00:00
Devrandom
29bad58ff4 Expose test_process_background_events 2021-06-01 19:00:00 +02:00
Matt Corallo
0e41bba506 Give OnchainEvent::HTLCUpdate individual fields instead of a pair 2021-06-01 16:11:53 +00:00
Matt Corallo
77bdc32bbd
Merge pull request #933 from TheBlueMatt/2021-05-ser-fast
Speed up deserialization of secp256k1 objects significantly
2021-06-01 16:11:24 +00:00
Matt Corallo
7231b4a245 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)
2021-06-01 15:47:01 +00:00
Matt Corallo
583e6ac6f0 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)
2021-06-01 15:47:01 +00:00
Matt Corallo
c632fffc3d 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)
2021-06-01 15:47:01 +00:00
Matt Corallo
615419d525 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.
2021-06-01 15:47:01 +00:00
Matt Corallo
08ecb53915 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)
2021-06-01 15:47:01 +00:00
Matt Corallo
c7113bcd92 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)
2021-06-01 15:47:01 +00:00
Matt Corallo
c05347f48a
Merge pull request #892 from TheBlueMatt/2021-04-fix-htlc-ser
Correct Channel outbound HTLC serialization and expand fuzzing coverage
2021-05-31 23:52:22 +00:00
Matt Corallo
4cc320bb60
Merge pull request #934 from TheBlueMatt/2021-05-new-tag
Add new `(C-not implementable)` tag on `EventsProvider`
2021-05-31 20:35:16 +00:00
Matt Corallo
25dbd0d7e0 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".
2021-05-31 18:20:22 +00:00
Matt Corallo
e003c43183 [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.
2021-05-31 18:20:22 +00:00
Matt Corallo
b780cbdbfc [fuzz] Fix hang due to double-lock in full_stack_target 2021-05-31 18:20:22 +00:00