Commit graph

2014 commits

Author SHA1 Message Date
Matt Corallo
5a8ede09fb Expose counterparty-revoked-outputs in get_claimable_balance
This uses the various new tracking added in the prior commits to
expose a new `Balance` type - `CounterpartyRevokedOutputClaimable`.

Some nontrivial work is required, however, as we now have to track
HTLC outputs as spendable in a transaction that comes *after* an
HTLC-Success/HTLC-Timeout transaction, which we previously didn't
need to do. Thus, we have to check if an
`onchain_events_awaiting_threshold_conf` event spends a commitment
transaction's HTLC output while walking events. Further, because
we now need to track HTLC outputs after the
HTLC-Success/HTLC-Timeout confirms, and because we have to track
the counterparty's `to_self` output as a contentious output which
could be claimed by either party, we have to examine the
`OnchainTxHandler`'s set of outputs to spend when determining if
certain outputs are still spendable.

Two new tests are added which test various different transaction
formats, and hopefully provide good test coverage of the various
revoked output paths.
2022-08-16 01:06:00 +00:00
Matt Corallo
f712eb4157 Simplify claimable balance trivially with consistent accessors 2022-08-15 23:18:12 +00:00
Matt Corallo
a17794c380 Scan onchain_events_awaiting_threshold_conf once in balance calc
Instead of a series of different
`onchain_events_awaiting_threshold_conf.iter()...` calls to scan
for HTLC status in balance calculation, pull them all out into one
`for ... { match ... }` to do it once and simplify the code
somewhat.
2022-08-15 23:18:12 +00:00
Matt Corallo
04d8f5e3f1 Track the txid that resolves HTLCs even after resolution completes
We need this information when we look up if we still need to spend
a revoked output from an HTLC-Success/HTLC-Timeout transaction for
balance calculation.
2022-08-15 23:18:12 +00:00
Matt Corallo
9469ce0f38 Track HTLC-Success/HTLC-Timeout claims of revoked outputs
When a counterparty broadcasts a revoked commitment transaction,
followed immediately by HTLC-Success/-Timeout spends thereof, we'd
like to have an `onchain_events_awaiting_threshold_conf` entry
for them.

This does so using the `HTLCSpendConfirmation` entry, giving it
(slightly) new meaning. Because all existing uses of
`HTLCSpendConfirmation` already check if the relevant commitment
transaction is revoked first, this should be trivially backwards
compatible.

We will ultimately figure out if something is being spent via the
`OnchainTxHandler`, but to do so we need to look up the output via
the HTLC transaction txid, which this allows us to do.
2022-08-15 23:18:12 +00:00
Matt Corallo
e76ac33330 Fix off-by-one in test_onchain_htlc_claim_reorg_remote_commitment
The test intended to disconnect a transaction previously connected
but didn't disconnect enough blocks to do so, leading to it
confirming two conflicting transactions.

In the next few commits this will become an assertion failure.
2022-08-15 23:18:12 +00:00
Matt Corallo
66ced68ec6 Clean up nesting in get_counterparty_output_claim_info 2022-08-15 23:18:12 +00:00
Matt Corallo
0ec54ecd97 Track counterparty payout info in counterparty commitment txn
When handling a revoked counterparty commitment transaction which
was broadcast on-chain, we occasionally need to look up which
output (and its value) was to the counterparty (the `to_self`
output). This will allow us to generate `Balance`s for the user for
the revoked output.
2022-08-15 23:18:11 +00:00
Matt Corallo
9115f66dbc Store the full event transaction in OnchainEvent structs
When we see a transaction which generates some `OnchainEvent`, its
useful to have the full transaction around for later analysis.
Specifically, it lets us check the list of outputs which were spent
in the transaction, allowing us to look up, e.g. which HTLC
outpoint was spent in a transaction.

This will be used in a few commits to do exactly that - figure out
which HTLC a given `OnchainEvent` corresponds with.
2022-08-15 23:17:22 +00:00
Matt Corallo
4005724ae6
Merge pull request #1663 from tnull/2022-08-drop-register-output-return
Drop return value from `Filter::register_output`
2022-08-15 23:10:32 +00:00
Elias Rohrer
c562f3338b Clarify 'should' vs 'will' in get_relevant_txids 2022-08-15 20:55:37 +02:00
Elias Rohrer
2f4457fd7e Drop return value from Filter::register_output
This commit removes the return value from `Filter::register_output` as
creating a suitable value almost always entails blocking operations
(e.g., lookups via network request), which however conflicts with the
requirement that user calls should avoid blocking calls at all cost.

