Commit graph

2807 commits

Author SHA1 Message Date
Matt Corallo
8bb661449e
Merge pull request #1878 from dunxen/2022-11-config-minfinalcltvexpiry
Allow configurable `min_final_cltv_expiry_delta`
2023-01-24 22:35:55 +00:00
Arik
45a6f3392d
Merge pull request #1967 from arik-so/2023-01-rename-signer-traits
Split out `EcdsaChannelSigner` method from `BaseSign`, and rename it to `ChannelSigner`
2023-01-24 13:20:26 -08:00
Valentine Wallace
ae34533932
Parameterize add_new_pending_payment with retry strategy and route params 2023-01-24 14:12:04 -05:00
Valentine Wallace
cbb75e27b2
Copy Retry from invoice module to outbound_payment module
Also configure it such that in std tests, it will use SinceEpoch instead of
Instant so time can be manually advanced.
2023-01-24 14:11:59 -05:00
Duncan Dean
5b53670172
Add new payment type and metadata bytes
Adds two new payment `Method`s for identifying payments with custom
`min_final_cltv_expiry_delta` as payments with LDK or user payment
hashes.

The `min_final_cltv_expiry_delta` value is packed into the first 2
bytes of the expiry timestamp in the payment secret metadata.
2023-01-24 21:01:27 +02:00
Duncan Dean
1d72e87e78
Add min_final_cltv_expiry parameter to invoice utils
All utility functions for invoice construction will now also accept an
Option<>al `min_final_cltv_expiry_delta` which is useful for things like
swaps etc. The `min_final_cltv_expiry_delta` will default back to
`MIN_FINAL_CLTV_EXPIRY_DELTA` if `None` is provided.
2023-01-24 13:07:46 +02:00
Duncan Dean
fb10fc9590
Add _delta suffix to min_final_cltv_expiry
This matches the spec and helps avoid any confusion around
naming. We're also then consistent with `cltv_expiry` in an HTLC being
the actual block height value for the CLTV and not a delta.
2023-01-24 13:07:23 +02:00
Arik Sosman
712c60e1c7
Make Channel and ChannelManager less particular about their Signer type. 2023-01-23 15:48:39 -08:00
Arik Sosman
394491115c
Rename Sign to WriteableEcdsaChannelSigner. 2023-01-23 15:48:38 -08:00
Arik Sosman
30c45469e5
Separate channel-type-agnostic methods into ChannelSigner trait. 2023-01-23 15:48:26 -08:00
Arik Sosman
1b245da370
Rename BaseSign to EcdsaChannelSigner. 2023-01-23 15:47:43 -08:00
Matt Corallo
869b71dccf impl Display for NodeId
`NodeId` is a public key, there's not much reason to not implement
`Display` for it and only `Debug`.
2023-01-23 23:39:40 +00:00
Matt Corallo
e0a0add9fe
Merge pull request #1926 from jkczyz/2022-12-invoice
BOLT 12 `invoice` encoding and building
2023-01-23 23:18:09 +00:00
Valentine Wallace
948ebc67f0
Copy PaymentAttempts from invoice module to outbound_payment module 2023-01-23 15:12:09 -05:00
Elias Rohrer
99fe52e93c
Expose impl_writeable_msg 2023-01-20 19:03:59 -06:00
Jeffrey Czyz
15f12953b2
Fix unused_imports warning in no-std tests 2023-01-20 16:04:39 -06:00
Jeffrey Czyz
a452551480
Invoice parsing tests
Tests for checking invoice semantics when parsing invoice bytes as
defined by BOLT 12.
2023-01-20 16:04:39 -06:00
Jeffrey Czyz
bf1147f23f
Invoice building tests
Tests for checking invoice message semantics when building an invoice as
defined by BOLT 12.
2023-01-20 16:04:39 -06:00
Jeffrey Czyz
fe83aede0c
Expand invoice module docs and include an example 2023-01-20 16:04:38 -06:00
Jeffrey Czyz
7f52d26e6e
Use SystemTime::now() for Invoice creation time
For std builds, Invoice::created_at can be automatically set upon
construction using SystemTime::now() offset by SystemTime::UNIX_EPOCH.
Change InvoiceRequest::respond_with and Refund::respond_with to only
take a created_at parameter in no-std builds.
2023-01-20 16:04:38 -06:00
Jeffrey Czyz
f779bc066f
Builder for creating invoices for refunds
Add a builder for creating invoices for a refund and required fields.
Other settings are optional and duplicative settings will override
previous settings. Building produces a semantically valid `invoice`
message for the refund, which then can be signed with the key associated
with the provided signing pubkey.
2023-01-20 16:04:38 -06:00
Jeffrey Czyz
88c5197e44
Builder for creating invoices for offers
Add a builder for creating invoices for an offer from a given request
and required fields. Other settings are optional and duplicative
settings will override previous settings. Building produces a
semantically valid `invoice` message for the offer, which then can be
signed with the key associated with the offer's signing pubkey.
2023-01-20 16:04:37 -06:00
Jeffrey Czyz
e1aa18aed8
Invoice encoding and parsing
Define an interface for BOLT 12 `invoice` messages. The underlying
format consists of the original bytes and the parsed contents.

The bytes are later needed for serialization. This is because it must
mirror all the `offer` and `invoice_request` TLV records, including
unknown ones, which aren't represented in the contents.

Invoices may be created for an Offer (from an InvoiceRequest) or for a
Refund. The primary difference is how the signing pubkey is given -- by
the writer of the offer or the reader of the refund.
2023-01-20 16:04:37 -06:00
Matt Corallo
efdd2217b7 Update min-inbound-fee values on NetworkGraph load
Historically we've had various bugs in keeping the
`lowest_inbound_channel_fees` field in `NodeInfo` up-to-date as we
go. This leaves the A* routing less efficient as it can't prune
hops as aggressively.

In order to get accurate benchmarks, this commit updates the
minimum-inbound-fees field on load. This is not the most efficient
way of doing so, but suffices for fetching benchmarks and will be
removed in the coming commits.

Note that this is *slower* than the non-updating version in the
previous commit. While I haven't dug into this incredibly deeply,
the graph snapshot in use has min-fee info for only 9,618 of
20,818 nodes. Thus, it is my guess that with the graph snapshot
as-is the branch predictor is able to largely remove the A*
heuristic lookups, but with this change it is forced to wait for
A* heuristic map lookups to complete, causing a performance
regression.

```
test routing::router::benches::generate_mpp_routes_with_probabilistic_scorer ... bench: 182,980,059 ns/iter (+/- 32,662,047)
test routing::router::benches::generate_mpp_routes_with_zero_penalty_scorer  ... bench: 151,170,457 ns/iter (+/- 75,351,011)
test routing::router::benches::generate_routes_with_probabilistic_scorer     ... bench:  58,187,277 ns/iter (+/- 11,606,440)
test routing::router::benches::generate_routes_with_zero_penalty_scorer      ... bench:  41,210,193 ns/iter (+/- 18,103,320)
```
2023-01-19 19:10:05 +00:00
Matt Corallo
608c8adfd5 Update the lightning graph snapshot used in benchmarks
The previous copy was more than one and a half years old, the
lightning network has changed a lot since!

As of this commit, performance on my Xeon W-10885M with a
SK hynix Gold P31 storing a BTRFS volume is as follows:

