Commit graph

4537 commits

Author SHA1 Message Date
Jeffrey Czyz
2d44dbe013
Disallow offer_metadata in Refund
The offer_metadata was optional but is redundant with invreq_metadata
(i.e., payer_metadata) for refunds. It is now disallowed in the spec and
was already unsupported by RefundBuilder.
2023-01-30 15:44:39 -06:00
Jeffrey Czyz
6236e0d472
Allow quantity in Refund
The spec always allowed this but the reason was unclear. It's useful if
the refund is for an invoice paid for offer where a quantity was given
in the request. The description in the refund would be from the offer,
which may have given a unit for each item. So allowing a quantity makes
it clear how many items the refund is for.
2023-01-30 15:44:39 -06:00
Jeffrey Czyz
4059677e8e
Support explicit quantity_max = 1 in Offer
The spec was modified to allow setting offer_quantity_max explicitly to
one. This is to support a use case where more than one item is supported
but only one item is left in the inventory. Introduce a Quantity::One
variant to replace Quantity::Bounded(1) so the later can be used for the
explicit setting.
2023-01-30 15:44:39 -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
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
Jeffrey Czyz
98417a16df
Merge pull request #1968 from lexe-tech/max/net-tokio-no-arc
lightning-net-tokio: Don't require `Arc<PeerManager>`
2023-01-18 10:26:39 -06:00
Max Fang
fce0397507 lightning-net-tokio: Don't require Arc<PeerManager> 2023-01-17 20:37:10 -08:00
Matt Corallo
c86950d510
Merge pull request #1962 from TheBlueMatt/2023-01-bp-no-std
Use the user-provided `SleepFuture` for interval checks in `background-processor`
2023-01-17 23:48:48 +00:00
Matt Corallo
e1b58a810f
Merge pull request #1960 from tnull/2023-01-deref-router-in-invoicepayer
Make `InvoicePayer`'s `Router` `Deref`
2023-01-17 23:21:22 +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
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
aa4c6f6418 Make background-processor no-std-friendly (ish)
This makes `background-processor` build without `std` at all. This
isn't particularly useful in the general no-std case as
`background-processor` is only useful with the `futures` feature,
and async will generally need `std` in some way or another. Still,
it ensures we don't end up reintroducing a dependency on the
current time, which breaks `wasm` use-cases.
2023-01-17 20:38:07 +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
Matt Corallo
6742bd5244
Merge pull request #1963 from lexe-tech/max/derive-debug
derive `Debug` for `ConfirmationTarget`
2023-01-17 17:03:13 +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
Matt Corallo
7fefa00e09
Merge pull request #1939 from TheBlueMatt/2022-01-fuzz-hashbrown
Misc fuzzing tweaks
2023-01-17 00:55:37 +00:00
Matt Corallo
e59b3847a3 Use the user-provided SleepFuture for interval checks in BP
`background-processor` does a number of jobs on various timers.
Instead of doing those by interrogating `std::time::Instant`, this
change swaps to using the existing user-provided sleep future.

Fixes #1864.
2023-01-17 00:26:21 +00:00
Matt Corallo
d308710d4f Use flexible timer types in background processor's regular jobs
`background-processor` does a number of jobs on various timers.
Currently, those are all done by checking the timers every 100ms
by interrogating `std::time::Instant`. This is fine for the
threaded version, but we'd like more flexibility in the `futures`-
based `background-processor`.

