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

Splice: Better balance checking #6748

Merged

Conversation

ddustin
Copy link
Collaborator

@ddustin ddustin commented Oct 5, 2023

ChangeLog-Fixed: Issue splicing with pending / stuck HTLCs fixed.

@ddustin ddustin added this to the v23.11 milestone Oct 5, 2023
@ddustin ddustin requested a review from rustyrussell October 5, 2023 20:51
@ddustin
Copy link
Collaborator Author

ddustin commented Oct 5, 2023

@rustyrussell One question I was unsure of here -> if there is an HTLC in the channel struct should that be counted as a pending HTLC or should it only be considered if it is in certain specific states?

@ddustin ddustin force-pushed the ddustin/splice_stuck_htlc branch from bacb181 to 90b0245 Compare October 5, 2023 22:50
tests/test_splicing.py Show resolved Hide resolved
Comment on lines +2983 to +3025
if (!amount_msat_add(&funding_amount,
funding_amount,
pending_htlcs[TX_INITIATOR]))
peer_failed_warn(peer->pps, &peer->channel_id,
"Unable to calculate starting channel amount");
if (!amount_msat_add(&funding_amount,
funding_amount,
pending_htlcs[TX_ACCEPTER]))
peer_failed_warn(peer->pps, &peer->channel_id,
"Unable to calculate starting channel amount");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I cried in the last couple of days to understand this logic here, and I am still not sure 100% for what this code does

Can you clarify this operation? and why do we need to look at the pending htlc? we can not just look at the peer->channel->view? to get the balance of the channel. it should contains the on-flight htlc too, right?

Please add a couple of comments in the code to make the review easy to look at, thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems pending HTLC amounts are not included in the channel->view amount as my initial splicing code assumed. I've asked rusty for some clarification here: #6748 (comment)

Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo Oct 23, 2023

Choose a reason for hiding this comment

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

I am still confused by this change here.

From the following comment https://github.com/ElementsProject/lightning/blob/master/common/initial_channel.h#L19 the peer->channel->view contains all the pending change, this mean that it contains also the pending_htlcs?

Is the comment outdated?

Can you clarify these operations for readers, please?

Copy link
Contributor

Choose a reason for hiding this comment

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

as far as I understand, peer->channel->view only contains the main outputs.

I think there's a semantic confusion here, because the doc on the view field talks about "pending" in the sense of whether protocol changes (such as add_htlc) are committed with a signature, but the new code here is using "pending" in the sense of "live" or "in-flight" HTLCs. should probably drop the use of the world pending.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, pending means "uncommitted" in that comment. Should be fixed!

@ddustin ddustin force-pushed the ddustin/splice_stuck_htlc branch from 90b0245 to 9ef52ad Compare October 14, 2023 19:39
Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

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

Ack 9ef52ad

@rustyrussell rustyrussell force-pushed the ddustin/splice_stuck_htlc branch from 9ef52ad to 8d0d7b7 Compare October 23, 2023 05:43
@rustyrussell
Copy link
Contributor

Fixed up Python whitespace which was annoying flake8, and rebased onto #6802 for test flake fixes.

@rustyrussell
Copy link
Contributor

Fixed up Python whitespace which was annoying flake8, and rebased onto #6802 for test flake fixes.

That was foolish: #6802 was broken. Will rebase once that's actually in master :(

* Regression test added for Issue ElementsProject#6572 (issuecomment-1730808863) w/stuck HTLC
* `check_balance` adjusted to calculate pending HTLCs explicitly
* Test confirmed to fail prior to PR ElementsProject#6713

ChangeLog-Fixed: Issue splicing with pending / stuck HTLCs fixed.
@rustyrussell rustyrussell force-pushed the ddustin/splice_stuck_htlc branch from c0dc177 to 864c363 Compare October 23, 2023 11:29
@rustyrussell
Copy link
Contributor

Rebased on master.

Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

The code looks good to me but I am still confused on the C logic

Comment on lines +2983 to +3025
if (!amount_msat_add(&funding_amount,
funding_amount,
pending_htlcs[TX_INITIATOR]))
peer_failed_warn(peer->pps, &peer->channel_id,
"Unable to calculate starting channel amount");
if (!amount_msat_add(&funding_amount,
funding_amount,
pending_htlcs[TX_ACCEPTER]))
peer_failed_warn(peer->pps, &peer->channel_id,
"Unable to calculate starting channel amount");
Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo Oct 23, 2023

Choose a reason for hiding this comment

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

I am still confused by this change here.

From the following comment https://github.com/ElementsProject/lightning/blob/master/common/initial_channel.h#L19 the peer->channel->view contains all the pending change, this mean that it contains also the pending_htlcs?

Is the comment outdated?

Can you clarify these operations for readers, please?

@rustyrussell
Copy link
Contributor

Yes, note that htlcs need to be in a committed state for splicing, so this code (which omits the committed check for htlcs) is actually correct here (though not general).

I don't think you need to recalc funding_amount though. channel->funding_sats is this?

@rustyrussell rustyrussell merged commit dc4e0a4 into ElementsProject:master Oct 26, 2023
38 checks passed
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