```
test ln::channelmanager::bench::bench_sends                                  ... bench:   5,896,492 ns/iter (+/- 512,421)
test routing::gossip::benches::read_network_graph                            ... bench: 1,645,740,604 ns/iter (+/- 47,611,514)
test routing::gossip::benches::write_network_graph                           ... bench: 234,870,775 ns/iter (+/- 8,301,775)
test routing::router::benches::generate_mpp_routes_with_probabilistic_scorer ... bench: 166,155,032 ns/iter (+/- 30,206,162)
test routing::router::benches::generate_mpp_routes_with_zero_penalty_scorer  ... bench: 136,843,661 ns/iter (+/- 67,111,218)
test routing::router::benches::generate_routes_with_probabilistic_scorer     ... bench:  52,954,598 ns/iter (+/- 11,360,547)
test routing::router::benches::generate_routes_with_zero_penalty_scorer      ... bench:  37,598,126 ns/iter (+/- 17,262,519)
test bench::bench_sends                                                      ... bench:  37,760,922 ns/iter (+/- 5,179,123)
test bench::bench_reading_full_graph_from_file                               ... bench:      25,615 ns/iter (+/- 1,149)
```
2023-01-19 05:06:29 +00:00
Matt Corallo
153b048332
Merge pull request #1951 from wpaulino/remove-get-node-secret 2023-01-19 03:49:15 +00:00
Arik
d66c70eed4
Merge pull request #1964 from TheBlueMatt/2023-01-no-debug-panics
Use test/_test_utils to enable single-threaded debug assertions
2023-01-18 17:41:54 -08:00
Wilmer Paulino
acd2ae606d
Remove NodeSigner::get_node_secret
Secrets should not be exposed in-memory at the interface level as it
would be impossible the implement it against a hardware security
module/secure element.
2023-01-18 17:23:25 -08:00
Wilmer Paulino
9133beaf75
Use NodeSigner::ecdh to compute SharedSecrets 2023-01-18 17:23:23 -08:00
Wilmer Paulino
19c4468bfc
Sign gossip messages with NodeSigner 2023-01-18 17:23:22 -08:00
Wilmer Paulino
db0d6ecdbb
Add NodeSigner::sign_gossip_message
Adds signing capability to NodeSigner for all gossip messages that
require a node signature.
2023-01-18 17:23:15 -08:00
Matt Corallo
50d12600b4
Merge pull request #1860 from wpaulino/open-channel-anchors-support
Support opening anchor channels and test end-to-end unilateral close
2023-01-19 01:00:44 +00:00
Wilmer Paulino
aee9952ea3
Remove unused NodeSigner implementations in tests
These implementations have every method panic, so assuming that the test
suite passes, these implementations are never used.
2023-01-18 16:57:52 -08:00
Wilmer Paulino
660165ce67
Add test yielding anchor-related events 2023-01-18 14:46:16 -08:00
Wilmer Paulino
d9dd21b086
Add mine_transactions test util 2023-01-18 14:46:15 -08:00
Wilmer Paulino
8dda117fb7
Support negotiating anchors throughout channel open 2023-01-18 14:46:13 -08:00
Jeffrey Czyz
243f448701
Encoding for TLV stream without signature records
When using bytes from an InvoiceRequest to constructing bytes for an
Invoice, any signature TLV records in the bytes must be excluded. Define
a wrapper for encoding such pre-serialized bytes in this manner. This
will allow the forthcoming InvoiceBuilder to construct bytes for an
Invoice properly.
2023-01-18 15:31:48 -06:00
Jeffrey Czyz
6b3535451e
Define TlvStream::skip_signatures
Provide a helper for skipping signature TLV records from a TLV stream.
This prevents needing to duplicate the check for signature TLV records
when writing a TLV stream without signatures in an upcoming commit.
2023-01-18 15:31:48 -06:00
Jeffrey Czyz
bd0040a02b
Drop AsRef<[u8]> implementation for TlvRecord
Explicitly using TlvRecord::record_bytes makes reading the code more
obvious than hiding which bytes are used in AsRef<[u8]>::as_ref.
2023-01-18 15:31:48 -06:00
Matt Corallo
ad40573bc4
Merge pull request #1956 from TheBlueMatt/2023-01-ser-cleanups
Trivial Serialization Tweaks
2023-01-18 21:31:07 +00:00
Matt Corallo
7a9bea1bdd Use test/_test_utils to enable single-threaded debug assertions
We have a number of debug assertions which are expected to never
fire when running in a single thread. This is just fine in tests,
and gives us good coverage of our lockorder requirements, but is
not-irregularly surprising to users, who may run with their own
debug assertions in test environments.

Instead, we gate these checks by the `cfg(test)` setting as well as
the `_test_utils` feature, ensuring they run in our own tests, but
not downstream tests.
2023-01-17 23:47:45 +00:00
Matt Corallo
31b0a13158
Merge pull request #1957 from TheBlueMatt/2022-01-mon-ref-lockorder
Pass MonitorUpdates by ref and tweak manager lockorder
2023-01-17 23:09:05 +00:00
Wilmer Paulino
31a59629c4
Define option_anchors_zero_fee_htlc_tx feature bit 2023-01-17 15:03:54 -08:00
Wilmer Paulino
bb617d3392
Fix stale reference to BaseSign::ready_channel 2023-01-17 15:03:53 -08:00
Wilmer Paulino
9cbbb58333
Add missing space in DebugTx logging 2023-01-17 15:03:47 -08:00
Matt Corallo
3e9727b808 Use a variable-length integer for many serialization wrappers
The lightning protocol uses u16s for lengths in most cases. As our
serialization framework primarily targets that, we must as well.
However, because we may serialize objects that have  more than 65K
entries, we want to be able to store larger values. Thus, we define
a variable length integer here which is backwards-compatible but
treats 0xffff as "read eight more bytes".

This doesn't address any specific known issue, but feels like good
practice just in case.
2023-01-17 21:48:23 +00:00
Matt Corallo
01fe9badc0
Merge pull request #1955 from TheBlueMatt/2023-01-1950-message-text
Fix link text in `reply_short_channel_ids_end`
2023-01-17 17:49:29 +00:00
Max Fang
ad4b91da88 derive Debug for ConfirmationTarget 2023-01-16 20:15:01 -08:00
Matt Corallo
437fa4f807
Merge pull request #1959 from danielgranhao/stop-passing-init-features-in-msg-handlers
Stop passing `InitFeatures` in msg handlers
2023-01-17 01:26:31 +00:00
Daniel Granhão
bcf174034a
Stop passing InitFeatures in msg handlers 2023-01-16 21:18:53 +00:00