Commit graph

4614 commits

Author SHA1 Message Date
Viktor Tigerström
c42323c857 Remove unnecessary channel counterparty checks 2023-01-09 23:50:41 +01:00
Viktor Tigerström
5578d79bfa Add handle unkown peer test 2023-01-09 23:50:41 +01:00
Viktor Tigerström
8c175f5238 Add duplicate temporary_channel_id for 2 peers test 2023-01-09 23:50:41 +01:00
Viktor Tigerström
0eb74ec007 Unify failure to query Channel error messages 2023-01-09 23:50:41 +01:00
Viktor Tigerström
ff9840ea35 Avoid unnecessary immediate retake per_peer_state lock 2023-01-09 23:50:41 +01:00
Viktor Tigerström
b8ca7c9256 Remove unnecessary per_peer_state branch
After `channels` are now stored in the `per_peer_state`, some logic can
be simplified and extra accessing of the `per_peer_state` can be
removed.
2023-01-09 23:50:41 +01:00
Viktor Tigerström
1ab25a086a Store channels per peer 2023-01-09 23:50:41 +01:00
Matt Corallo
197a47a8f3
Merge pull request #1941 from andrei-21/feature/rework-unwrap
Rework `unwrap()` call in persistence
2023-01-09 19:35:57 +00:00
Omer Yacine
0acd5d3e46
Fix an incorrect assertion in tlv stream encoding
Types must be unique and monotonically increasing (using < instead of <=)
2023-01-09 21:20:23 +02:00
Omer Yacine
3a33693b1e
Expose impl_writeable_tlv_based macro
Every exported macro needed to have all the macros used inside it:
1- to be exported as well.
2- be called from the `$crate` namespace so it works in other crates.

Some structs in `lightning::util::ser` needed to be made public as they were used inside the exported macros.

Use the macros like this:
```Rust
lightning::impl_writeable_tlv_based!(...)
```
2023-01-09 21:16:30 +02:00
Matt Corallo
8896f6eb7f
Merge pull request #1940 from TheBlueMatt/2023-01-nostd-try-lock 2023-01-09 16:22:34 +00:00
Andrei
a320ebc100 Rework unwrap() call in persistence 2023-01-08 00:00:00 +00:00
Matt Corallo
efc0244ba6 Make the no-std RwLockGuard try_lock actually try
There doesn't appear to be any reason to have `try_lock` fail, and
future work shouldn't need to check for std to use `try_lock`.
2023-01-07 22:43:09 +00:00
Viktor Tigerström
4207eab59d Add try_write function to FairRwLock 2023-01-07 00:52:30 +01:00
Viktor Tigerström
48f9c72eb6 Add ChannelManager::PeerState::latest_features docs 2023-01-07 00:52:29 +01:00
Viktor Tigerström
ce5cc73b4d Add counterparty_node to test macros 2023-01-07 00:52:29 +01:00
valentinewallace
d8a20eda5f
Merge pull request #1927 from jkczyz/2022-12-invoice-rework
Pre-work for BOLT 12 invoices
2023-01-06 11:07:17 -05:00
Jeffrey Czyz
b50fc4e32c
Define blinded hop features for use in BOLT 12
BOLT 12 invoices may contain blinded_payinfo for each hop in a blinded
path. Each blinded_payinfo contains features, whose length must be
encoded since there may be multiple hops.

Note these features are also needed in the BOLT 4 encrypted_data_tlv
stream. But since they are a single TLV record, the length must *not* be
encoded there.
2023-01-05 22:39:24 -06:00
Jeffrey Czyz
d985ced7e3
Define BOLT 12 invoice features with MPP support 2023-01-05 22:39:24 -06:00
Jeffrey Czyz
ea1a68c6e6
Use explicit WithoutLength for BOLT 12 features
Most BOLT 12 features are used as the value of a TLV record and thus
don't use an explicit length. One exception is the features inside the
blinded payinfo subtype since the TLV record contains a list of them.
However, these features are also used in the BOLT 4 encrypted_data_tlv
TLV stream as a single record, where the length is implicit.

