Skip to content
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

Sanity check max htlc amount msat #246

Merged
merged 2 commits into from
Sep 28, 2023

Conversation

YusukeShimizu
Copy link
Contributor

@YusukeShimizu YusukeShimizu commented Sep 21, 2023

Fixes #81

  • check the channel's max htlc limit
    Added logic to check the maximum htlc limit set per node for each channel.
    In cln, max htlc amt is not affect, so checks are only performed when the sender is lnd.
    receivable amount depends on whether the node is a cln or a lnd, so max htlc amt is not taken into account.
    Also, since the max htlc limit is not always set reliably, the check is skipped if it is not set.

  • add sanity check of spendable amt at swap_out_agreement

@YusukeShimizu YusukeShimizu force-pushed the max-htlc-sanity-check branch 2 times, most recently from 2963d6e to 6d6ae59 Compare September 21, 2023 07:18
Added logic to check the maximum htlc limit
set per node for each channel.

In cln, max htlc amt is only taken into account when foward,
so checks are only performed when the sender is lnd.
Receivable amount depends on whether the destination
node is a cln or a lnd, so max htlc amt is not taken into account.

Also, since the max htlc limit is not always set reliably,
the check is skipped if it is not set.
@YusukeShimizu YusukeShimizu force-pushed the max-htlc-sanity-check branch 2 times, most recently from 5dfb71f to 70e93bf Compare September 22, 2023 01:09
@YusukeShimizu YusukeShimizu marked this pull request as ready for review September 22, 2023 01:18
@YusukeShimizu YusukeShimizu changed the title [wip] Sanity check max htlc amount msat Sanity check max htlc amount msat Sep 22, 2023
@grubles
Copy link
Collaborator

grubles commented Sep 25, 2023

Tested by manually setting the max HTLC to the absolute minimum for both CLN and LND. Currently CLN does not apply the max HTLC to payments using sendpay, so setting it doesn't matter here.

With the max HTLC set to 1000msat on the LND side and with LND as a swap-in receiver, the swap is canceled:

$ lightning-cli --signet peerswap-swap-in 140490x1x0 200000000 lbtc
{
   "code": -1,
   "message": "swap canceled, reason: from the LND peer: exceeding spendable amount_msat: 1000"
}

With LND as a swap-out sender, the swap is also canceled:

$ pscli swapout --sat_amt 240000000 --channel_id 154470388586315776 --asset lbtc
2023/09/25 08:57:42 rpc error: code = Unknown desc = exceeding spendable amount_msat: 1000

Restoring the max HTLC amount for LND allows the swap to occur.

@wtogami
Copy link
Contributor

wtogami commented Sep 28, 2023

In cln, max htlc amt is not affect, so checks are only performed when the sender is lnd.

Can max htlc be queried prior to beginning a CLN swap? If so this could go in another PR later. I consider this to be a low priority.

Merging this for now.

@wtogami wtogami merged commit 226f607 into ElementsProject:master Sep 28, 2023
@YusukeShimizu
Copy link
Contributor Author

Yes, it is possible.
I will respond with another PR.

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.

Sanity check channel balance prior to swap
3 participants