Commit graph

3123 commits

Author SHA1 Message Date
Alec Chen
53c79711b4 Add PartialOrd, Ord to PaymentHash, PaymentPreimage for tests 2023-04-22 23:04:29 -05:00
Matt Corallo
bc54441424
Merge pull request #2212 from wpaulino/off-by-one-locktime
Fix off-by-one finalized transaction locktime
2023-04-22 21:54:06 +00:00
Wilmer Paulino
97e4344bea
Fix off-by-one finalized transaction locktime
While these transactions were still valid, we incorrectly assumed that
they would propagate with a locktime of `current_height + 1`, when in
reality, only those with a locktime strictly lower than the next height
in the chain are allowed to enter the mempool.
2023-04-22 11:16:32 -07:00
Wilmer Paulino
e904d68fa8
Catch up test nodes to latest block height
In a future commit, we plan to correctly enforce that the spending
transaction has a valid locktime relative to the chain for the node
broascasting it in `TestBroadcaster::broadcast_transaction` to. We catch
up these test node instances to their expected height, such that we do
not fail said enforcement.
2023-04-22 11:16:32 -07:00
Wilmer Paulino
69d0bfacd9
Use current height when generating claims on block_disconnected
The `height` argument passed to `OnchainTxHandler::block_disconnected`
represents the height being disconnected, and not the current height.
Due to the incorrect assumption, we'd generate a claim with a locktime
in the future.

Ultimately, we shouldn't be generating claims within
`block_disconnected`. Rather, we should retry the claim at a later block
height, since the bitcoin blockchain does not ever roll back without
connecting a new block. Addressing this is left for future work.
2023-04-22 11:16:28 -07:00
Matt Corallo
5f96d13344
Merge pull request #2199 from tnull/2023-04-fix-async-event-processing
Allow async events processing without holding `total_consistency_lock`
2023-04-22 01:45:06 +00:00
Wilmer Paulino
db123f74be
Implement pending claim rebroadcast on force-closed channels
This attempts to rebroadcast/fee-bump each pending claim a monitor is
tracking for a force-closed channel. This is crucial in preventing
certain classes of pinning attacks and ensures reliability if
broadcasting fails. For implementations of `FeeEstimator` that also
support mempool fee estimation, we may broadcast a fee-bumped claim
instead, ensuring we can also react to mempool fee spikes between
blocks.
2023-04-21 14:34:41 -07:00
Wilmer Paulino
e496d62b98
Extend OnchainTxHandler::generate_claim to optionally force feerate bump
In the next commit, we plan to extend the `OnchainTxHandler` to retry
pending claims on a timer. This timer may fire with much more frequency
than incoming blocks, so we want to avoid manually bumping feerates
(currently by 25%) each time our fee estimator provides a lower feerate
than before.
2023-04-21 14:34:40 -07:00
Valentine Wallace
b13163426a
Fix outbound_payment for new Path::blinded_tail 2023-04-21 15:35:08 -04:00
Valentine Wallace
5a6f9b0028
Account for Path::blinded_tail when adding a shadow cltv offset 2023-04-21 15:35:08 -04:00
Valentine Wallace
976411d984
Test scoring paths with blinded tails 2023-04-21 15:35:08 -04:00
Valentine Wallace
dac4a1cf1c
Account for Path::blinded_tail in InflightHtlcs::process_path 2023-04-21 15:35:08 -04:00
Valentine Wallace
2e51a1c803
Support (de)serializing Path::blinded_tails in HTLCSource 2023-04-21 15:35:08 -04:00
Valentine Wallace
c8fd77de25
Support (de)serializing Path::blinded_tails in Routes 2023-04-21 15:35:07 -04:00
Valentine Wallace
97a8c91564
Support (de)ser for Path::blinded_tails in events 2023-04-21 15:35:07 -04:00
Valentine Wallace
64c26c8a79
Add blinded path {metadata} fields to Path, but disallow paying blinded paths for now 2023-04-21 15:35:04 -04:00
Matt Corallo
49a366262c Clean up handshake timeout disconnection log message
It currently reads "disconnected from peer which hasn't completed
handshake due to ping timeout", which is confusing.

Instead, it will now read "disconnected from peer which hasn't
completed handshake due to ping/handshake timeout"
2023-04-21 17:18:04 +00:00
Elias Rohrer
f2453b7fff
Allow events processing without holding total_consistency_lock
Unfortunately, the RAII types used by `RwLock` are not `Send`, which is
why they can't be held over `await` boundaries. In order to allow
asynchronous events processing in multi-threaded environments, we here
allow to process events without holding the `total_consistency_lock`.
2023-04-21 18:02:54 +02:00
Valentine Wallace
d5b05e54c3
Replace Vec<RouteHop> with new Path struct
This lays groundwork for adding blinded path info to Path
2023-04-21 11:48:27 -04:00
Valentine Wallace
93afed56e8
Add utilities for getting a path's final value and cltv delta 2023-04-21 11:48:27 -04:00
Valentine Wallace
b5827f77ad
Minor Route/RouteHop doc updates 2023-04-21 11:48:24 -04:00
Matt Corallo
61c22c581d Clarify the error message when we disconnect a peer
We very regularly receive confusion over the super generic
"Peer sent invalid data or we decided to disconnect due to a
protocol error" message, which doesn't say very much. Usually, we
end up disconnecting because we have a duplicate connection with a
peer, which doesn't merit such a scary message.

Instead, here we clarify the error message to just refer to the
fact that we're disconnecting, and note that its usually a dup
connection in a parenthetical.
2023-04-21 14:39:01 +00:00
Matt Corallo
9d5adfcd10
Merge pull request #2205 from wpaulino/sign-ecdsa-with-noncedata
Generate local signatures with additional randomness
2023-04-20 21:53:13 +00:00
Wilmer Paulino
86531e5ceb
Use new feature to gate test vectors behind
To match the local signatures found in test vectors, we must make sure
we don't use any additional randomess when generating signatures, as
we'll arrive at a different signature otherwise.
2023-04-20 12:14:28 -07:00
Wilmer Paulino
16edbd4196
Sign gossip messages without grinding low R signatures
Gossip messages always use signatures in their compact form, so grinding
for low R signatures is unnecessary.
2023-04-20 12:14:24 -07:00
Wilmer Paulino
78b967f5b0
Generate local signatures with additional randomness
Previously, our local signatures would always be deterministic, whether
we'd grind for low R value signatures or not. For peers supporting
SegWit, Bitcoin Core will generally use a transaction's witness-txid, as
opposed to its txid, to advertise transactions. Therefore, to ensure a
transaction has the best chance to propagate across node mempools in the
network, each of its broadcast attempts should have a unique/distinct
witness-txid, which we can achieve by introducing random nonce data when
generating local signatures, such that they are no longer deterministic.
2023-04-20 12:14:21 -07:00
Wilmer Paulino
2c5bd1c56f
Implement EntropySource for InMemorySigner
This allows the `InMemorySigner` to produce its own randomness, which we
plan to use when generating signatures in future work.

We can no longer derive `Clone` due to the `AtomicCounter`, so we opt to
implement it manually.
2023-04-20 12:14:19 -07:00
Matt Corallo
a7600dcd58
Merge pull request #2206 from jkczyz/2023-04-invoice-description
Expose description from Invoice's offer/refund
2023-04-20 18:18:28 +00:00
Valentine Wallace
2a23b80c35
outbound_payment: remove unused cltv delta var 2023-04-20 10:14:17 -04:00
Valentine Wallace
6d6a86c92c
Extract read/write variants from impl_for_vec
We'll need to (de)serialize vecs of BlindedPaths differently based on whether
we're writing or reading
2023-04-20 10:14:17 -04:00
Valentine Wallace
ed4348f08a
Update PaymentParameters::route_hints for blinded paths 2023-04-20 10:14:17 -04:00
Valentine Wallace
e691e5077d
Update docs and method names for blinded payment paths 2023-04-20 10:14:17 -04:00
Valentine Wallace
efed905a4f
Move blinded_path and its utils into a new module 2023-04-20 10:14:15 -04:00
Jeffrey Czyz
42a772d675
Expose description from Invoice's offer/refund
This will allow clients like VLS to check the description for an invoice
as part of verification.
2023-04-20 08:41:07 -05:00
Matt Corallo
b8ed4d2608
Merge pull request #1989 from jkczyz/2023-01-stateless-offers
Stateless BOLT 12 message verification
2023-04-20 04:25:21 +00:00
Jeffrey Czyz
8afe694020
DRY up InvoiceFields construction 2023-04-19 21:31:08 -05:00
Jeffrey Czyz
c8a847ae11
Support responding to refunds with transient keys 2023-04-19 21:31:07 -05:00
Jeffrey Czyz
e1a6bc3cad
Extract keys from Offer::metadata to sign Invoice
For offers where the signing pubkey is derived, the keys need to be
extracted from the Offer::metadata in order to sign an invoice.
Parameterize InvoiceBuilder such that a build_and_sign method is
available for this situation.
2023-04-19 21:31:07 -05:00
Jeffrey Czyz
259aa9aac3
DRY up verification of invreq TLV records 2023-04-19 21:31:07 -05:00
Jeffrey Czyz
2298af4d0b
Stateless verification of Invoice for Refund
Stateless verification of Invoice for Offer

Verify that an Invoice was produced from a Refund constructed by the
payer using the payer metadata reflected in the Invoice. The payer
metadata consists of a 128-bit encrypted nonce and possibly a 256-bit
HMAC over the nonce and Refund TLV records (excluding the payer id)
using an ExpandedKey.

