Commit graph

3406 commits

Author SHA1 Message Date
Elias Rohrer
15b1c9b837
Merge pull request #2319 from valentinewallace/2023-05-forward-less-than-onion
Allow forwarding less than the amount in the onion
2023-06-21 09:25:07 +02:00
Matt Corallo
e49a1ba96d Ensure we build if a downstream crate sets --cfg=fuzzing
Downstream crates building fur fuzzing will usually set
`--cfg=fuzzing` as a side-effect of the Rust fuzzing tooling. Thus,
we should ensure we build without failure in such cases.

We do this here by simply relying on the `_test_utils` feature,
rather than conditionally-compiling in modules based on the
`fuzzing` flag.
2023-06-20 23:22:15 +00:00
Valentine Wallace
2127eb8a19
Document on claim events that amount_msat may be > invoice amount 2023-06-20 17:57:38 -04:00
Valentine Wallace
0d94d9f9b7
Check UpdateAddHTLC::skimmed_fee_msat on receive
Make sure the penultimate hop took the amount of fee that they claimed to take.
Without checking this TLV, we're heavily relying on the receiving wallet code
to correctly implement logic to calculate that that the fee is as expected.
2023-06-20 17:57:38 -04:00
Valentine Wallace
4cee62233c
Set UpdateAddHTLC::skimmed_fee_msat on forward
So the receiver can verify it and approve underpaying HTLCs (see
ChannelConfig::accept_underpaying_htlcs).
2023-06-20 17:57:38 -04:00
Valentine Wallace
5a79d6cc53
Persist update_add sender skimmed fee in Channel 2023-06-20 17:57:38 -04:00
Valentine Wallace
47567e45dc
Track the sender's skimmed fee in UpdateAddHTLC 2023-06-20 17:57:38 -04:00
Valentine Wallace
9a3914dee6
Allow receiving less than the onion claims to pay
Useful for penultimate hops in routes to take an extra fee, if for example they
opened a JIT channel to the payee and want them to help bear the channel open
cost.
2023-06-20 17:57:38 -04:00
Valentine Wallace
27b99acd64
Add PaymentClaimable::counterparty_skimmed_fee_msat
See its docs
2023-06-20 17:57:38 -04:00
Valentine Wallace
94853044fe
Persist counterparty skimmed fee in ClaimableHTLC
Used to get an accurate skimmed fee in the resulting PaymentClaimable event.
2023-06-20 17:57:38 -04:00
Valentine Wallace
52f290119d
Set extra skimmed fee on intercepted forward
Receivers need to use this value to verify incoming payments if
ChannelConfig::accept_underpaying_htlcs is set.
2023-06-20 17:57:38 -04:00
Valentine Wallace
85a5b31bb8
Add config knob for accepting underpaying HTLCs
See ChannelConfig::accept_underpaying_htlcs
2023-06-20 17:57:38 -04:00
Valentine Wallace
672d666ef4
Move next hop packet pubkey calculation to outside channel lock 2023-06-20 17:57:38 -04:00
Valentine Wallace
a2a7fef4d7
Move PendingHTLCStatus construction inside channel lock
We need the channel lock for constructing a pending HTLC's status because we
need to know if the channel accepts underpaying HTLCs in upcoming commits.
2023-06-20 17:57:35 -04:00
Matt Corallo
ba342de241
Merge pull request #2120 from valentinewallace/2023-03-blinded-pathfinding 2023-06-20 15:51:59 +00:00
Matt Corallo
c5214c2d06
Merge pull request #2089 from wpaulino/bump-transaction-event-handler
Add BumpTransaction event handler
2023-06-19 22:45:54 +00:00
Wilmer Paulino
bc39da678e
Provide a default CoinSelectionSource implementation via a new trait
Certain users may not care how their UTXOs are selected, or their wallet
may not expose enough controls to fully implement the
`CoinSelectionSource` trait. As an alternative, we introduce another
trait `WalletSource` they could opt to implement instead, which is much
simpler as it just returns the set of confirmed UTXOs that may be used.
This trait implementation is then consumed into a wrapper `Wallet` which
implements the `CoinSelectionSource` trait using a "smallest
above-dust-after-spend first" coin selection algorithm.
2023-06-19 14:05:46 -07:00
Wilmer Paulino
d4b6f8c08e
Add BumpTransaction event handler
This allows users to bump their commitments and HTLC transactions
without having to worry about all the little details to do so. Instead,
we'll just require that they implement the `CoinSelectionSource` trait
over their wallet/UTXO source, granting the event handler permission to
spend confirmed UTXOs for the transactions it'll produce.