Here we swap the `std::time::Instant` interrogation for a lambda
which we will switch out to the user-provided sleeper in the next
commit.
2023-01-17 00:03:35 +00:00
Elias Rohrer
bc8e1e51e9
Make InvoicePayer's Router Deref
As of HEAD the `ChannelManager` is parametrized by a `Router`, while
`InvoicePayer` also owns a `Router`. In order to allow for a single
object being reused, we make the `InvoicePayer` side `Deref`.
2023-01-16 16:54:53 -06:00
Daniel Granhão
bcf174034a
Stop passing InitFeatures in msg handlers 2023-01-16 21:18:53 +00:00
Matt Corallo
bae81bafca Swap per_peer_state lock order 2023-01-15 23:53:21 +00:00
Matt Corallo
7e23afe1dc Pass monitor updates by reference, not owned
In the next commit(s) we'll start holding `ChannelMonitorUpdate`s
that are being persisted in `Channel`s until they're done
persisting. In order to do that, switch to applying the updates by
reference instead of value.
2023-01-15 23:53:21 +00:00
Matt Corallo
f9bafa6d0e Use ChannelUnavailable for a peer disconnecting not MisuseError
This fixes a crash in the `full_stack_target` fuzz test (found by
Chaincode's generous fuzzing infrastructure!) but ultimately is a
better error code - a peer disconnecting before we can fund a
channel isn't a "misuse error" its an unavailable channel.
2023-01-15 23:38:24 +00:00
Matt Corallo
fb5b427cba Make fuzz assertions explicit in Cargo.toml 2023-01-15 23:32:09 +00:00
Matt Corallo
11524884cb Do not rely on auto-deref'ing when aaccessing a Hash{Map,Set}
In newer versions of `hashbrown` this code would be broken. While
we aren't updating `hashbrown` any time soon (as it requires an
MSRV bump), it is useful to swap for a newer `hashbrown` when
fuzzing, which this makes easier.
2023-01-15 23:32:08 +00:00
Matt Corallo
7bdbbca3b0 Switch to hashbrown in fuzzing
hashbrown by default uses ahash, which may be a bit faster, but
more importantly, if we upgrade to hashbrown 0.13/ahash 0.8 we can
make it use a constant randomization factor, making fuzzers happier.
2023-01-15 23:31:06 +00:00
Matt Corallo
3259996e50 Bump fuzz afl dependency to latest upstream version 2023-01-15 23:31:06 +00:00
Matt Corallo
b75a558a1d Convert Vec de/serialization impl to a macro and impl for tuples
...to make it easier to add new implementations and implement it
for all tuples which implement `Readabe` + `Writeable`. Note that
we don't want to just convert to a blanket implementation as we'd
really like to keep our optimized `Vec<u8>` wrapper or we'll end
up spinning way too much when writing vecs of bytes.
2023-01-15 20:30:12 +00:00
Matt Corallo
a03db3ca30 Add support for including ignorable types in enum de/ser macros
An enum implements de/serialization via
`impl_writeable_tlv_based_enum_upgradable` currently cannot contain
an object that only implements `MaybeReadable`.

This solves that by implementing the required blocks for
`ignorable`, opting to return `Ok(None)` in the top-level read in
cases where the inner field read returns `Ok(None)`.
2023-01-15 20:28:42 +00:00
Matt Corallo
7fd9b33c09 Implement (de)serialization for BTreeMap same as HashMap 2023-01-15 20:28:19 +00:00
Matt Corallo
8ecd71777c Fix link text in reply_short_channel_ids_end 2023-01-15 07:03:55 +00:00
Matt Corallo
ce6bcf68a1
Merge pull request #1950 from tnull/2023-01-fix-doc-warnings-and-nits
Fix doc warnings and doc cleanup in `msgs.rs`/`ser.rs`
2023-01-15 07:03:14 +00:00
Matt Corallo
de783e0b95
Merge pull request #1946 from wpaulino/init-features-user-config
Use UserConfig to determine advertised InitFeatures by ChannelManager
2023-01-15 04:00:11 +00:00
Matt Corallo
1e81287cbc
Merge pull request #1953 from arik-so/2023-01-debug-gossip-heisenbug 2023-01-14 22:43:26 +00:00
Arik Sosman
16deda07aa
Allow manually passing a timestamp to channel_failed. Fixes #1914. 2023-01-14 08:22:50 -08:00
Arik Sosman
e9d4ae1d3e
Add error messages to stale gossip cleanup assertions.
Should help debug #1914.
2023-01-14 07:27:44 -08:00
Wilmer Paulino
abf4e79dcd
Use UserConfig to determine advertised InitFeatures by ChannelManager
This is purely a refactor that does not change the InitFeatures
advertised by a ChannelManager. This allows users to configure which
features should be advertised based on the values of `UserConfig`. While
there aren't any existing features currently leveraging this behavior,
it will be used by the upcoming anchors_zero_fee_htlc_tx feature.

The UserConfig dependency on provided_init_features caused most
callsites of the main test methods responsible for opening channels to
be updated. This commit foregos that completely by no longer requiring
the InitFeatures of each side to be provided to these methods. The
methods already require a reference to each node's ChannelManager to
open the channel, so we use that same reference to obtain their
InitFeatures. A way to override such features was required for some
tests, so a new `override_init_features` config option now exists on
the test harness.
2023-01-13 23:54:51 -08:00
Matt Corallo
ac6e0b3fed
Merge pull request #1930 from arik-so/2022-12-remove-keysinterface
Remove KeysInterface
2023-01-14 04:59:27 +00:00
Elias Rohrer
defa2f6811
Fix misc. warnings from --document-private-items 2023-01-13 18:26:09 -06:00