Implement Readable and Writeable for Features wrapped in WithoutLength
such that either serialization can be used where required.
2023-01-05 22:39:24 -06:00
Jeffrey Czyz
1a437f4150
Remove Option from InvoiceRequest::signature
Refunds don't have signatures and now use their own abstraction.
Therefore, signatures can be required in invoice requests as per the
spec.
2023-01-05 22:39:24 -06:00
Jeffrey Czyz
7964b9f745
Correct documentation about Refund::payer_id
The docs incorrectly stated that Refund::payer_id is for signing, where
it is only used for identifying a node if Refund::paths is not present.
2023-01-05 22:38:31 -06:00
Matt Corallo
b79ff71fe7
Merge pull request #1812 from valentinewallace/2022-10-chanman-router-param
Parameterize `ChannelManager` by a `Router`
2023-01-05 22:09:35 +00:00
Valentine Wallace
19516c041e
Test utils: allow queueing >2 persistence update results 2023-01-05 11:29:24 -05:00
Valentine Wallace
22501c3c5e
ser_macros: rename check_tlv_order
.. to disamgibutate from check_encoded_tlv_order
2023-01-05 11:29:24 -05:00
Matt Corallo
af6fa143a1
Provide a static_value TLV field serialization type
This is useful in the type serialization definition macros to avoid
writing or reading a field at all, simply using a static value on
each reload.
2023-01-05 11:29:21 -05:00
Valentine Wallace
682bb9b0ae
Parameterize Simple*ChannelManager with DefaultRouter and ProbScorer 2023-01-05 11:29:00 -05:00
Valentine Wallace
3a1982c741
Take in-flight HTLCs by reference in Router::find_route
Useful in upcoming work when for payment retries.
2023-01-05 11:24:56 -05:00
Valentine Wallace
3a274e0415
Implement routing against the netgraph in tests 2023-01-05 11:23:45 -05:00
Matt Corallo
e1208bfd66
Merge pull request #1935 from TheBlueMatt/2022-12-no-non-time-panic
Ensure derive_channel_keys doesn't panic if per-run seed is high
2023-01-03 22:02:04 +00:00
Valentine Wallace
2e06efe2ff
Parameterize ChannelManager by a Router trait
This will be used in upcoming work to fetch routes on-the-fly for payment
retries, which will no longer be the responsibility of InvoicePayer.
2023-01-03 15:34:14 -05:00
Matt Corallo
5dde803d08 Ensure the per-channel key derivation counter doesn't role over
Previously, the `derive_channel_keys` derivation ID asserted that
the high bit of the per-channel key derivation counter doesn't
role over as it checked the 31st bit was zero. As we no longer do
that, we should ensure the assertion in `generate_channel_keys_id`
asserts that we don't role over.
2023-01-03 17:34:19 +00:00
Matt Corallo
7d84a45ae8
Merge pull request #1934 from TheBlueMatt/2022-12-113-bindings-upstream
Trivial Bindings Updates
2023-01-03 17:06:37 +00:00
Matt Corallo
dc39799c60
Merge pull request #1936 from TheBlueMatt/2023-01-in-flight-clone
`#[derive(Clone)]` for `InFlightHtlcs`
2023-01-03 16:43:18 +00:00
Matt Corallo
9414830951 #[derive(Clone)] for InFlightHtlcs
This is useful for bindings, and generally isn't a bad thing for
users to have access to.
2023-01-02 01:09:43 +00:00
Matt Corallo
34de734194 Ensure derive_channel_keys doesn't panic if per-run seed is high
b04d1b868f changed the way we
calculate the `channel_keys_id` to include the 128-bit
`user_channel_id` as well, shifting the counter up four bytes and
the `starting_time_nanos` field up into the second four bytes.