While the event handler should in most cases produce valid transactions,
assuming the provided confirmed UTXOs are valid, it may not produce
relayable transactions due to not satisfying certain Replace-By-Fee
(RBF) mempool policy requirements. Some of these require that the
replacement transactions have a higher feerate and absolute fee than the
conflicting transactions it aims to replace. To make sure we adhere to
these requirements, we'd have to persist some state for all transactions
the event handler has produced, greatly increasing its complexity. While
we may consider implementing so in the future, we choose to go with a
simple initial version that relies on the OnchainTxHandler's bumping
frequency. For each new bumping attempt, the OnchainTxHandler proposes a
25% feerate increase to ensure transactions can propagate under
constrained mempool circumstances.
2023-06-19 14:05:45 -07:00
Wilmer Paulino
d5cbc6c261
Expose ClaimId for each claim bump in BumpTransactionEvent 2023-06-19 14:05:45 -07:00
Wilmer Paulino
537c34b7d6
Expose existing PackageID to API and rename to ClaimId
In a future commit, we plan to expand `BumpTransactionEvent` variants to
include the unique identifier assigned to pending output claims by the
`OnchainTxHandler` when a commitment is broadcast/confirmed. This
requires making it public in our API. We also choose to rename it to
`ClaimId` for the benefit of users, as the previous `PackageID` term
could be interpreted to be the ID of a BIP-331 transaction package.
2023-06-19 14:05:42 -07:00
Wilmer Paulino
ce962ad5c5
Change package ID computation for HTLC claims on anchor channels
While the previous way of computing the identifier was safe, it wouldn't
have been in certain scenarios if we considered splitting aggregated
packages. While this type of splitting has yet to be implemented, it may
come in the near future. To ensure we're prepared to handle such, we
opt to instead commit to all of the HTLCs to claim in the request.
2023-06-19 14:05:39 -07:00
Valentine Wallace
6c3ca554a4
Implement routing to blinded payment paths
Sending to them is still disallowed, for now.
2023-06-19 09:54:25 -04:00
Valentine Wallace
25a707314f
Router: clean up Path construction
We don't need to collect a vec of Results anymore.
2023-06-19 09:54:25 -04:00
Valentine Wallace
8344222173
Add CandidateRouteHop::Blinded and ::OneHopBlinded variant
It's unclear what values 1-hop blinded paths should set their BlindedPayInfos
to, because those values are meant to refer to the fees/cltv delta on the path
*between* the intro node and the destination. We zero out these values in the
new variant's methods so they don't mess with path finding/construction.
2023-06-19 09:54:25 -04:00
Valentine Wallace
b3a27acd0e
Update CandidateRouteHop::short_channel_id to be optional 2023-06-19 09:54:23 -04:00
Matt Corallo
c3c105075a
Merge pull request #2351 from TheBlueMatt/2023-04-remove-legacy-recv
Drop `create_inbound_payment*_legacy` breaking downgrade to 0.0.103
2023-06-17 18:38:25 +00:00
Valentine Wallace
be59d010f0
Routing: accommodate for blinded paths in used liquidity tracking 2023-06-16 11:14:58 -04:00
Valentine Wallace
a2918814f0
Replace max_channel_saturation_power_of_half hardcode with const 2023-06-16 11:14:58 -04:00
Valentine Wallace
6a54098dd1
Add utils for creating blinded PaymentParameters 2023-06-16 11:14:58 -04:00
Valentine Wallace
3184393df2
Reverse (BlindedPath, BlindedPayInfo) tuple order in offers invoice.
To make it uniform with PaymentParameters' Payee::Blinded::route_hints.
2023-06-16 11:14:53 -04:00
Duncan Dean
d957f362ff
Rename inbound_is_awaiting_accept() to is_awaiting_accept() 2023-06-15 22:31:41 +02:00
Duncan Dean
8f93e2dc94
Rename InboundV1Channel::new_from_req to InboundV1Channel::new 2023-06-15 22:31:40 +02:00
Duncan Dean
637e03a3de
Move inbound channel methods into InboundV1Channel's impl 2023-06-15 22:31:37 +02:00
Duncan Dean
4a0cd5cf55
Move outbound channel methods into OutboundV1Channel's impl 2023-06-15 22:20:14 +02:00
Duncan Dean
4b1e2865cf
Create and use methods for counting channels
This commit also adds two new maps to `PeerState` for keeping track
of `OutboundV1Channel`s and `InboundV1Channel`s so that further
commits are a bit easier to review.
2023-06-15 12:55:40 +02:00
Duncan Dean
4ad67cfe18
Refactor channel map update macros for use with ChannelContext 2023-06-15 12:55:37 +02:00
Duncan Dean
2ea27e02cd
Move Channel::force_shutdown to ChannelContext impl 2023-06-15 12:51:45 +02:00
Duncan Dean
baadeb7374
Move inbound channel constructor into InboundV1Channel impl 2023-06-15 12:51:44 +02:00
Duncan Dean
e6c2f04f15
Move outbound channel constructor into OutboundV1Channel impl 2023-06-15 12:51:43 +02:00
Duncan Dean
883e0566ef
Introduce InboundV1Channel & OutboundV1Channel 2023-06-15 12:51:34 +02:00
Duncan Dean
10125269d2
Move channel constants up 2023-06-14 16:04:30 +02:00
Duncan Dean
e3f0c55182
Make ChannelManager::issue_channel_close_events take a ChannelContext 2023-06-14 16:04:28 +02:00
Duncan Dean
25c1ad8e19
Convert ChannelDetails::from_channel to ChannelDetails::from_channel_context
This rename and refactor is so that we can get channel details from a
`ChannelContext` which is a common object to all channels.
2023-06-14 16:04:27 +02:00
Duncan Dean
60706d6338
Move Channel::get_available_balances to ChannelContext impl 2023-06-14 16:04:26 +02:00
Duncan Dean
9f4e71452a
Move Channel::next_*_commit_tx_fee_msat methods to ChannelContext impl 2023-06-14 16:04:25 +02:00
Duncan Dean
08ee72be9d
Move Channel::commit_tx_fee_msat to file-level utilities 2023-06-14 16:04:24 +02:00
Duncan Dean
ed6a5bb151
Move Channel::get_*_pending_htlc_stats to ChannelContext impl 2023-06-14 16:04:23 +02:00
Duncan Dean
2774aa26d9
Prepare some methods for upcoming moves to ChannelContext
To reduce interleaving in commits, we introduce a `context` variable
in methods to be moved in upcoming commits so there is minimal change
with the moves.
2023-06-14 16:04:22 +02:00
Duncan Dean
3ff94fae55
Move Channel::get_feerate_sat_per_1000_weight and other methods
This is one of a series of commits to make sure methods are moved by
chunks so they are easily reviewable in diffs. Unfortunately they are
not purely move-only as fields to be updated for things to
compile, but these should be quite clear.

This commit also uses the `context` field where needed for compilation
and tests to pass due to the above change.

f s/tarcontext.get_/target_/
2023-06-14 16:04:21 +02:00
Duncan Dean
0d739eeb22
Move Channel::build_holder_transaction_keys and some other methods
This is one of a series of commits to make sure methods are moved by
chunks so they are easily reviewable in diffs. Unfortunately they are
not purely move-only as fields need to be updated for things to
compile, but these should be quite clear.

This commit also uses the `context` field where needed for compilation
and tests to pass due to the above change.
2023-06-14 16:04:14 +02:00