Thus, the HMAC can be reproduced from the refund bytes using the nonce
and the original ExpandedKey, and then checked against the metadata. If
metadata does not contain an HMAC, then the reproduced HMAC was used to
form the signing keys, and thus can be checked against the payer id.
2023-04-19 21:31:07 -05:00
Jeffrey Czyz
1a7540f2c9
Refund metadata and payer id derivation
Add support for deriving a transient payer id for each Refund from an
ExpandedKey and a nonce. This facilitates payer privacy by not tying any
Refund to any other nor to the payer's node id.

Additionally, support stateless Invoice verification by setting payer
metadata using an HMAC over the nonce and the remaining TLV records,
which will be later verified when receiving an Invoice response.
2023-04-19 21:31:07 -05:00
Jeffrey Czyz
022eadc4db
Stateless verification of Invoice for Offer
Verify that an Invoice was produced from an InvoiceRequest constructed
by the payer using the payer metadata reflected in the Invoice. The
payer metadata consists of a 128-bit encrypted nonce and possibly a
256-bit HMAC over the nonce and InvoiceRequest TLV records (excluding
the payer id) using an ExpandedKey.

Thus, the HMAC can be reproduced from the invoice request bytes using
the nonce and the original ExpandedKey, and then checked against the
metadata. If metadata does not contain an HMAC, then the reproduced HMAC
was used to form the signing keys, and thus can be checked against the
payer id.
2023-04-19 21:31:07 -05:00
Jeffrey Czyz
9bd43e077f
Fix builder docs in offers module 2023-04-19 21:31:06 -05:00
Jeffrey Czyz
3880e69237
InvoiceRequest metadata and payer id derivation
Add support for deriving a transient payer id for each InvoiceRequest
from an ExpandedKey and a nonce. This facilitates payer privacy by not
tying any InvoiceRequest to any other nor to the payer's node id.

Additionally, support stateless Invoice verification by setting payer
metadata using an HMAC over the nonce and the remaining TLV records,
which will be later verified when receiving an Invoice response.
2023-04-19 21:31:06 -05:00
Jeffrey Czyz
e15044b889
Refactor InvoiceRequestContents fields into a sub-struct
InvoiceRequestBuilder has a field containing InvoiceRequestContents.
When deriving the payer_id from the remaining fields, a struct is needed
without payer_id as it not optional. Refactor InvoiceRequestContents to
have an inner struct without the payer_id such that
InvoiceRequestBuilder can use it instead.
2023-04-19 21:31:06 -05:00
Jeffrey Czyz
dd2ccd2322
Stateless verification of InvoiceRequest
Verify that an InvoiceRequest was produced from an Offer constructed by
the recipient using the Offer metadata reflected in the InvoiceRequest.
The Offer metadata consists of a 128-bit encrypted nonce and possibly a
256-bit HMAC over the nonce and Offer TLV records (excluding the signing
pubkey) using an ExpandedKey.

Thus, the HMAC can be reproduced from the offer bytes using the nonce
and the original ExpandedKey, and then checked against the metadata. If
metadata does not contain an HMAC, then the reproduced HMAC was used to
form the signing keys, and thus can be checked against the signing
pubkey.
2023-04-19 21:30:40 -05:00
Jeffrey Czyz
b2e87ff25b
TlvStream range iterator
Add an iterator that yields TlvRecords over a range of a TlvStream.
Useful for verifying that, e.g., an InvoiceRequest was sent in response
to an Offer constructed by the intended recipient.
2023-04-19 21:08:05 -05:00
Jeffrey Czyz
1cad430e14
Offer metadata and signing pubkey derivation
Add support for deriving a transient signing pubkey for each Offer from
an ExpandedKey and a nonce. This facilitates recipient privacy by not
tying any Offer to any other nor to the recipient's node id.

Additionally, support stateless Offer verification by setting its
metadata using an HMAC over the nonce and the remaining TLV records,
which will be later verified when receiving an InvoiceRequest.
2023-04-19 21:06:37 -05:00
Wilmer Paulino
a3b416a32c
Make PackageTemplate::height_timer non-optional
Now that we leverage a package's `height_timer` even for untractable
packages, there's no need to have it be an `Option` anymore. We aim to
not break compatibility by keeping the deserialization of such as an
`option`, and use the package's `height_original` when not present. This
allows us to retry packages from older `ChannelMonitor` versions that
have had a failed initial package broadcast.
2023-04-19 16:49:37 -07:00
Wilmer Paulino
4828817f3f
Use existing height timer to retry untractable packages
Untractable packages are those which cannot have their fees updated once
signed, hence why they weren't retried. There's no harm in retrying
these packages by simply re-broadcasting them though, as the fee market
could have spontaneously spiked when we first broadcast it, leading to
our transaction not propagating throughout node mempools unless
broadcast manually.
2023-04-19 16:49:35 -07:00