Removing the return value also rendered quite a bit of test code for
dependent transaction handling superfluous, which is therefore also
removed with this commit.
2022-08-15 20:47:33 +02:00
valentinewallace
ca4e31d751
Merge pull request #1659 from valentinewallace/2022-08-fix-payload-decode
Fix payment onion payload decode
2022-08-15 14:32:47 -04:00
Valentine Wallace
dfbebbf4c3
Rename HighZeroBytesDroppedVarInt to HighZeroBytesDroppedBigSize
As observed by @wpaulino, this struct encodes its bytes as big-endian,
therefore it's a BigSize, not a VarInt.
2022-08-15 11:41:59 -04:00
Valentine Wallace
a23681fde1
Fix bug in onion payment payload decode
Prior to this change, we could have failed to decode a valid payload of size
>253. This is because we were decoding the length (a BigSize, big-endian) as a
VarInt (little-endian).

Found in #1652.
2022-08-15 11:41:56 -04:00
Matt Corallo
b414c0641b
Merge pull request #1658 from lightning-signer/2022-08-bitcoin-0-29
Update bitcoin crate to 0.29.0
2022-08-12 23:51:06 +00:00
Devrandom
11166aa836 Modify ecdh to take Scalar 2022-08-11 00:21:26 +02:00
Devrandom
7e05623bef Update bitcoin crate to 0.29.0 2022-08-11 00:21:26 +02:00
valentinewallace
d2191d9c6d
Merge pull request #1655 from valentinewallace/2022-08-fix-ci-doc-links-check
Fix CI to error on doc links to private items
2022-08-09 12:49:40 -04:00
Valentine Wallace
c242003dd3
Fix CI to error on doc links to private items
Somehow we weren't doing this.
2022-08-07 13:49:12 -04:00
Valentine Wallace
dcef41d17b
Minor msgs::OnionHopData cleanups 2022-08-05 22:34:36 -04:00
Matt Corallo
fc771d3b20 [C Bindings] Expose channel and nodes list in ReadOnlyNetworkGraph 2022-08-05 21:14:36 +00:00
Matt Corallo
b4521f52e2
Merge pull request #1638 from ViktorTigerstrom/2022-07-update-decode-update-add-htlc-onion-return-parameters
Don't return `channel_state` from `decode_update_add_htlc_onion`
2022-08-03 17:44:46 +00:00
Matt Corallo
736c0b9e7f
Merge pull request #1619 from G8XSU/main
Add config support for 'their_channel_reserve_proportional_millionths' [#1498]
2022-08-03 17:37:51 +00:00
Matt Corallo
28c9b56113
Merge pull request #1503 from valentinewallace/2022-05-onion-msgs
Onion messages v1
2022-08-03 04:39:56 +00:00
Valentine Wallace
17ec697f8f
Fix possible incomplete read bug on onion packet decode
Pre-existing to this PR, we were reading next packet bytes with io::Read::read,
which is not guaranteed to read all the bytes we need, only guaranteed to read
*some* bytes.

We fix this to be read_exact, which is guaranteed to read all the next hop
packet bytes.
2022-08-02 19:19:39 -04:00
Valentine Wallace
39397d4e14
Error when attempting to send an OM to a blinded route with 0 hops 2022-08-02 19:19:39 -04:00
Valentine Wallace
6500c99f29
Add SendError enum for onion messages and error on too-big packets 2022-08-02 19:19:39 -04:00
Valentine Wallace
eaff561e24
Add test utilities and integration tests for onion messages 2022-08-02 19:19:39 -04:00
Valentine Wallace
b26fb851cd
Significantly expand onion message documentation 2022-08-02 19:19:39 -04:00
Valentine Wallace
bf007ea763
Implement receiving and forwarding onion messages
This required adapting `onion_utils::decode_next_hop` to work for both payments
and onion messages.

Currently we just print out the path_id of any onion messages we receive. In
the future, these received onion messages will be redirected to their
respective handlers: i.e. an invoice_request will go to an InvoiceHandler,
custom onion messages will go to a custom handler, etc.
2022-08-02 19:19:37 -04:00
Valentine Wallace
9051c38ebe
Support sending onion messages
This adds several utilities in service of then adding
OnionMessenger::send_onion_message, which can send to either an unblinded
pubkey or a blinded route. Sending custom TLVs and sending an onion message
containing a reply path are not yet supported.

We also need to split the construct_keys_callback macro into two macros to
avoid an unused assignment warning.
2022-08-02 19:17:27 -04:00
Valentine Wallace
4c8dc2c2a0
Add baseline OnionMessenger and msgs::OnionMessage and its serialization
OnionMessenger will be hooked up to the PeerManager to send and receive OMs in
a follow-up PR.
2022-08-02 19:17:26 -04:00
Valentine Wallace
6017379b8e
KeysInterface: add new ecdh method
This method will help us avoid retrieving our node secret, something we want to
get rid of entirely.  It will be used in upcoming commits when decoding the
onion message packet, and in future PRs to help us get rid of
KeysInterface::get_node_secret usages across the codebase
2022-08-02 19:17:23 -04:00
Valentine Wallace
33ff2746ef
Add onion_message::Packet and adapt construct_onion_packet_with_init_noise for it
We need to add a new Packet struct because onion message packet hop_data fields
can be of variable length, whereas regular payment packets are always 1366
bytes.

Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
Co-authored-by: Jeffrey Czyz <jkczyz@gmail.com>
2022-08-02 19:17:19 -04:00
Gursharan Singh
092d1c1f0d Add config support for 'their_channel_reserve_proportional_millionths' [#1498]
It is proportion of the channel value to configure as the
`their_channel_reserve_satoshis` for both outbound and inbound channels.
It decides the minimum balance that the other node has to maintain on their
side, at all times.
2022-08-02 14:33:01 -07:00
Viktor Tigerström
65e6fb7467 Don't return channel_state from decode_update_add_htlc_onion
Currently `decode_update_add_htlc_onion` returns the `channel_state`
lock to ensure that `internal_update_add_htlc` holds a single
`channel_state` lock in when the entire function execution. This is
unnecessary, and since we are moving the channel storage to the
`per_peer_state`, this no longer achieves the goal it was intended for.

We therefore avoid returning the `channel_state` from
`decode_update_add_htlc_onion`, and just retake the lock in
`internal_update_add_htlc` instead.
2022-08-02 23:16:17 +02:00
Valentine Wallace
4e5381a50f
Add onion messages module + enable the construction of blinded routes
Blinded routes can be provided as destinations for onion messages, when the
recipient prefers to remain anonymous.

We also add supporting utilities for constructing blinded path keys, and
control TLVs structs representing blinded payloads prior to being
encoded/encrypted. These utilities and struct will be re-used in upcoming
commits for sending and receiving/forwarding onion messages.

Finally, add utilities for reading the padding from an onion message's
encrypted TLVs without an intermediate Vec.
2022-08-02 12:11:11 -04:00
Matt Corallo
018a78328e
Merge pull request #1635 from TheBlueMatt/2022-07-accessor-pub
Expose `ChannelMonitor::get_counterparty_node_id`
2022-07-27 18:46:52 +00:00
Matt Corallo
6b1ec5c738
Merge pull request #1632 from TheBlueMatt/2022-07-warnings
Fix compilation warnings
2022-07-27 16:29:09 +00:00
Matt Corallo
75b111291f Expose ChannelMonitor::get_counterparty_node_id
This fixes an oversight in ac842ed9dd
namely that it left users unable to implement their own
`ChainMonitor` from outside of the `rust-lightning` crate.
2022-07-27 03:53:47 +00:00
Matt Corallo
e10dfe4fd0 Bump crate versions to 0.0.110/invoice 0.18 2022-07-26 22:01:09 +00:00
Matt Corallo
10aa4aa42f Fix new compilation warnings in debug_sync module 2022-07-26 20:29:36 +00:00
Duncan Dean
b2a2b1fb02
Specify why flags for channel_disabled error are zero
We can remove the TODO for this and specify why the flags are zero
as it's now fully specified in BOLT 4.

See https://github.com/lightning/bolts/blob/341ec84/04-onion-routing.md?plain=1#L1008
2022-07-26 10:29:12 +02:00
Jeffrey Czyz
f0b818952b
Merge pull request #1403 from jurvis/jurvis/add-paymentforwardingfailed-event
Add HTLCHandlingFailed event
2022-07-25 19:23:53 -05:00
Matt Corallo
61b0a904da
Merge pull request #1617 from TheBlueMatt/2022-07-base-ppm
Add a per-amount base penalty in the ProbabilisticScorer
2022-07-25 22:02:10 +00:00
Matt Corallo
79b55f0815
Merge pull request #1626 from TheBlueMatt/2022-07-fix-pm-docs
Remove scary disconenct warnings on PeerManager new connection fns
2022-07-25 21:56:40 +00:00
Matt Corallo
d8cca9806c
Merge pull request #1611 from TheBlueMatt/2022-07-lower-bounded-estimator-nit
Use a separate (non-trait) fee-estimation fn in LowerBoundedEstimator
2022-07-25 21:11:07 +00:00
Matt Corallo
1988cb22cc
Merge pull request #1519 from tnull/2022-06-require-htlc-max
Make `htlc_maximum_msat` a required field.
2022-07-25 21:04:54 +00:00
Matt Corallo
7f80972e1f Rename amount penalty to liquidity_penalty_amount_multiplier_msat
This makes our `ProbabilisticScorer` field names more consistent,
as we add more types of penalties, referring to a penalty as only
the "amount penalty" no longer makes sense - we not have several
amount multiplier penalties.
2022-07-25 19:22:24 +00:00