Commit graph

4622 commits

Author SHA1 Message Date
Jeffrey Czyz
3d41df025d
Fuzz test for bech32 decoding
Fuzz testing bech32 decoding along with deserializing the underlying
message can result in overly exhaustive searches. Instead, the message
deserializations are now fuzzed separately. Add fuzzing for bech32
decoding.
2023-02-23 18:25:49 -06:00
Jeffrey Czyz
56a01de61d
Expose Bech32Encode trait for fuzzing
In order to fuzz test Bech32Encode parsing independent of the underlying
message deserialization, the trait needs to be exposed. Conditionally
expose it only for fuzzing.
2023-02-23 18:25:49 -06:00
Jeffrey Czyz
16168d4c07
Fuzz test for parsing Invoice
An invoice is serialized as a TLV stream and encoded as bytes. Add a
fuzz test that parses the TLV stream and deserializes the underlying
Invoice. Then compare the original bytes with those obtained by
re-serializing the Invoice.
2023-02-23 18:25:49 -06:00
Jeffrey Czyz
e049e97993
Fuzz test for parsing InvoiceRequest
An invoice request is serialized as a TLV stream and encoded as bytes.
Add a fuzz test that parses the TLV stream and deserializes the
underlying InvoiceRequest. Then compare the original bytes with those
obtained by re-serializing the InvoiceRequest.
2023-02-23 18:24:41 -06:00
Jeffrey Czyz
9a65709239
Derive traits for InvoiceRequest and Invoice
Offer and Refund derive Debug, Clone, and PartialEq. For consistency,
derive these traits for InvoiceRequest and Invoice as well.
2023-02-21 14:07:51 -06:00
Jeffrey Czyz
0001260f74
Fuzz test for parsing Refund
A refund is serialized as a TLV stream and encoded in bech32 without a
checksum. Add a fuzz test that parses the unencoded TLV stream and
deserializes the underlying Refund. Then compare the original bytes with
those obtained by re-serializing the Refund.
2023-02-08 19:02:17 -06:00
Jeffrey Czyz
a320a4daf5
Fix RoutingFees::base_msat docs 2023-02-08 18:56:40 -06:00
Jeffrey Czyz
fcb67434d9
Make BlindedPayInfo fields public
BlindedPayInfo fields need to be public in order to construct one for
fuzz tests. Typically, they would be constructed from ChannelUpdateInfo
for public channels and ChannelDetails for unannounced channels. For
now, make the fields public so they can be constructed manually.
2023-02-08 18:56:40 -06:00
Jeffrey Czyz
53d2d47360
Fuzz test for parsing Offer
An offer is serialized as a TLV stream and encoded in bech32 without a
checksum. Add a fuzz test that parses the unencoded TLV stream and
deserializes the underlying Offer. Then compare the original bytes with
those obtained by re-serializing the Offer.
2023-02-08 18:47:48 -06:00
Jeffrey Czyz
153d831ccc
Make offers module public
This is needed in order to fuzz test BOLT 12 message deserialization.
2023-02-03 15:23:43 -06:00
Jeffrey Czyz
6388c9a3e5
Add test for requesting invoice from expired offer 2023-02-03 15:23:43 -06:00
Jeffrey Czyz
4763612131
Make separate no-std version for invoice response
Both Refund::respond_with and InvoiceRequest::respond_with take a
created_at since the Unix epoch Duration in no-std. However, this can
cause problems if two downstream dependencies want to use the lightning
crate with different feature flags set. Instead, define
respond_with_no_std versions of each method in addition to a
respond_with version in std.
2023-02-03 15:23:33 -06:00
Jeffrey Czyz
3302f25e9f
Fix BOLT 12 invoice doctests to work with no-std 2023-02-03 15:14:58 -06:00
Matt Corallo
8ecd7c30c9
Merge pull request #1961 from TheBlueMatt/2023-01-expose-hist-buckets
Expose historical bucket data via new accessors
2023-01-31 00:38:14 +00:00
Matt Corallo
ccf9215762
Merge pull request #1972 from jkczyz/2023-01-bolt12-spec-updates
BOLT 12 spec updates
2023-01-30 23:36:20 +00:00
Matt Corallo
3f32f60ae7 Expose historical bucket data via new accessors
Users should be able to view the data we use to score channels, so
this exposes that data in new accessors.

Fixes #1854.
2023-01-30 22:32:06 +00:00
Matt Corallo
30060c18b3 Calc decayed buckets to decide if we have valid historical points
When we're calculating if, once we apply the unupdated decays, the
historical data tracker has enough data to assign a score, we
previously calculated the decayed points while walking the buckets
as we don't use the decayed buckets anyway (to avoid losing
precision). That is fine, except that as written it decayed
individual buckets additional times.

Instead, here we actually calculate the full set of decayed buckets
and use those to decide if we have valid points. This adds some
additional stack space and may in fact be slower, but will be
useful in the next commit and shouldn't be a huge change.
2023-01-30 22:32:06 +00:00
Jeffrey Czyz
22ea505348
Update docs regarding payment path privacy 2023-01-30 15:44:39 -06:00
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
Matt Corallo
437cc6960b
Merge pull request #1985 from Kurtsley/chore-no-std-phantom-invoice
Remove std::SystemTime from create_phantom_invoice, ref #1978
2023-01-30 21:01:51 +00:00
Kurtsley
afa0480487 Remove std::SystemTime from create_phantom_invoice, ref #1978
Replace current_timestamp call with no-std duration_from_epoch
2023-01-27 00:02:41 -06:00
Matt Corallo
d4de913ae7
Merge pull request #1974 from danielgranhao/speed-up-secure-random-byte-gen 2023-01-26 23:13:06 +00:00
Daniel Granhão
f19821dac4
Use Chacha20 in get_secure_random_bytes() 2023-01-26 20:58:00 +00:00
Matt Corallo
801d297f53
Merge pull request #1991 from TheBlueMatt/2023-01-fix-comment
Remove stale comment in test
2023-01-26 19:51:32 +00:00
Matt Corallo
21ae60b0d1
Merge pull request #1986 from TheBlueMatt/2023-01-monitor-eq
Implement PartialEq for ChannelMonitor
2023-01-26 19:11:49 +00:00
Matt Corallo
9b40e8f14e Remove stale comment in test
This should have been done in 7dcbf2cd1c
but was not.
2023-01-26 17:39:55 +00:00
Daniel Granhão
eedaf90259
Add get_secure_random_bytes() benchmark 2023-01-26 17:27:33 +00:00
Matt Corallo
8bc3428d5b
Merge pull request #1984 from TheBlueMatt/2023-01-test-robust
Make `test_duplicate_payment_hash_one_failure_one_success` robust
2023-01-26 04:02:31 +00:00
Matt Corallo
53bc6db64c Remove the ChannelMonitor secp context
`ChannelMonitor` indirectly already has a context - the
`OnchainTxHandler` has one. This makes it trivial to remove the
existing one, so we do so for a free memory usage reduction.
2023-01-26 02:23:16 +00:00
Matt Corallo
d9dfc16e4a Implement PartialEq for ChannelMonitor
It turns out `#[derive(PartialEq)]` will automatically bound the
`PartialEq` implementation by any bounds on the struct also being
`PartialEq`. This means to use an auto-derived `ChannelMonitor`
`PartialEq` the `EcdsaSigner` used must also be `PartialEq`, but
for the use-cases we have today for a `ChannelMonitor` `PartialEq`
it doesn't really matter - we use it internally in tests and
downstream users wanted similar test-only usage.

Fixes #1912.
2023-01-26 02:23:08 +00:00
valentinewallace
e2beaef41e
Merge pull request #1916 from valentinewallace/2022-11-chanman-payment-retries
`ChannelManager` Payment Retries
2023-01-25 21:09:13 -05:00
Matt Corallo
7dcbf2cd1c Make test_duplicate_payment_hash_one_failure_one_success robust
`test_duplicate_payment_hash_one_failure_one_success` currently
fails if the "wrong" HTLC is picked to be claimed. Given the HTLCs
are identical, there's no way to figure out which we should claim.
The test instead relies on a magic value - the first one is the
right one....unless we change our CSPRNG implementation. When we
try to do so, the test randomly fails.

