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

Channel: improve force-close handling #184

Merged
merged 3 commits into from
Apr 25, 2022

Conversation

aarani
Copy link
Collaborator

@aarani aarani commented Apr 13, 2022

This commit creates a unified function to handle most force-close
cases (last remote commit, next remote commit, last local commit,
remote revoked commits), this removes the need to implement this
logic in the upper layer.

This commit also fixes a bug where revocation was broken if
local's to_self_delay <> remote's to_self_delay.

@aarani aarani marked this pull request as draft April 13, 2022 09:43
@aarani aarani changed the title Channel: refactor force-close handling Channel: improve force-close handling Apr 13, 2022
@aarani aarani force-pushed the fundingTxSpentRefactorBackport branch from b17c4ba to c92d94a Compare April 13, 2022 09:54
@aarani aarani marked this pull request as ready for review April 13, 2022 10:00
|> ignore)

// FIXME: what if all the money is in htlcs?
if toLocalIndexOpt.IsNone && toRemoteIndexOpt.IsNone then
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a temporary fix for the false-positive scenario, this causes the function to return "Unknown Closing Tx" if we couldn't find any to_local and to_remote output, but this creates an issue with commitment TXs that only have HTLC outputs and not any main one.

Copy link
Owner

Choose a reason for hiding this comment

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

I want you to add test to check the false positive scenario.

but this creates an issue with commitment TXs that only have HTLC outputs and not any main one.

And a test to check that this won't lead to the crash?

Copy link
Collaborator Author

@aarani aarani Apr 20, 2022

Choose a reason for hiding this comment

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

I want you to add test to check the false positive scenario.

I added a test for old local commitment txs

And a test to check that this won't lead to the crash?

I think I should explain more, there's no chance of a crash, the only problem with that edge case is that instead of BalanceBelowDustLimit error we return UnknownClosingTx which seems a bad error for the case (I added a comment explaining it in the code also)

MainOutput = Error UnknownClosingTx
}

let HandleFundingTxSpent
Copy link
Owner

Choose a reason for hiding this comment

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

I think this function needs test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a test for revoked/remote/local cases.

@joemphilips
Copy link
Owner

some @aarani 's questions are hard hard for me to answer. And I have no time to catch up. (Channel state handling is not my interest anyway.)
Since at least there is no malicious code, I'd better just approve this change after tests I've mentioned above.

@aarani aarani force-pushed the fundingTxSpentRefactorBackport branch 2 times, most recently from 5bf2211 to abf5b58 Compare April 20, 2022 11:00
@knocte
Copy link
Collaborator

knocte commented Apr 22, 2022

How's this looking Joe?

@canndrew hey hello, by any chance you can have a quick look in case you spot something off very quickly?

lastLocalCommitmentSpec.ToRemote.ToMoney()


Expect.equal outputsSumFromRemoteSpendingRevokedRemoteCommitment (expectedAmountFromToRemote + expectedAmountFromToLocal) "wrong penalty tx"
Copy link
Owner

@joemphilips joemphilips Apr 24, 2022

Choose a reason for hiding this comment

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

You are running 3 attempt for HandleFundingTxSpent, and setup and assertions are mostly the same, it can be more succinct by grouping into the function instead of repeating.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I grouped validation, commitment tx creation (as much as I could) into functions

@aarani aarani force-pushed the fundingTxSpentRefactorBackport branch from abf5b58 to 4acb992 Compare April 25, 2022 08:58
@aarani aarani force-pushed the fundingTxSpentRefactorBackport branch from 4acb992 to 78882d4 Compare April 25, 2022 13:23
Copy link
Owner

@joemphilips joemphilips left a comment

Choose a reason for hiding this comment

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

LGTM: a806702

This commit creates a unified function to handle most force-close
cases (last remote commit, next remote commit, last local commit,
remote revoked commits), this removes the need to implement this
logic in the upper layer.

This commit also fixes a bug where revocation was broken if
local's to_self_delay <> remote's to_self_delay.
@knocte knocte force-pushed the fundingTxSpentRefactorBackport branch from a806702 to a19f5d2 Compare April 25, 2022 15:14
@knocte
Copy link
Collaborator

knocte commented Apr 25, 2022

LGTM: a806702

Rebasing from github UI (no changes).

@knocte knocte merged commit 499d633 into joemphilips:master Apr 25, 2022
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.

3 participants