benthecarman [Fri, 2 Feb 2024 14:14:51 +0000 (14:14 +0000)]
Make DirectedChannelInfo `source` and `target` public
We use these params for our HubPreferentialScorer and without these
utility functions then we have to manually do this and calculate which
is the source and which is the target node.
Elias Rohrer [Mon, 29 Jan 2024 15:16:08 +0000 (16:16 +0100)]
Expose `skimmed_fee_msat` in `PaymentForwarded`
We generally allow routing nodes to forward less than the expected HTLC
amount, if the receiver knowingly accepts this and claims the
underpaying HTLC (see `ChannelConfig::accept_underpaying_htlcs`). This
use case is in particular useful for the LSPS2/JIT channel setting where
the intial underpaying HTLC pays for the channel open.
While we previously exposed the withheld amount as
`PaymentClaimable::counterparty_skimmed_fee_msat` on the receiver side,
we did not individually provide it on the forwarding node's side.
Here, we therefore expose this additionally withheld amount via
`PaymentForwarded::skimmed_fee_msat`.
shaavan [Wed, 31 Jan 2024 12:14:58 +0000 (17:44 +0530)]
Add tests to check the introduced behaviour
- The first test make sure that the OutboundV1Channel is not
immediately removed when peers disconnect, but is removed after N timer
ticks.
- The second test makes sure that the SendOpenChannel is rebroadcasted
for the OutboundV1Channel if peer reconnects within time.
shaavan [Sun, 10 Dec 2023 12:47:32 +0000 (18:17 +0530)]
Do not remove Outbound Channel immediately when peer disconnects
- Do not remove channel immediately when peer_disconnect, instead
removed it after some time if peer doesn't reconnect soon (handled in
previous commit).
- Do not mark per ok_to_remove if we have some OutboundV1Channels too.
- Rebroadcast SendOpenChannel for outboundV1Channel when peer
reconnects.
- Update the relevant tests to account for the behavior change.
- Repurpose the test_disconnect_in_funding_batch to test that all
channels in the batch close when one them closes.
Duncan Dean [Tue, 9 Jan 2024 07:07:01 +0000 (09:07 +0200)]
Remove `Outpoint::to_channel_id` method
To avoid confusion and for accuracy going forward, we remove this method
as it is inconsistent with channel IDs generated during V2 channel
establishment. If one wants to create a V1, funding outpoint-based
channel ID, then `ChannelId::v1_from_funding_outpoint` should be used
instead.
A large portion of the library has always made the assumption that having
the funding outpoint will always allow us to generate the channel ID.
This will not be the case anymore and we need to pass the channel ID along
where appropriate. All channels that could have been persisted up to this
point could only have used V1 establishment, so if some structures don't
store a channel ID for them they can safely fall back to the funding
outpoint-based version.
Jeffrey Czyz [Thu, 18 Jan 2024 21:34:19 +0000 (15:34 -0600)]
Fix panic when peer is mid-handshake
Peer::their_node_id is set to Some during the handshake process.
However, df3ab2ee2753e7f9ec02ddf1c8a51db77c50e35d accesses the field
unconditionally, causing a panic. This may be triggered if a gossip
message is received mid-handshake from another peer or if the user calls
broadcast_node_announcement during this time. The latter tends to be
executed on a timer.
Ensure that Peer::their_node_id is only accessed once the handshake is
complete.
Matt Corallo [Mon, 22 Jan 2024 20:26:32 +0000 (20:26 +0000)]
Fix deadlock when handling bad calls to `batch_funding.._generated`
When handling calls to `batch_funding_transaction_generated` which
were missing outputs for one of the batch channels, we'd previously
deadlock when trying to clean up the now-closed channels. This
fixes that and adds a new test case for it.
Jeffrey Czyz [Thu, 11 Jan 2024 19:13:12 +0000 (13:13 -0600)]
Use consistent cltv_expiry_delta in ForwardTlvs
When converting from CounterpartyForwardingInfo to PaymentRelay, the
cltv_expiry_delta is copied. Then, when forming a blinded payment path,
the value is mutated so that esoteric values don't reveal information
about the path. However, the value was only used in computing
PaymentConstraints and wasn't actually updated in PaymentRelay. Move the
logic for modifying the cltv_expiry_delta to the conversion code to
avoid this inconsistency.
Fix sender double-including shadow offset in CLTV expiry height.
The excess delta is included in the final RouteHop::cltv_expiry_delta, so by
adding it explicitly to cur_cltv we were erroneously including it twice in the
total cltv expiry.
This could've add up to an extra MAX_SHADOW_CLTV_DELTA_OFFSET (432) blocks to
the total cltv expiry.
Matt Corallo [Mon, 15 Jan 2024 01:25:10 +0000 (01:25 +0000)]
Move cryptographic algorithms and utilities to a new `crypto` mod
As we'd generally like the `lightning` crate to, over time, have
more modules rather than being very monolithic, we should move the
cryptographic things into their own module, which we do here.
We also take this opportunity to move stream adapters into their
own module and make clear that the ChaChaPoly `decrypt` method is
variable time.
Jeffrey Czyz [Tue, 31 Oct 2023 19:27:29 +0000 (14:27 -0500)]
Functional tests for BOLT 12 Offers payment flow
ChannelManager provides utilities to create offers and refunds along
with utilities to initiate and request payment for them, respectively.
It also manages the payment flow via implementing OffersMessageHandler.
Test that functionality, including the resulting event generation.
Jeffrey Czyz [Thu, 4 Jan 2024 16:30:51 +0000 (10:30 -0600)]
Remove "no-std" feature checks
An upcoming rust-bitcoin release will remove the "no-std" feature.
Replace "no-std" in feature checks with "std", negating as needed. Using
a single feature flag makes the checks more consistent across modules.
Jeffrey Czyz [Thu, 14 Dec 2023 16:25:10 +0000 (10:25 -0600)]
Have TestRouter wrap DefaultRouter
TestRouter checks route and scoring expectations before delegating to
the standalone find_route function. Refactor it to wrap DefaultRouter
and delegate to it instead. This allows TestRouter to implement
create_blinded_payment_paths by delegating to DefaultRouter.
Jeffrey Czyz [Fri, 27 Oct 2023 18:27:55 +0000 (13:27 -0500)]
Support OnionMessenger in functional_test_utils
OnionMessenger is needed to write functional tests for ChannelManager's
OffersMessageHandler implementation. Also adds a TestMessageRouter,
which simply wraps DefaultMessageRouter for now.
Jeffrey Czyz [Wed, 3 Jan 2024 21:41:00 +0000 (15:41 -0600)]
DRY up EntropySource implementation
The ChaCha20-based EntropySource implementation is duplicated within the
sign module. Refactor those into a RandomBytes implementation so that it
may be reused both there. Also useful as a standalone EntropySource
implementation for tests where an independent EntropySource is needed to
ensure that backwards-compatibility testing is not broken.
Jeffrey Czyz [Wed, 1 Nov 2023 18:12:44 +0000 (13:12 -0500)]
Add peel_onion_message method to OnionMessenger
When testing OnionMessenger in functional tests, it would be useful to
examine the contents of an OnionMessage response. Expose the standalone
peel_onion_message on OnionMessenger to facilitate this.
Previously, we were setting the final blinded hop's CLTV expiry height to
best_block_height + total_blinded_path_cltv_delta + shadow_cltv_offset. This is
incorrect, it should instead be set to best_block_height + shadow_cltv_offset
only -- it doesn't make sense to include the delta for the other blinded hops
in the final hop's expiry.
The reason this too-high final cltv value didn't cause test failures previously
is because of a 2nd bug that is fixed in an upcoming commit where the sender
adds the shadow offset twice to the total path CLTV expiry. This 2nd offset
meant that intermediate nodes had some buffer CLTV to subtract their delta from
while still (usually) have enough leftover to meet the expiry in the final hop's
onion.