In `derive_channel_keys` we hash the full `channel_keys_id` with an
HD-derived key from our master seed. Previously, that key was
derived with an index of the per-restart counter, re-calculated by
pulling the second four bytes out of the `user_channel_id`. Because
the `channel_keys_id` fields were shifted up four bytes, that is
now a reference to the `starting_time_nanos` value. This should be
fine, the derivation doesn't really add any value here, its all
being hashed anyway, except that derivation IDs must be below 2^31.
This implies that we panic if the user passes a
`starting_time_nanos` which has the high bit set. For those using
the nanosecond part of the current time this isn't an issue - the
value cannot exceed 1_000_000, which does not have the high bit
set, however, some users may use some other per-run seed.

Thus, here we simply drop the high bit from the seed, ensuring we
don't panic. Note that this is backwards compatible as it only
changes the key derivation in cases where we previously panicked.

Ideally we'd drop the derivation entirely, but that would break
backwards compatibility of key derivation.
2022-12-28 18:11:18 +00:00
Matt Corallo
f00bc4d713 No-export &self methods on non-cloneable enum(s)
Specifically, `OnionMessageContents` is a non-cloneable enum, which
isn't stored opaque so we cannot call `&self` methods on it.
Because its methods aren't critical to the API for now, we simply
no-export them rather than trying to work out an alternative
approach.
2022-12-25 00:58:19 +00:00
Matt Corallo
9449d042b9 Store an owned Score in ScorerAccountingForInFlightHtlcs
`ScorerAccountingForInFlightHtlcs` generally stores a `Score`
reference generated by calling `LockableScore::lock`, which
actually returns an arbitrary `Score`. Given `Score` is implemented
directly on lock types, it makes sense to simply hold a fully owned
`Score` in `ScorerAccountingForInFlightHtlcs` rather than a mutable
reference to one.
2022-12-25 00:58:19 +00:00
Matt Corallo
f0c181e2f2
Merge pull request #1929 from valentinewallace/2022-12-outbound-payment-mod-followup
Outbound payment module follow-up
2022-12-21 23:08:58 +00:00
Valentine Wallace
cc60fd601f
outbound_payment: put method signature closing paren on next line
in long method signatures
2022-12-21 16:26:55 -05:00
Arik
c04d1c985f
Merge pull request #1931 from TheBlueMatt/2022-12-1910-followups
Trivial #1910 Followups
2022-12-21 11:05:09 -08:00
Matt Corallo
fa42b5ea82 Fix capitalization broken in 9d7bb73b59
9d7bb73b59 broke some capitalization
in docs for `sign_invoice`, which we fix here as well as taking
this opportunity to clean up the `sign_invoice` docs more
generally.
2022-12-21 16:39:37 +00:00
Matt Corallo
ac690e8191 Clean up use ordering introduced in 9d7bb73b59
9d7bb73b59 moved some code around
unnecessarily, which we fix here.
2022-12-21 16:38:54 +00:00
Valentine Wallace
60492d769a
Fix cfg(test) indentation 2022-12-20 21:23:54 -05:00
Valentine Wallace
8d5f7c87cb
Make add_new_pending_payment private to module
And expose it in testing only, for safety
2022-12-20 21:23:54 -05:00
valentinewallace
cbbf84b050
Merge pull request #1928 from valentinewallace/2022-12-fix-main
Fix `main` build
2022-12-20 19:31:16 -05:00
Valentine Wallace
1ded1d21bd
Fix main build 2022-12-20 17:55:06 -05:00
Matt Corallo
f7211fbf79
Merge pull request #1910 from arik-so/2022-12-keys-interface-name-split
Split KeysInterface into EntropySource, NodeSigner, and SignerProvider
2022-12-20 22:19:43 +00:00
valentinewallace
e64ebe8608
Merge pull request #1923 from valentinewallace/2022-12-outbound-payment-mod
Abstract `ChannelManager` outbound payment logic
2022-12-20 15:40:48 -05:00
Arik Sosman
9d7bb73b59
Split out KeysInterface into EntropySource, NodeSigner, and SignerProvider. 2022-12-20 10:09:11 -08:00