Here we change one HTLC to a lower amount so we can figure out
which transaction to broadcast to make the test robust against
CSPRNG changes.
2023-01-26 01:59:21 +00:00
Matt Corallo
b536d01702 Implement PartialEq/Eq for Events 2023-01-26 01:52:10 +00:00
Matt Corallo
abbd295157
Merge pull request #1948 from alecchendev/custom-fail-back-err
Allow specifying an error when failing back HTLC
2023-01-25 23:24:49 +00:00
Matt Corallo
ca5b10884e
Merge pull request #1799 from TheBlueMatt/2022-10-heap-nerdsnipe
Router Optimizations
2023-01-25 23:19:13 +00:00
Alec Chen
48aef2da9e Add test_fail_htlc_backwards_with_reason
Add a test for newly added function failing back a basic payment
and ensuring the intended failure code and data are sent back
to the peer.
2023-01-25 15:36:04 -06:00
Alec Chen
95892e37da Add FailureCode enum and ChannelManager::fail_htlc_backwards_with_reason
FailureCode is used to specify which error code and data to send
to peers when failing back an HTLC.

ChannelManager::fail_htlc_backwards_with_reason
allows a user to specify the error code and
corresponding data to send to peers when failing back an HTLC.
This function is mentioned in Event::PaymentClaimable docs.
ChannelManager::get_htlc_fail_reason_from_failure_code was also
added to assist with this function.
2023-01-25 15:35:59 -06:00
Valentine Wallace
6d819796f2
Disambiguate send_payment_internal from pay_internal 2023-01-25 14:44:10 -05:00
Valentine Wallace
ad486a4596
Payment retries: copy tests from InvoicePayer
As part of migrating payment retries from InvoicePayer to ChannelManager,
several tests don't need a rewrite and can be pretty much copied and pasted.
2023-01-25 14:44:10 -05:00
Valentine Wallace
2f49c8170c
Test ChannelManager automatic retries 2023-01-25 14:44:10 -05:00
Valentine Wallace
acf9292d58
Support sending payments with a retry strategy in ChannelManager 2023-01-25 14:44:10 -05:00
Valentine Wallace
d776dee3a5
Retry HTLCs in process_pending_htlc_forwards 2023-01-25 14:44:07 -05:00
Valentine Wallace
72a7da8d51
Remove AllPathsFailed outbounds at send_payment_internal callsites instead
This makes it easier to retry payments if all paths fail on initial send, in
in which case we'll want to hold off on removing the pending payment
2023-01-25 14:44:07 -05:00
Valentine Wallace
686ef08316
Generate PendingHTLCsForwardable upon retryable payment 2023-01-25 14:44:07 -05:00
Valentine Wallace
6351a99935
Decode onion fail outside of outbound_payments lock
It's not ideal to do all this computation while the lock is held. We also want
to decode the failure *before* taking the lock, so we can store the failed scid
in the relevant outbound for retry in the next commit(s).
2023-01-25 14:44:07 -05:00
Valentine Wallace
c0a22f7174
Store retry data in PendingOutboundPayment::Retryable
Used in upcoming commit(s) to automatically retry HTLCs in ChannelManager
2023-01-25 14:44:03 -05:00
Matt Corallo
bde841e928 Clean up compute_fees and add a saturating variant
Often when we call `compute_fees` we really just want it to
saturate and we deal with `u64::max_value` later. In that case,
we're much better off doing the saturating in the `compute_fees` as
it can use CMOVs rather than branching at each step and then
`unwrap_or`ing at the callsite.
2023-01-25 18:58:51 +00:00
Matt Corallo
e64b5d9d2e Add a fuzzer to check that IndexedMap is equivalent to BTreeMap 2023-01-25 18:58:51 +00:00