Skip to content

Client trusts lsp #572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

martinsaposnic
Copy link

@martinsaposnic martinsaposnic commented Jun 9, 2025

Please just review the second commit 53a8174. The first commit is just compatibility changes so it works with rust-lightning

This PR uses the functionality introduced in this other PR lightningdevkit/rust-lightning#3838, and creates 2 tests that demonstrates the feature

Changes:

  • call store_funding_transaction when funding transaction is created
  • call channel_needs_manual_broadcast to check if it needs to call funding_transaction_generated_manual_broadcast or funding_transaction_generated
  • call lsps2_funding_tx_broadcast_safe when FundingTxBroadcastSafe is emitted
  • a refactor on PaymentClaimable so it does not autoclaim (this will be changed in a future commit)
  • a new fn receive_via_jit_channel_manual_claim so the client can actually do a manual claim with claim_for_hash, instead of auto claiming
  • two beautiful tests that check the functionality
    • lsps2_client_trusts_lsp checks that the funding_tx is not broadcasted until the htlc is claimed
    • lsps2_lsp_trusts_client_but_client_does_not_claim checks that the funding_tx is broadcasted even though the client didn't claim the htlc

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Jun 9, 2025

👋 I see @tnull was un-assigned.
If you'd like another reviewer assignemnt, please click here.

@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

src/event.rs Outdated
"Failed to process funding transaction: {:?}",
err
self.liquidity_source.as_ref().map(|ls| {
ls.lsps2_store_funding_transaction(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we always need to store the funding transaction, even if we're not doing the full flow?

Copy link
Author

@martinsaposnic martinsaposnic Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it to inside the if statement, so it will store it only if needs_manual_broadcast is true 👍

src/event.rs Outdated
return Err(ReplayEvent());
},
};
self.payment_store.update(&update).map_err(|e| {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of unrelated changes happening in this commit. a) not sure if I agree that they are worth doing at all but b) always try to keep such changes in separate commits please.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that, I made a rebase and a cleanup. now this commit 53a8174 will have the minimal changes to make the client_trusts_lsp flow work

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of unrelated changes happening in this commit.

This was a refactor on the PaymentClaimable event to make the manual claim work on my tests.

That part is removed after the rebase, so we should be good now

@martinsaposnic martinsaposnic requested a review from tnull June 16, 2025 19:49
@martinsaposnic martinsaposnic marked this pull request as ready for review June 17, 2025 14:29
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 2nd Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 3rd Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 4th Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@tnull
Copy link
Collaborator

tnull commented Jun 26, 2025

cc @johncantrell97 as he previously looked into this and might be interested in reviewing/and or might have additional thoughts.

@tnull tnull removed their request for review June 26, 2025 12:13
Copy link
Contributor

@enigbe enigbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have partially reviewed 53a81743 (pending tests) and found it helpful in clarifying my understanding of LSPs. I have some initial comments/questions regarding the following:

client_trusts_lsp configuration

  • client_trusts_lsp is configured statically but I have assumed that based on blip52, this could (should?) be dynamically configured without restarting the node when it detects an attack.
  • Given the current implementation, what happens to in-flight outbound JIT channels (whose clients are awaiting funding transactions to be broadcast) during a trust mode transition, i.e. lsp_trusts_client to client_trusts_lsp?

error silencing

I don't fully understand why possible APIMisuseError relating to channel_needs_manual_broadcast is silenced/ignored with unwrap_or(false). Should we proceed with funding if we can't, for example, associate a channel with the user_channel_id?

src/liquidity.rs Outdated
@@ -134,6 +133,8 @@ pub struct LSPS2ServiceConfig {
pub min_payment_size_msat: u64,
/// The maximum payment size that we will accept when opening a channel.
pub max_payment_size_msat: u64,
/// Use the client trusts lsp model
pub client_trusts_lsp: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to understand the client_trusts_lsp configuration here. According to bLIP-52, I expect the LSP to dynamically switch from lsp_trusts_client to client_trusts_lsp mode upon detecting an attack, without requiring a restart.
However, this configuration appears to be static and set at node startup. If that's the case, what happens when:

  1. A node initially running in lsp_trusts_client mode detects an attack
  2. The node restarts with client_trusts_lsp: true to switch modes
  3. There's an existing outbound JIT channel where the client expects the LSP to broadcast the funding transaction before sending the preimage to claim.

What are the potential consequences for that in-flight JIT channel during the mode transition?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just pushed a fixup that makes the flag dynamic

There's an existing outbound JIT channel where the client expects the LSP to broadcast the funding transaction before sending the preimage to claim.

I just posted a question about this https://discord.com/channels/915026692102316113/994015949176963183/1397280758196080660

my current interpretation about this is that once lsps2.buy succeeds, that flag is part of the contract for this flow. the LSP can always abort and make you start over, but it cannot change the trust model mid negotiation

we will see what they respond on discord

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my current interpretation about this is that once lsps2.buy succeeds, that flag is part of the contract for this flow. the LSP can always abort and make you start over, but it cannot change the trust model mid negotiation

I created a test that shows how this works (test lsps2_in_flight_under_attack_switch)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my current interpretation about this is that once lsps2.buy succeeds, that flag is part of the contract for this flow. the LSP can always abort and make you start over, but it cannot change the trust model mid negotiation

Yes, as also noted on Discord, I agree with that interpretation and even think that for now we can leave the flag to be statically determined at startup.

src/liquidity.rs Outdated
if let Some(handler) = lsps2_service_handler {
handler
.channel_needs_manual_broadcast(user_channel_id, &counterparty_node_id)
.unwrap_or(false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure about unwrap_or here. I think we should log the error and be concerned about its cause if channel_needs_manual_broadcast returns an APIError::APIMisuseError? Say we couldn't find a channel mapped to the provided user_channel_id, should we still go on to call channel_manager.funding_transaction_generated for a non-existent channel when handling FundingGenerationReady? I am confused about this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also fixed in commit 2cc5267

thank you for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants